xref: /freebsd/contrib/bmake/mk/auto.dep.mk (revision c60f6422ffae3ea85e7b10bad950ad27c463af18)
1# $Id: auto.dep.mk,v 1.13 2025/08/09 22:42:24 sjg Exp $
2#
3#	@(#) Copyright (c) 2010-2021, Simon J. Gerraty
4#
5#	SPDX-License-Identifier: BSD-2-Clause
6#
7#	Please send copies of changes and bug-fixes to:
8#	sjg@crufty.net
9#
10
11# This module provides automagic dependency generation along the
12# lines suggested in the GNU make.info
13
14# set MKDEP_MK=auto.dep.mk and dep.mk will include us
15
16# This version differs from autodep.mk, in that
17# we use ${.TARGET:T}.d rather than ${.TARGET:T:R}.d
18# this makes it simpler to get the args to -MF and -MT right
19# and ensure we can simply include all the .d files.
20#
21# However suffix rules do not work with something like .o.d so we
22# don't even try to handle 'make depend' gracefully.
23# dep.mk will handle that itself.
24#
25.if !target(__${.PARSEFILE}__)
26__${.PARSEFILE}__: .NOTMAIN
27
28# set this to -MMD to ignore /usr/include
29# actually it ignores <> so may not be a great idea
30CFLAGS_MD ?= -MD
31# -MF etc not available on all gcc versions.
32.if ${COMPILER_TYPE:Ugcc} == "gcc" && ${COMPILER_VERSION:U0} < 30000
33CFLAGS_MF=
34.endif
35CFLAGS_MF ?= -MF ${.TARGET:T}.d -MT ${.TARGET:T}
36CFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
37CXXFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
38
39CLEANFILES += .depend *.d
40
41.if ${MAKE_VERSION} >= 20160218
42
43# we have .dinclude and this is all that is required
44.if empty(_SKIP_BUILD)
45_all_objs = ${OBJS} ${POBJS} ${SOBJS}
46.for d in ${_all_objs:M*o:T:O:u:%=%.d}
47.dinclude <$d>
48.endfor
49.endif
50
51.else				# we lack .dinclude
52
53.if ${.MAKE.MODE:Unormal:Mmeta} != ""
54# ignore .MAKE.DEPENDFILE
55DEPENDFILE = .depend
56.else
57# this what bmake > 20100401 will look for
58.MAKE.DEPENDFILE ?= .depend
59DEPENDFILE ?= ${.MAKE.DEPENDFILE}
60.endif
61
62CLEANFILES += ${DEPENDFILE}
63
64# skip generating dependfile for misc targets
65.if ${.TARGETS:Uall:M*all} != ""
66.END:	${DEPENDFILE}
67.endif
68
69# doing 'make depend' isn't a big win with this model
70.if !target(depend)
71depend: ${DEPENDFILE}
72.endif
73
74# this is trivial
75${DEPENDFILE}: ${OBJS} ${POBJS} ${SOBJS}
76	-@for f in ${.ALLSRC:M*o:T:O:u:%=%.d}; do \
77		echo ".-include \"$$f\""; \
78	done > $@
79
80.endif
81
82.-include <ccm.dep.mk>
83
84.endif
85