1 # $FreeBSD: src/share/mk/bsd.dep.mk,v 1.27.2.3 2002/12/23 16:33:37 ru Exp $
3 # The include file <bsd.dep.mk> handles Makefile dependencies.
8 # CTAGS A tags file generation program [gtags]
10 # CTAGSFLAGS Options for ctags(1) [not set]
12 # DEPENDFILE dependencies file [.depend]
14 # GTAGSFLAGS Options for gtags(1) [-o]
16 # HTAGSFLAGS Options for htags(1) [not set]
18 # MKDEP Options for ${MKDEPCMD} [not set]
20 # MKDEPCC CC to be used in ${MKDEPCMD} script [cc]
22 # MKDEPCMD Makefile dependency list program [mkdep]
24 # MKDEPINTDEPS Extra internal dependencies for intermediates [not set]
26 # SRCS List of source files (c, c++, assembler)
32 # Remove depend and tags file
35 # Make the dependencies for the source files, and store
36 # them in the file ${DEPENDFILE}.
39 # In "ctags" mode, create a tags file for the source files.
40 # In "gtags" mode, create a (GLOBAL) gtags file for the
41 # source files. If HTML is defined, htags(1) is also run
44 .if
!target
(__
<bsd.init.mk
>__
)
45 .error bsd.dep.mk cannot be included directly.
57 # Support better dependencies tracking for both host cc and target cc.
58 .if defined
(__USE_HOST_CCVER
)
59 _MKDEPENV
= ${NXENV
:NPATH
=*}
61 _MKDEPENV
= CCVER
=${CCVER}
64 # Keep `tags' here, before SRCS are mangled below for `depend'.
65 .if
!target
(tags) && defined
(SRCS
) && !defined
(NOTAGS
)
67 .if
${CTAGS
:T
} == "ctags"
68 @
${CTAGS} ${CTAGSFLAGS} -f
/dev
/stdout \
69 ${.ALLSRC
:N
*.h
} | sed
"s;${.CURDIR}/;;" > ${.TARGET
}
70 .elif
${CTAGS
:T
} == "gtags"
71 @cd
${.CURDIR
} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR
}
73 @cd
${.CURDIR
} && htags
${HTAGSFLAGS} -d
${.OBJDIR
} ${.OBJDIR
}
81 .for _LSRC in
${SRCS
:M
*.l
:N
*/*}
82 .for _LC in
${_LSRC
:R
}.c
84 ${LEX} -t
${LFLAGS} ${.ALLSRC
} > ${.TARGET
}
85 SRCS
:= ${SRCS
:S
/${_LSRC}/${_LC}/}
90 .for _YSRC in
${SRCS
:M
*.y
:N
*/*}
91 .for _YC in
${_YSRC
:R
}.c
92 SRCS
:= ${SRCS
:S
/${_YSRC}/${_YC}/}
94 .if
!empty
(YFLAGS
:M-d
) && !empty
(SRCS
:My.tab.h
)
95 .ORDER
: ${_YC} y.tab.h
96 ${_YC} y.tab.h
: ${_YSRC}
97 ${YACC} ${YFLAGS} ${.ALLSRC
}
99 CLEANFILES
+= y.tab.c y.tab.h
100 .elif
!empty
(YFLAGS
:M-d
)
101 .for _YH in
${_YC
:S
/.c
/.h
/}
104 ${YACC} ${YFLAGS} -o
${_YC} ${.ALLSRC
}
110 ${YACC} ${YFLAGS} -o
${_YC} ${.ALLSRC
}
118 depend
: beforedepend _dependincs
${DEPENDFILE} afterdepend
120 # Tell bmake not to look for generated files via .PATH
121 .NOPATH
: ${DEPENDFILE}
123 # Different types of sources are compiled with slightly different flags.
124 # Split up the sources, and filter out headers and non-applicable flags.
125 # Separate flag groups out of the sources and treat them differently.
126 # The special "_" group is for all files not in any group.
128 __FLAGS_FILES
= ${SRCS}
129 .for _FG in
${FLAGS_GROUPS}
130 .for _FFILE in
${${_FG}_FLAGS_FILES
}
131 __FLAGS_FILES
:= ${__FLAGS_FILES
:N
${_FFILE}}
135 _DEPENDFILES
= ${FLAGS_GROUPS
:S
/^
/.depend_
/g
}
137 ${DEPENDFILE}: ${_DEPENDFILES}
140 # __FLAG_FILES is built from SRCS. That means it will contain
141 # also .h files and other files that are not direct sources, but which
142 # might be required to even run mkdep. This is important if those are
143 # generated as well, like some forwarding headers.
145 # We'll have to pass these "sources" on to the other .depend_ file targets,
146 # since otherwise they might be run before the generated sources are
147 # generated. _ALL_DEPENDS captures all files in SRCS that are not handled
148 # by the mkdep calls, i.e. all sources that are not being used directly
149 # for the .depend* file.
151 _ALL_DEPENDS
=${__FLAGS_FILES
:N
*.
[sS
]:N
*.c
:N
*.
cc:N
*.C
:N
*.
cpp:N
*.
cpp:N
*.
cxx:N
*.m
}
153 .for _FG in _
${FLAGS_GROUPS}
154 .depend
${_FG
:S
/^
/_
/:N__
}: ${${_FG}_FLAGS_FILES
} ${_ALL_DEPENDS}
157 .if
${${_FG}_FLAGS_FILES
:M
*.
[csS
]} != ""
158 ${_MKDEPENV} CC
=${MKDEPCC} ${MKDEPCMD} -f
${.TARGET
} -a
${MKDEP} \
160 ${CFLAGS
:M-nostdinc
*} ${CFLAGS
:M-
[BID
]*} \
164 .if
${${_FG}_FLAGS_FILES
:M
*.
cc} != "" || \
165 ${${_FG}_FLAGS_FILES
:M
*.C
} != "" || \
166 ${${_FG}_FLAGS_FILES
:M
*.
cpp} != "" || \
167 ${${_FG}_FLAGS_FILES
:M
*.
cxx} != ""
168 ${_MKDEPENV} CC
=${CXX} ${MKDEPCMD} -f
${.TARGET
} -a
${MKDEP} \
170 ${CXXFLAGS
:M-nostdinc
*} ${CXXFLAGS
:M-
[BID
]*} \
171 ${CXXFLAGS
:M-std
=*} \
172 ${.ALLSRC
:M
*.
cc} ${.ALLSRC
:M
*.C
} ${.ALLSRC
:M
*.
cpp} ${.ALLSRC
:M
*.
cxx}
174 .if
${${_FG}_FLAGS_FILES
:M
*.m
} != ""
175 ${MKDEPCMD} -f
${.TARGET
} -a
${MKDEP} \
177 ${OBJCFLAGS
:M-nostdinc
*} ${OBJCFLAGS
:M-
[BID
]*} \
178 ${OBJCFLAGS
:M-Wno-import
*} \
181 .if
!empty
(${_FG
:M_
}) && !empty
(_DEPENDFILES
)
182 cat
${_DEPENDFILES} >> ${.TARGET
}
184 .if defined
(MKDEPINTDEPS
) && !empty
(MKDEPINTDEPS
)
185 . for _ITD in
${MKDEPINTDEPS
:O
:u
}
187 sed
-e
"s,${_ITD:C/^(.*:)(.*)/\1,\2 \1/},g" < ${.TARGET
} > $$TMP; \
193 .if target
(_EXTRADEPEND
)
195 ${DEPENDFILE}: _EXTRADEPEND
199 depend
: beforedepend _dependincs afterdepend
201 .if
!target
(beforedepend
)
204 .if
!target
(afterdepend
)
209 .if
!target
(cleandepend
)
212 .if
${CTAGS
:T
} == "ctags"
213 rm -f
${DEPENDFILE} ${_DEPENDFILES} tags
214 .elif
${CTAGS
:T
} == "gtags"
215 rm -f
${DEPENDFILE} ${_DEPENDFILES} GPATH GRTAGS GSYMS GTAGS
223 .if
!target
(checkdpadd
) && (defined
(DPADD
) || defined
(LDADD
))
225 .if
${OBJFORMAT} != aout
226 @ldadd
=`echo \`for lib in
${DPADD} ; do \
227 echo
$$lib | sed
's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
229 ldadd1
=`echo ${LDADD}` ; \
230 if
[ "$$ldadd" != "$$ldadd1" ] ; then \
232 echo
"DPADD -> $$ldadd" ; \
233 echo
"LDADD -> $$ldadd1" ; \
236 @dpadd
=`echo \`ld -Bstatic
-f
${LDADD}\
`` ; \
237 if
[ "$$dpadd" != "${DPADD}" ] ; then \
239 echo
"LDADD -> $$dpadd" ; \
240 echo
"DPADD = ${DPADD}" ; \
245 .if defined
(INCS
) && make
(depend
)
246 _dependincs
: buildincludes .WAIT installincludes
251 .ORDER
: beforedepend _dependincs
${DEPENDFILE} afterdepend