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