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# MKDEPINTDEPS Extra internal dependencies for intermediates [not set] 23# 24# SRCS List of source files (c, c++, assembler) 25# 26# 27# +++ targets +++ 28# 29# cleandepend: 30# Remove depend and tags file 31# 32# depend: 33# Make the dependencies for the source files, and store 34# them in the file ${DEPENDFILE}. 35# 36# tags: 37# In "ctags" mode, create a tags file for the source files. 38# In "gtags" mode, create a (GLOBAL) gtags file for the 39# source files. If HTML is defined, htags(1) is also run 40# after gtags(1). 41 42.if !target(__<bsd.init.mk>__) 43.error bsd.dep.mk cannot be included directly. 44.endif 45 46CTAGS?= gtags 47CTAGSFLAGS?= 48GTAGSFLAGS?= -o 49HTAGSFLAGS?= 50 51MKDEPCMD?= mkdep 52DEPENDFILE?= .depend 53 54# Keep `tags' here, before SRCS are mangled below for `depend'. 55.if !target(tags) && defined(SRCS) && !defined(NOTAGS) 56tags: ${SRCS} 57.if ${CTAGS:T} == "ctags" 58 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \ 59 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET} 60.elif ${CTAGS:T} == "gtags" 61 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR} 62.if defined(HTML) 63 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR} 64.endif 65.endif 66.endif 67 68.if defined(SRCS) 69CLEANFILES?= 70 71.for _LSRC in ${SRCS:M*.l:N*/*} 72.for _LC in ${_LSRC:R}.c 73${_LC}: ${_LSRC} 74 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET} 75SRCS:= ${SRCS:S/${_LSRC}/${_LC}/} 76CLEANFILES+= ${_LC} 77.endfor 78.endfor 79 80.for _YSRC in ${SRCS:M*.y:N*/*} 81.for _YC in ${_YSRC:R}.c 82SRCS:= ${SRCS:S/${_YSRC}/${_YC}/} 83CLEANFILES+= ${_YC} 84.if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h) 85.ORDER: ${_YC} y.tab.h 86${_YC} y.tab.h: ${_YSRC} 87 ${YACC} ${YFLAGS} ${.ALLSRC} 88 cp y.tab.c ${_YC} 89CLEANFILES+= y.tab.c y.tab.h 90.elif !empty(YFLAGS:M-d) 91.for _YH in ${_YC:S/.c/.h/} 92${_YH}: ${_YC} 93${_YC}: ${_YSRC} 94 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 95SRCS+= ${_YH} 96CLEANFILES+= ${_YH} 97.endfor 98.else 99${_YC}: ${_YSRC} 100 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 101.endif 102.endfor 103.endfor 104.endif 105 106.if !target(depend) 107.if defined(SRCS) 108depend: beforedepend _dependincs ${DEPENDFILE} afterdepend 109 110# Tell bmake not to look for generated files via .PATH 111.NOPATH: ${DEPENDFILE} 112 113# Different types of sources are compiled with slightly different flags. 114# Split up the sources, and filter out headers and non-applicable flags. 115# Separate flag groups out of the sources and treat them differently. 116# The special "_" group is for all files not in any group. 117__FLAGS= 118__FLAGS_FILES= ${SRCS} 119.for _FG in ${FLAGS_GROUPS} 120.for _FFILE in ${${_FG}_FLAGS_FILES} 121__FLAGS_FILES:= ${__FLAGS_FILES:N${_FFILE}} 122.endfor 123.endfor 124 125_DEPENDFILES= ${FLAGS_GROUPS:S/^/.depend_/g} 126 127${DEPENDFILE}: ${_DEPENDFILES} 128 129# 130# __FLAG_FILES is built from SRCS. That means it will contain 131# also .h files and other files that are not direct sources, but which 132# might be required to even run mkdep. This is important if those are 133# generated as well, like some forwarding headers. 134# 135# We'll have to pass these "sources" on to the other .depend_ file targets, 136# since otherwise they might be run before the generated sources are 137# generated. _ALL_DEPENDS captures all files in SRCS that are not handled 138# by the mkdep calls, i.e. all sources that are not being used directly 139# for the .depend* file. 140# 141_ALL_DEPENDS=${__FLAGS_FILES:N*.[sS]:N*.c:N*.cc:N*.C:N*.cpp:N*.cpp:N*.cxx:N*.m} 142 143.for _FG in _ ${FLAGS_GROUPS} 144.depend${_FG:S/^/_/:N__}: ${${_FG}_FLAGS_FILES} ${_ALL_DEPENDS} 145 -rm -f ${.TARGET} 146 -> ${.TARGET} 147.if ${${_FG}_FLAGS_FILES:M*.[csS]} != "" 148 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ 149 ${${_FG}_FLAGS} \ 150 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ 151 ${CFLAGS:M-std=*} \ 152 ${.ALLSRC:M*.[csS]} 153.endif 154.if ${${_FG}_FLAGS_FILES:M*.cc} != "" || \ 155 ${${_FG}_FLAGS_FILES:M*.C} != "" || \ 156 ${${_FG}_FLAGS_FILES:M*.cpp} != "" || \ 157 ${${_FG}_FLAGS_FILES:M*.cxx} != "" 158 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ 159 ${${_FG}_FLAGS} \ 160 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \ 161 ${CXXFLAGS:M-std=*} \ 162 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx} 163.endif 164.if ${${_FG}_FLAGS_FILES:M*.m} != "" 165 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ 166 ${${_FG}_FLAGS} \ 167 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \ 168 ${OBJCFLAGS:M-Wno-import*} \ 169 ${.ALLSRC:M*.m} 170.endif 171.if !empty(${_FG:M_}) && !empty(_DEPENDFILES) 172 cat ${_DEPENDFILES} >> ${.TARGET} 173.endif 174.if defined(MKDEPINTDEPS) && !empty(MKDEPINTDEPS) 175. for _ITD in ${MKDEPINTDEPS:O:u} 176 TMP=_depend$$$$; \ 177 sed -e "s,${_ITD:C/^(.*:)(.*)/\1,\2 \1/},g" < ${.TARGET} > $$TMP; \ 178 mv $$TMP ${.TARGET} 179. endfor 180.endif 181.endfor 182 183.if target(_EXTRADEPEND) 184_EXTRADEPEND: .USE 185${DEPENDFILE}: _EXTRADEPEND 186.endif 187 188.else 189depend: beforedepend _dependincs afterdepend 190.endif 191.if !target(beforedepend) 192beforedepend: 193.endif 194.if !target(afterdepend) 195afterdepend: 196.endif 197.endif 198 199.if !target(cleandepend) 200cleandepend: 201.if defined(SRCS) 202.if ${CTAGS:T} == "ctags" 203 rm -f ${DEPENDFILE} ${_DEPENDFILES} tags 204.elif ${CTAGS:T} == "gtags" 205 rm -f ${DEPENDFILE} ${_DEPENDFILES} GPATH GRTAGS GSYMS GTAGS 206.if defined(HTML) 207 rm -rf HTML 208.endif 209.endif 210.endif 211.endif 212 213.if !target(checkdpadd) && (defined(DPADD) || defined(LDADD)) 214checkdpadd: 215.if ${OBJFORMAT} != aout 216 @ldadd=`echo \`for lib in ${DPADD} ; do \ 217 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \ 218 done \`` ; \ 219 ldadd1=`echo ${LDADD}` ; \ 220 if [ "$$ldadd" != "$$ldadd1" ] ; then \ 221 echo ${.CURDIR} ; \ 222 echo "DPADD -> $$ldadd" ; \ 223 echo "LDADD -> $$ldadd1" ; \ 224 fi 225.else 226 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \ 227 if [ "$$dpadd" != "${DPADD}" ] ; then \ 228 echo ${.CURDIR} ; \ 229 echo "LDADD -> $$dpadd" ; \ 230 echo "DPADD = ${DPADD}" ; \ 231 fi 232.endif 233.endif 234 235.if defined(INCS) && make(depend) 236_dependincs: buildincludes .WAIT installincludes 237.else 238_dependincs: 239.endif 240 241.ORDER: beforedepend _dependincs ${DEPENDFILE} afterdepend 242