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