1# $FreeBSD$ 2# 3# The include file <bsd.dep.mk> handles Makefile dependencies. 4# 5# 6# +++ variables +++ 7# 8# DEPENDFILE dependencies file [.depend] 9# 10# MKDEP Options for ${MKDEPCMD} [not set] 11# 12# MKDEPCMD Makefile dependency list program [mkdep] 13# 14# SRCS List of source files (c, c++, assembler) 15# 16# 17# +++ targets +++ 18# 19# cleandepend: 20# Remove depend and tags file 21# 22# depend: 23# Make the dependencies for the source files, and store 24# them in the file ${DEPENDFILE}. 25# 26# tags: 27# Create a (GLOBAL) gtags file for the source files. 28# If HTML is defined, htags is also run after gtags. 29 30.if !target(__<bsd.init.mk>__) 31.error bsd.dep.mk cannot be included directly. 32.endif 33 34.if ${CC} != "cc" 35MKDEPCMD?= CC='${CC}' mkdep 36.else 37MKDEPCMD?= mkdep 38.endif 39DEPENDFILE?= .depend 40 41.if defined(SRCS) 42CLEANFILES?= 43 44.for _LSRC in ${SRCS:M*.l:N*/*} 45.for _LC in ${_LSRC:S/.l/.c/} 46${_LC}: ${_LSRC} 47 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET} 48SRCS:= ${SRCS:S/${_LSRC}/${_LC}/} 49CLEANFILES:= ${CLEANFILES} ${_LC} 50.endfor 51.endfor 52 53.for _YSRC in ${SRCS:M*.y:N*/*} 54.for _YC in ${_YSRC:S/.y/.c/} 55SRCS:= ${SRCS:S/${_YSRC}/${_YC}/} 56CLEANFILES:= ${CLEANFILES} ${_YC} 57.if ${YFLAGS:M-d} != "" && ${SRCS:My.tab.h} 58.ORDER: ${_YC} y.tab.h 59${_YC} y.tab.h: ${_YSRC} 60 ${YACC} ${YFLAGS} ${.ALLSRC} 61 cp y.tab.c ${_YC} 62SRCS:= ${SRCS} y.tab.h 63CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h 64.elif ${YFLAGS:M-d} != "" 65.for _YH in ${_YC:S/.c/.h/} 66.ORDER: ${_YC} ${_YH} 67${_YC} ${_YH}: ${_YSRC} 68 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 69SRCS:= ${SRCS} ${_YH} 70CLEANFILES:= ${CLEANFILES} ${_YH} 71.endfor 72.else 73${_YC}: ${_YSRC} 74 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 75.endif 76.endfor 77.endfor 78.endif 79 80.if !target(depend) 81.if defined(SRCS) 82depend: beforedepend ${DEPENDFILE} afterdepend 83 84# Different types of sources are compiled with slightly different flags. 85# Split up the sources, and filter out headers and non-applicable flags. 86${DEPENDFILE}: ${SRCS} 87 rm -f ${DEPENDFILE} 88.if ${SRCS:M*.[sS]} != "" 89 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 90 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ 91 ${AINC} \ 92 ${.ALLSRC:M*.[sS]} 93.endif 94.if ${SRCS:M*.c} != "" 95 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 96 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ 97 ${.ALLSRC:M*.c} 98.endif 99.if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cpp} != "" || \ 100 ${SRCS:M*.cxx} != "" 101 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 102 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \ 103 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx} 104.endif 105.if ${SRCS:M*.m} != "" 106 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 107 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \ 108 ${OBJCFLAGS:M-Wno-import*} \ 109 ${.ALLSRC:M*.m} 110.endif 111.if target(_EXTRADEPEND) 112_EXTRADEPEND: .USE 113${DEPENDFILE}: _EXTRADEPEND 114.endif 115 116.ORDER: ${DEPENDFILE} afterdepend 117.else 118depend: beforedepend afterdepend 119.endif 120.if !target(beforedepend) 121beforedepend: 122.else 123.ORDER: beforedepend ${DEPENDFILE} 124.ORDER: beforedepend afterdepend 125.endif 126.if !target(afterdepend) 127afterdepend: 128.endif 129.endif 130 131.if defined(NOTAGS) 132tags: 133.endif 134 135.if !target(tags) 136tags: ${SRCS} 137 @cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR} 138.if defined(HTML) 139 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR} 140.endif 141.endif 142 143.if !target(cleandepend) 144cleandepend: 145.if defined(SRCS) 146 rm -f ${DEPENDFILE} ${.OBJDIR}/GPATH ${.OBJDIR}/GRTAGS \ 147 ${.OBJDIR}/GSYMS ${.OBJDIR}/GTAGS 148.if defined(HTML) 149 rm -rf ${.OBJDIR}/HTML 150.endif 151.endif 152.endif 153 154.if !target(checkdpadd) && (defined(DPADD) || defined(LDADD)) 155checkdpadd: 156.if ${OBJFORMAT} != aout 157 @ldadd=`echo \`for lib in ${DPADD} ; do \ 158 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \ 159 done \`` ; \ 160 ldadd1=`echo ${LDADD}` ; \ 161 if [ "$$ldadd" != "$$ldadd1" ] ; then \ 162 echo ${.CURDIR} ; \ 163 echo "DPADD -> $$ldadd" ; \ 164 echo "LDADD -> $$ldadd1" ; \ 165 fi 166.else 167 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \ 168 if [ "$$dpadd" != "${DPADD}" ] ; then \ 169 echo ${.CURDIR} ; \ 170 echo "LDADD -> $$dpadd" ; \ 171 echo "DPADD = ${DPADD}" ; \ 172 fi 173.endif 174.endif 175