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 # SRCS List of source files (c, c++, assembler)
28 # Remove depend and tags file
31 # Make the dependencies for the source files, and store
32 # them in the file ${DEPENDFILE}.
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
40 .if
!target
(__
<bsd.init.mk
>__
)
41 .error bsd.dep.mk cannot be included directly.
52 # Keep `tags' here, before SRCS are mangled below for `depend'.
53 .if
!target
(tags) && defined
(SRCS
) && !defined
(NOTAGS
)
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
}
61 @cd
${.CURDIR
} && htags
${HTAGSFLAGS} -d
${.OBJDIR
} ${.OBJDIR
}
69 .for _LSRC in
${SRCS
:M
*.l
:N
*/*}
70 .for _LC in
${_LSRC
:R
}.c
72 ${LEX} -t
${LFLAGS} ${.ALLSRC
} > ${.TARGET
}
73 SRCS
:= ${SRCS
:S
/${_LSRC}/${_LC}/}
78 .for _YSRC in
${SRCS
:M
*.y
:N
*/*}
79 .for _YC in
${_YSRC
:R
}.c
80 SRCS
:= ${SRCS
:S
/${_YSRC}/${_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
}
87 CLEANFILES
+= y.tab.c y.tab.h
88 .elif
!empty
(YFLAGS
:M-d
)
89 .for _YH in
${_YC
:S
/.c
/.h
/}
92 ${YACC} ${YFLAGS} -o
${_YC} ${.ALLSRC
}
98 ${YACC} ${YFLAGS} -o
${_YC} ${.ALLSRC
}
106 depend
: beforedepend _dependincs
${DEPENDFILE} afterdepend
108 # Tell bmake not to look for generated files via .PATH
109 .NOPATH
: ${DEPENDFILE}
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.
116 __FLAGS_FILES
= ${SRCS}
117 .for _FG in
${FLAGS_GROUPS}
118 .for _FFILE in
${${_FG}_FLAGS_FILES
}
119 __FLAGS_FILES
:= ${__FLAGS_FILES
:N
${_FFILE}}
123 _DEPENDFILES
= ${FLAGS_GROUPS
:S
/^
/.depend_
/g
}
125 ${DEPENDFILE}: ${_DEPENDFILES}
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.
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.
139 _ALL_DEPENDS
=${__FLAGS_FILES
:N
*.
[sS
]:N
*.c
:N
*.
cc:N
*.C
:N
*.
cpp:N
*.
cpp:N
*.
cxx:N
*.m
}
141 .for _FG in _
${FLAGS_GROUPS}
142 .depend
${_FG
:S
/^
/_
/:N__
}: ${${_FG}_FLAGS_FILES
} ${_ALL_DEPENDS}
145 .if
${${_FG}_FLAGS_FILES
:M
*.
[csS
]} != ""
146 ${MKDEPCMD} -f
${.TARGET
} -a
${MKDEP} \
148 ${CFLAGS
:M-nostdinc
*} ${CFLAGS
:M-
[BID
]*} \
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} \
158 ${CXXFLAGS
:M-nostdinc
*} ${CXXFLAGS
:M-
[BID
]*} \
159 ${CXXFLAGS
:M-std
=*} \
160 ${.ALLSRC
:M
*.
cc} ${.ALLSRC
:M
*.C
} ${.ALLSRC
:M
*.
cpp} ${.ALLSRC
:M
*.
cxx}
162 .if
${${_FG}_FLAGS_FILES
:M
*.m
} != ""
163 ${MKDEPCMD} -f
${.TARGET
} -a
${MKDEP} \
165 ${OBJCFLAGS
:M-nostdinc
*} ${OBJCFLAGS
:M-
[BID
]*} \
166 ${OBJCFLAGS
:M-Wno-import
*} \
169 .if
!empty
(${_FG
:M_
}) && !empty
(_DEPENDFILES
)
170 cat
${_DEPENDFILES} >> ${.TARGET
}
174 .if target
(_EXTRADEPEND
)
176 ${DEPENDFILE}: _EXTRADEPEND
180 depend
: beforedepend _dependincs afterdepend
182 .if
!target
(beforedepend
)
185 .if
!target
(afterdepend
)
190 .if
!target
(cleandepend
)
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
204 .if
!target
(checkdpadd
) && (defined
(DPADD
) || defined
(LDADD
))
206 .if
${OBJFORMAT} != aout
207 @ldadd
=`echo \`for lib in
${DPADD} ; do \
208 echo
$$lib | sed
's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \
210 ldadd1
=`echo ${LDADD}` ; \
211 if
[ "$$ldadd" != "$$ldadd1" ] ; then \
213 echo
"DPADD -> $$ldadd" ; \
214 echo
"LDADD -> $$ldadd1" ; \
217 @dpadd
=`echo \`ld -Bstatic
-f
${LDADD}\
`` ; \
218 if
[ "$$dpadd" != "${DPADD}" ] ; then \
220 echo
"LDADD -> $$dpadd" ; \
221 echo
"DPADD = ${DPADD}" ; \
226 .if defined
(INCS
) && make
(depend
)
227 _dependincs
: buildincludes .WAIT installincludes
232 .ORDER
: beforedepend _dependincs
${DEPENDFILE} afterdepend