1246149Ssjg#
2246149Ssjg# RCSid:
3246149Ssjg#	$Id: auto.dep.mk,v 1.2 2010/04/19 17:37:19 sjg Exp $
4246149Ssjg#
5246149Ssjg#	@(#) Copyright (c) 2010, Simon J. Gerraty
6246149Ssjg#
7246149Ssjg#	This file is provided in the hope that it will
8246149Ssjg#	be of use.  There is absolutely NO WARRANTY.
9246149Ssjg#	Permission to copy, redistribute or otherwise
10246149Ssjg#	use this file is hereby granted provided that 
11246149Ssjg#	the above copyright notice and this notice are
12246149Ssjg#	left intact. 
13246149Ssjg#      
14246149Ssjg#	Please send copies of changes and bug-fixes to:
15246149Ssjg#	sjg@crufty.net
16246149Ssjg#
17246149Ssjg
18246149Ssjg# This module provides automagic dependency generation along the
19246149Ssjg# lines suggested in the GNU make.info
20246149Ssjg
21246149Ssjg# set MKDEP=auto.dep and dep.mk will include us
22246149Ssjg
23246149Ssjg# This version differs from autodep.mk, in that 
24246149Ssjg# we use ${.TARGET:T}.d rather than ${.TARGET:T:R}.d
25246149Ssjg# this makes it simpler to get the args to -MF and -MT right
26246149Ssjg# and ensure we can simply include all the .d files.
27246149Ssjg# 
28246149Ssjg# However suffix rules do not work with something like .o.d so we
29246149Ssjg# don't even try to handle 'make depend' gracefully.
30246149Ssjg# dep.mk will handle that itself.
31246149Ssjg#
32246149Ssjg.if !target(__${.PARSEFILE}__)
33246149Ssjg__${.PARSEFILE}__:
34246149Ssjg
35246149Ssjg# this what bmake > 20100401 will look for
36246149Ssjg.MAKE.DEPENDFILE ?= .depend
37246149Ssjg
38246149Ssjg# set this to -MMD to ignore /usr/include
39246149Ssjg# actually it ignores <> so may not be a great idea
40246149SsjgCFLAGS_MD ?= -MD 
41246149Ssjg# -MF etc not available on all gcc versions.
42246149SsjgCFLAGS_MF ?= -MF ${.TARGET:T}.d -MT ${.TARGET:T}
43246149SsjgCFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
44246149SsjgCXXFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
45246149Ssjg
46246149SsjgCLEANFILES += .depend ${.MAKE.DEPENDFILE} *.d
47246149Ssjg
48246149Ssjg# skip generating dependfile for misc targets
49246149Ssjg.if ${.TARGETS:Uall:M*all} != ""
50246149Ssjg.END:	${.MAKE.DEPENDFILE}
51246149Ssjg.endif
52246149Ssjg
53246149Ssjg# doing 'make depend' isn't a big win with this model
54246149Ssjg.if !target(depend)
55246149Ssjgdepend: ${.MAKE.DEPENDFILE}
56246149Ssjg.endif
57246149Ssjg
58246149Ssjg# this is trivial
59246149Ssjg${.MAKE.DEPENDFILE}: ${OBJS} ${POBJS} ${SOBJS}
60246149Ssjg	-@for f in ${.ALLSRC:M*o:T:O:u:%=%.d}; do \
61246149Ssjg		echo ".-include \"$$f\""; \
62246149Ssjg	done > $@
63246149Ssjg
64246149Ssjg.endif
65