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:R}.c 71${_LC}: ${_LSRC} 72 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET} 73SRCS:= ${SRCS:S/${_LSRC}/${_LC}/} 74CLEANFILES+= ${_LC} 75.endfor 76.endfor 77 78.for _YSRC in ${SRCS:M*.y:N*/*} 79.for _YC in ${_YSRC:R}.c 80SRCS:= ${SRCS:S/${_YSRC}/${_YC}/} 81CLEANFILES+= ${_YC} 82.if !empty(YFLAGS:M-d) && !empty(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} 87CLEANFILES+= y.tab.c y.tab.h 88.elif !empty(YFLAGS:M-d) 89.for _YH in ${_YC:S/.c/.h/} 90${_YH}: ${_YC} 91${_YC}: ${_YSRC} 92 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 93SRCS+= ${_YH} 94CLEANFILES+= ${_YH} 95.endfor 96.else 97${_YC}: ${_YSRC} 98 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 99.endif 100.endfor 101.endfor 102.endif 103 104.if !target(depend) 105.if defined(SRCS) 106depend: beforedepend _dependincs ${DEPENDFILE} afterdepend 107 108# Tell bmake not to look for generated files via .PATH 109.NOPATH: ${DEPENDFILE} 110 111# Different types of sources are compiled with slightly different flags. 112# Split up the sources, and filter out headers and non-applicable flags. 113# Separate flag groups out of the sources and treat them differently. 114# The special "_" group is for all files not in any group. 115__FLAGS= 116__FLAGS_FILES= ${SRCS} 117.for _FG in ${FLAGS_GROUPS} 118.for _FFILE in ${${_FG}_FLAGS_FILES} 119__FLAGS_FILES:= ${__FLAGS_FILES:N${_FFILE}} 120.endfor 121.endfor 122 123_DEPENDFILES= ${FLAGS_GROUPS:S/^/.depend_/g} 124 125${DEPENDFILE}: ${_DEPENDFILES} 126 127# 128# __FLAG_FILES is built from SRCS. That means it will contain 129# also .h files and other files that are not direct sources, but which 130# might be required to even run mkdep. This is important if those are 131# generated as well, like some forwarding headers. 132# 133# We'll have to pass these "sources" on to the other .depend_ file targets, 134# since otherwise they might be run before the generated sources are 135# generated. _ALL_DEPENDS captures all files in SRCS that are not handled 136# by the mkdep calls, i.e. all sources that are not being used directly 137# for the .depend* file. 138# 139_ALL_DEPENDS=${__FLAGS_FILES:N*.[sS]:N*.c:N*.cc:N*.C:N*.cpp:N*.cpp:N*.cxx:N*.m} 140 141.for _FG in _ ${FLAGS_GROUPS} 142.depend${_FG:S/^/_/:N__}: ${${_FG}_FLAGS_FILES} ${_ALL_DEPENDS} 143 -rm -f ${.TARGET} 144 -> ${.TARGET} 145.if ${${_FG}_FLAGS_FILES:M*.[csS]} != "" 146 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ 147 ${${_FG}_FLAGS} \ 148 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ 149 ${CFLAGS:M-std=*} \ 150 ${.ALLSRC:M*.[csS]} 151.endif 152.if ${${_FG}_FLAGS_FILES:M*.cc} != "" || \ 153 ${${_FG}_FLAGS_FILES:M*.C} != "" || \ 154 ${${_FG}_FLAGS_FILES:M*.cpp} != "" || \ 155 ${${_FG}_FLAGS_FILES:M*.cxx} != "" 156 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ 157 ${${_FG}_FLAGS} \ 158 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \ 159 ${CXXFLAGS:M-std=*} \ 160 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx} 161.endif 162.if ${${_FG}_FLAGS_FILES:M*.m} != "" 163 ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ 164 ${${_FG}_FLAGS} \ 165 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \ 166 ${OBJCFLAGS:M-Wno-import*} \ 167 ${.ALLSRC:M*.m} 168.endif 169.if !empty(${_FG:M_}) && !empty(_DEPENDFILES) 170 cat ${_DEPENDFILES} >> ${.TARGET} 171.endif 172.endfor 173 174.if target(_EXTRADEPEND) 175_EXTRADEPEND: .USE 176${DEPENDFILE}: _EXTRADEPEND 177.endif 178 179.else 180depend: beforedepend _dependincs afterdepend 181.endif 182.if !target(beforedepend) 183beforedepend: 184.endif 185.if !target(afterdepend) 186afterdepend: 187.endif 188.endif 189 190.if !target(cleandepend) 191cleandepend: 192.if defined(SRCS) 193.if ${CTAGS:T} == "ctags" 194 rm -f ${DEPENDFILE} ${_DEPENDFILES} tags 195.elif ${CTAGS:T} == "gtags" 196 rm -f ${DEPENDFILE} ${_DEPENDFILES} GPATH GRTAGS GSYMS GTAGS 197.if defined(HTML) 198 rm -rf HTML 199.endif 200.endif 201.endif 202.endif 203 204.if !target(checkdpadd) && (defined(DPADD) || defined(LDADD)) 205checkdpadd: 206.if ${OBJFORMAT} != aout 207 @ldadd=`echo \`for lib in ${DPADD} ; do \ 208 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \ 209 done \`` ; \ 210 ldadd1=`echo ${LDADD}` ; \ 211 if [ "$$ldadd" != "$$ldadd1" ] ; then \ 212 echo ${.CURDIR} ; \ 213 echo "DPADD -> $$ldadd" ; \ 214 echo "LDADD -> $$ldadd1" ; \ 215 fi 216.else 217 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \ 218 if [ "$$dpadd" != "${DPADD}" ] ; then \ 219 echo ${.CURDIR} ; \ 220 echo "LDADD -> $$dpadd" ; \ 221 echo "DPADD = ${DPADD}" ; \ 222 fi 223.endif 224.endif 225 226.if defined(INCS) && make(depend) 227_dependincs: buildincludes .WAIT installincludes 228.else 229_dependincs: 230.endif 231 232.ORDER: beforedepend _dependincs ${DEPENDFILE} afterdepend 233