xref: /freebsd/contrib/bmake/mk/auto.dep.mk (revision db29cad8157b2f3afdb890831ddf73da0f4c01c0)
13cbdda60SSimon J. Gerraty#
23cbdda60SSimon J. Gerraty# RCSid:
3*db29cad8SSimon J. Gerraty#	$Id: auto.dep.mk,v 1.3 2014/08/04 05:19:10 sjg Exp $
43cbdda60SSimon J. Gerraty#
53cbdda60SSimon J. Gerraty#	@(#) Copyright (c) 2010, Simon J. Gerraty
63cbdda60SSimon J. Gerraty#
73cbdda60SSimon J. Gerraty#	This file is provided in the hope that it will
83cbdda60SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
93cbdda60SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
103cbdda60SSimon J. Gerraty#	use this file is hereby granted provided that
113cbdda60SSimon J. Gerraty#	the above copyright notice and this notice are
123cbdda60SSimon J. Gerraty#	left intact.
133cbdda60SSimon J. Gerraty#
143cbdda60SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
153cbdda60SSimon J. Gerraty#	sjg@crufty.net
163cbdda60SSimon J. Gerraty#
173cbdda60SSimon J. Gerraty
183cbdda60SSimon J. Gerraty# This module provides automagic dependency generation along the
193cbdda60SSimon J. Gerraty# lines suggested in the GNU make.info
203cbdda60SSimon J. Gerraty
21*db29cad8SSimon J. Gerraty# set MKDEP_MK=auto.dep.mk and dep.mk will include us
223cbdda60SSimon J. Gerraty
233cbdda60SSimon J. Gerraty# This version differs from autodep.mk, in that
243cbdda60SSimon J. Gerraty# we use ${.TARGET:T}.d rather than ${.TARGET:T:R}.d
253cbdda60SSimon J. Gerraty# this makes it simpler to get the args to -MF and -MT right
263cbdda60SSimon J. Gerraty# and ensure we can simply include all the .d files.
273cbdda60SSimon J. Gerraty#
283cbdda60SSimon J. Gerraty# However suffix rules do not work with something like .o.d so we
293cbdda60SSimon J. Gerraty# don't even try to handle 'make depend' gracefully.
303cbdda60SSimon J. Gerraty# dep.mk will handle that itself.
313cbdda60SSimon J. Gerraty#
323cbdda60SSimon J. Gerraty.if !target(__${.PARSEFILE}__)
333cbdda60SSimon J. Gerraty__${.PARSEFILE}__:
343cbdda60SSimon J. Gerraty
353cbdda60SSimon J. Gerraty# this what bmake > 20100401 will look for
363cbdda60SSimon J. Gerraty.MAKE.DEPENDFILE ?= .depend
373cbdda60SSimon J. Gerraty
383cbdda60SSimon J. Gerraty# set this to -MMD to ignore /usr/include
393cbdda60SSimon J. Gerraty# actually it ignores <> so may not be a great idea
403cbdda60SSimon J. GerratyCFLAGS_MD ?= -MD
413cbdda60SSimon J. Gerraty# -MF etc not available on all gcc versions.
423cbdda60SSimon J. GerratyCFLAGS_MF ?= -MF ${.TARGET:T}.d -MT ${.TARGET:T}
433cbdda60SSimon J. GerratyCFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
443cbdda60SSimon J. GerratyCXXFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
453cbdda60SSimon J. Gerraty
463cbdda60SSimon J. GerratyCLEANFILES += .depend ${.MAKE.DEPENDFILE} *.d
473cbdda60SSimon J. Gerraty
483cbdda60SSimon J. Gerraty# skip generating dependfile for misc targets
493cbdda60SSimon J. Gerraty.if ${.TARGETS:Uall:M*all} != ""
503cbdda60SSimon J. Gerraty.END:	${.MAKE.DEPENDFILE}
513cbdda60SSimon J. Gerraty.endif
523cbdda60SSimon J. Gerraty
533cbdda60SSimon J. Gerraty# doing 'make depend' isn't a big win with this model
543cbdda60SSimon J. Gerraty.if !target(depend)
553cbdda60SSimon J. Gerratydepend: ${.MAKE.DEPENDFILE}
563cbdda60SSimon J. Gerraty.endif
573cbdda60SSimon J. Gerraty
583cbdda60SSimon J. Gerraty# this is trivial
593cbdda60SSimon J. Gerraty${.MAKE.DEPENDFILE}: ${OBJS} ${POBJS} ${SOBJS}
603cbdda60SSimon J. Gerraty	-@for f in ${.ALLSRC:M*o:T:O:u:%=%.d}; do \
613cbdda60SSimon J. Gerraty		echo ".-include \"$$f\""; \
623cbdda60SSimon J. Gerraty	done > $@
633cbdda60SSimon J. Gerraty
643cbdda60SSimon J. Gerraty.endif
65