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