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 # MKDEPCMD Makefile dependency list program [mkdep]
22 # MKDEPINTDEPS Extra internal dependencies for intermediates [not set]
24 # SRCS List of source files (c, c++, assembler)
30 # Remove depend and tags file
33 # Make the dependencies for the source files, and store
34 # them in the file ${DEPENDFILE}.
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
42 .if
!target
(__
<bsd.init.mk
>__
)
43 .error bsd.dep.mk cannot be included directly.
54 # Keep `tags' here, before SRCS are mangled below for `depend'.
55 .if
!target
(tags) && defined
(SRCS
) && !defined
(NOTAGS
)
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
}
63 @cd
${.CURDIR
} && htags
${HTAGSFLAGS} -d
${.OBJDIR
} ${.OBJDIR
}
71 .for _LSRC in
${SRCS
:M
*.l
:N
*/*}
72 .for _LC in
${_LSRC
:R
}.c
74 ${LEX} -t
${LFLAGS} ${.ALLSRC
} > ${.TARGET
}
75 SRCS
:= ${SRCS
:S
/${_LSRC}/${_LC}/}
80 .for _YSRC in
${SRCS
:M
*.y
:N
*/*}
81 .for _YC in
${_YSRC
:R
}.c
82 SRCS
:= ${SRCS
:S
/${_YSRC}/${_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
}
89 CLEANFILES
+= y.tab.c y.tab.h
90 .elif
!empty
(YFLAGS
:M-d
)
91 .for _YH in
${_YC
:S
/.c
/.h
/}
94 ${YACC} ${YFLAGS} -o
${_YC} ${.ALLSRC
}
100 ${YACC} ${YFLAGS} -o
${_YC} ${.ALLSRC
}
108 depend
: beforedepend _dependincs
${DEPENDFILE} afterdepend
110 # Tell bmake not to look for generated files via .PATH
111 .NOPATH
: ${DEPENDFILE}
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.
118 __FLAGS_FILES
= ${SRCS}
119 .for _FG in
${FLAGS_GROUPS}
120 .for _FFILE in
${${_FG}_FLAGS_FILES
}
121 __FLAGS_FILES
:= ${__FLAGS_FILES
:N
${_FFILE}}
125 _DEPENDFILES
= ${FLAGS_GROUPS
:S
/^
/.depend_
/g
}
127 ${DEPENDFILE}: ${_DEPENDFILES}
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.
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.
141 _ALL_DEPENDS
=${__FLAGS_FILES
:N
*.
[sS
]:N
*.c
:N
*.
cc:N
*.C
:N
*.
cpp:N
*.
cpp:N
*.
cxx:N
*.m
}
143 .for _FG in _
${FLAGS_GROUPS}
144 .depend
${_FG
:S
/^
/_
/:N__
}: ${${_FG}_FLAGS_FILES
} ${_ALL_DEPENDS}
147 .if
${${_FG}_FLAGS_FILES
:M
*.
[csS
]} != ""
148 ${MKDEPCMD} -f
${.TARGET
} -a
${MKDEP} \
150 ${CFLAGS
:M-nostdinc
*} ${CFLAGS
:M-
[BID
]*} \
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} \
160 ${CXXFLAGS
:M-nostdinc
*} ${CXXFLAGS
:M-
[BID
]*} \
161 ${CXXFLAGS
:M-std
=*} \
162 ${.ALLSRC
:M
*.
cc} ${.ALLSRC
:M
*.C
} ${.ALLSRC
:M
*.
cpp} ${.ALLSRC
:M
*.
cxx}
164 .if
${${_FG}_FLAGS_FILES
:M
*.m
} != ""
165 ${MKDEPCMD} -f
${.TARGET
} -a
${MKDEP} \
167 ${OBJCFLAGS
:M-nostdinc
*} ${OBJCFLAGS
:M-
[BID
]*} \
168 ${OBJCFLAGS
:M-Wno-import
*} \
171 .if
!empty
(${_FG
:M_
}) && !empty
(_DEPENDFILES
)
172 cat
${_DEPENDFILES} >> ${.TARGET
}
174 .if defined
(MKDEPINTDEPS
) && !empty
(MKDEPINTDEPS
)
175 . for _ITD in
${MKDEPINTDEPS
:O
:u
}
177 sed
-e
"s,${_ITD:C/^(.*:)(.*)/\1,\2 \1/},g" < ${.TARGET
} > $$TMP; \
183 .if target
(_EXTRADEPEND
)
185 ${DEPENDFILE}: _EXTRADEPEND
189 depend
: beforedepend _dependincs afterdepend
191 .if
!target
(beforedepend
)
194 .if
!target
(afterdepend
)
199 .if
!target
(cleandepend
)
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
213 .if
!target
(checkdpadd
) && (defined
(DPADD
) || defined
(LDADD
))
215 .if
${OBJFORMAT} != aout
216 @ldadd
=`echo \`for lib in
${DPADD} ; do \
217 echo
$$lib | sed
's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
219 ldadd1
=`echo ${LDADD}` ; \
220 if
[ "$$ldadd" != "$$ldadd1" ] ; then \
222 echo
"DPADD -> $$ldadd" ; \
223 echo
"LDADD -> $$ldadd1" ; \
226 @dpadd
=`echo \`ld -Bstatic
-f
${LDADD}\
`` ; \
227 if
[ "$$dpadd" != "${DPADD}" ] ; then \
229 echo
"LDADD -> $$dpadd" ; \
230 echo
"DPADD = ${DPADD}" ; \
235 .if defined
(INCS
) && make
(depend
)
236 _dependincs
: buildincludes .WAIT installincludes
241 .ORDER
: beforedepend _dependincs
${DEPENDFILE} afterdepend