| Commit | Line | Data |
|---|---|---|
| 984263bc MD |
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] | |
| 59620cdf | 21 | # |
| 984263bc MD |
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 | ||
| 44 | CTAGS?= gtags | |
| 45 | CTAGSFLAGS?= | |
| 46 | GTAGSFLAGS?= -o | |
| 47 | HTAGSFLAGS?= | |
| 48 | ||
| 49 | MKDEPCMD?= mkdep | |
| 50 | DEPENDFILE?= .depend | |
| 51 | ||
| 52 | # Keep `tags' here, before SRCS are mangled below for `depend'. | |
| 53 | .if !target(tags) && defined(SRCS) && !defined(NOTAGS) | |
| 54 | tags: ${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) | |
| 67 | CLEANFILES?= | |
| 68 | ||
| 69 | .for _LSRC in ${SRCS:M*.l:N*/*} | |
| 59620cdf | 70 | .for _LC in ${_LSRC:R}.c |
| 984263bc MD |
71 | ${_LC}: ${_LSRC} |
| 72 | ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET} | |
| 73 | SRCS:= ${SRCS:S/${_LSRC}/${_LC}/} | |
| 59620cdf | 74 | CLEANFILES+= ${_LC} |
| 984263bc MD |
75 | .endfor |
| 76 | .endfor | |
| 77 | ||
| 78 | .for _YSRC in ${SRCS:M*.y:N*/*} | |
| 59620cdf | 79 | .for _YC in ${_YSRC:R}.c |
| 984263bc | 80 | SRCS:= ${SRCS:S/${_YSRC}/${_YC}/} |
| 59620cdf | 81 | CLEANFILES+= ${_YC} |
| 8d049a95 | 82 | .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h) |
| 984263bc MD |
83 | .ORDER: ${_YC} y.tab.h |
| 84 | ${_YC} y.tab.h: ${_YSRC} | |
| 85 | ${YACC} ${YFLAGS} ${.ALLSRC} | |
| 86 | cp y.tab.c ${_YC} | |
| 59620cdf | 87 | CLEANFILES+= y.tab.c y.tab.h |
| ff5b5f8a | 88 | .elif !empty(YFLAGS:M-d) |
| 984263bc MD |
89 | .for _YH in ${_YC:S/.c/.h/} |
| 90 | .ORDER: ${_YC} ${_YH} | |
| 91 | ${_YC} ${_YH}: ${_YSRC} | |
| 92 | ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} | |
| 59620cdf JM |
93 | SRCS+= ${_YH} |
| 94 | CLEANFILES+= ${_YH} | |
| 984263bc MD |
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) | |
| 67be5538 | 106 | depend: beforedepend _dependincs ${DEPENDFILE} afterdepend |
| 984263bc | 107 | |
| 59620cdf JM |
108 | # Tell bmake not to look for generated files via .PATH |
| 109 | .NOPATH: ${DEPENDFILE} | |
| 110 | ||
| 984263bc MD |
111 | # Different types of sources are compiled with slightly different flags. |
| 112 | # Split up the sources, and filter out headers and non-applicable flags. | |
| 6d68f83f SS |
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 | ||
| f21f740a | 123 | _DEPENDFILES= ${FLAGS_GROUPS:S/^/.depend_/g} |
| 6d68f83f SS |
124 | |
| 125 | ${DEPENDFILE}: ${_DEPENDFILES} | |
| 6d68f83f | 126 | |
| f0ca6fca SS |
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 | ||
| 6d68f83f | 141 | .for _FG in _ ${FLAGS_GROUPS} |
| f0ca6fca | 142 | .depend${_FG:S/^/_/:N__}: ${${_FG}_FLAGS_FILES} ${_ALL_DEPENDS} |
| 6d68f83f SS |
143 | -rm -f ${.TARGET} |
| 144 | -> ${.TARGET} | |
| 145 | .if ${${_FG}_FLAGS_FILES:M*.[sS]} != "" | |
| 146 | ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ | |
| 147 | ${${_FG}_FLAGS} \ | |
| 984263bc MD |
148 | ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ |
| 149 | ${AINC} \ | |
| 150 | ${.ALLSRC:M*.[sS]} | |
| 151 | .endif | |
| 6d68f83f SS |
152 | .if ${${_FG}_FLAGS_FILES:M*.c} != "" |
| 153 | ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ | |
| 154 | ${${_FG}_FLAGS} \ | |
| 984263bc | 155 | ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ |
| 1ce5d5aa | 156 | ${CFLAGS:M-std=*} \ |
| 984263bc MD |
157 | ${.ALLSRC:M*.c} |
| 158 | .endif | |
| 6d68f83f SS |
159 | .if ${${_FG}_FLAGS_FILES:M*.cc} != "" || \ |
| 160 | ${${_FG}_FLAGS_FILES:M*.C} != "" || \ | |
| 161 | ${${_FG}_FLAGS_FILES:M*.cpp} != "" || \ | |
| 162 | ${${_FG}_FLAGS_FILES:M*.cxx} != "" | |
| 163 | ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ | |
| 164 | ${${_FG}_FLAGS} \ | |
| 984263bc | 165 | ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \ |
| 1ce5d5aa | 166 | ${CXXFLAGS:M-std=*} \ |
| 984263bc MD |
167 | ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx} |
| 168 | .endif | |
| 6d68f83f SS |
169 | .if ${${_FG}_FLAGS_FILES:M*.m} != "" |
| 170 | ${MKDEPCMD} -f ${.TARGET} -a ${MKDEP} \ | |
| 171 | ${${_FG}_FLAGS} \ | |
| 984263bc MD |
172 | ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \ |
| 173 | ${OBJCFLAGS:M-Wno-import*} \ | |
| 174 | ${.ALLSRC:M*.m} | |
| 175 | .endif | |
| f21f740a SS |
176 | .if !empty(${_FG:M_}) && !empty(_DEPENDFILES) |
| 177 | cat ${_DEPENDFILES} >> ${.TARGET} | |
| 178 | .endif | |
| 6d68f83f SS |
179 | .endfor |
| 180 | ||
| 984263bc MD |
181 | .if target(_EXTRADEPEND) |
| 182 | _EXTRADEPEND: .USE | |
| 183 | ${DEPENDFILE}: _EXTRADEPEND | |
| 184 | .endif | |
| 185 | ||
| 984263bc | 186 | .else |
| 67be5538 | 187 | depend: beforedepend _dependincs afterdepend |
| 984263bc MD |
188 | .endif |
| 189 | .if !target(beforedepend) | |
| 190 | beforedepend: | |
| 984263bc MD |
191 | .endif |
| 192 | .if !target(afterdepend) | |
| 193 | afterdepend: | |
| 194 | .endif | |
| 195 | .endif | |
| 196 | ||
| 197 | .if !target(cleandepend) | |
| 198 | cleandepend: | |
| 199 | .if defined(SRCS) | |
| 200 | .if ${CTAGS:T} == "ctags" | |
| 6d68f83f | 201 | rm -f ${DEPENDFILE} ${_DEPENDFILES} tags |
| 984263bc | 202 | .elif ${CTAGS:T} == "gtags" |
| 6d68f83f | 203 | rm -f ${DEPENDFILE} ${_DEPENDFILES} GPATH GRTAGS GSYMS GTAGS |
| 984263bc MD |
204 | .if defined(HTML) |
| 205 | rm -rf HTML | |
| 206 | .endif | |
| 207 | .endif | |
| 208 | .endif | |
| 209 | .endif | |
| 210 | ||
| 211 | .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD)) | |
| 212 | checkdpadd: | |
| 213 | .if ${OBJFORMAT} != aout | |
| 214 | @ldadd=`echo \`for lib in ${DPADD} ; do \ | |
| 215 | echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \ | |
| 216 | done \`` ; \ | |
| 217 | ldadd1=`echo ${LDADD}` ; \ | |
| 218 | if [ "$$ldadd" != "$$ldadd1" ] ; then \ | |
| 219 | echo ${.CURDIR} ; \ | |
| 220 | echo "DPADD -> $$ldadd" ; \ | |
| 221 | echo "LDADD -> $$ldadd1" ; \ | |
| 222 | fi | |
| 223 | .else | |
| 224 | @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \ | |
| 225 | if [ "$$dpadd" != "${DPADD}" ] ; then \ | |
| 226 | echo ${.CURDIR} ; \ | |
| 227 | echo "LDADD -> $$dpadd" ; \ | |
| 228 | echo "DPADD = ${DPADD}" ; \ | |
| 229 | fi | |
| 230 | .endif | |
| 231 | .endif | |
| 67be5538 MD |
232 | |
| 233 | .if defined(INCS) && make(depend) | |
| 59620cdf | 234 | _dependincs: buildincludes .WAIT installincludes |
| 67be5538 | 235 | .else |
| 67be5538 | 236 | _dependincs: |
| 67be5538 | 237 | .endif |
| 59620cdf JM |
238 | |
| 239 | .ORDER: beforedepend _dependincs ${DEPENDFILE} afterdepend |