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