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