xref: /freebsd/contrib/bmake/mk/auto.dep.mk (revision c59c3bf34db360695f07735bebc76a768cac5afc)
1*c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause
23cbdda60SSimon J. Gerraty#
33cbdda60SSimon J. Gerraty# RCSid:
4*c59c3bf3SSimon J. Gerraty#	$Id: auto.dep.mk,v 1.12 2024/02/17 17:26:57 sjg Exp $
53cbdda60SSimon J. Gerraty#
612904384SSimon J. Gerraty#	@(#) Copyright (c) 2010-2021, Simon J. Gerraty
73cbdda60SSimon J. Gerraty#
83cbdda60SSimon J. Gerraty#	This file is provided in the hope that it will
93cbdda60SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
103cbdda60SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
113cbdda60SSimon J. Gerraty#	use this file is hereby granted provided that
123cbdda60SSimon J. Gerraty#	the above copyright notice and this notice are
133cbdda60SSimon J. Gerraty#	left intact.
143cbdda60SSimon J. Gerraty#
153cbdda60SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
163cbdda60SSimon J. Gerraty#	sjg@crufty.net
173cbdda60SSimon J. Gerraty#
183cbdda60SSimon J. Gerraty
193cbdda60SSimon J. Gerraty# This module provides automagic dependency generation along the
203cbdda60SSimon J. Gerraty# lines suggested in the GNU make.info
213cbdda60SSimon J. Gerraty
22db29cad8SSimon J. Gerraty# set MKDEP_MK=auto.dep.mk and dep.mk will include us
233cbdda60SSimon J. Gerraty
243cbdda60SSimon J. Gerraty# This version differs from autodep.mk, in that
253cbdda60SSimon J. Gerraty# we use ${.TARGET:T}.d rather than ${.TARGET:T:R}.d
263cbdda60SSimon J. Gerraty# this makes it simpler to get the args to -MF and -MT right
273cbdda60SSimon J. Gerraty# and ensure we can simply include all the .d files.
283cbdda60SSimon J. Gerraty#
293cbdda60SSimon J. Gerraty# However suffix rules do not work with something like .o.d so we
303cbdda60SSimon J. Gerraty# don't even try to handle 'make depend' gracefully.
313cbdda60SSimon J. Gerraty# dep.mk will handle that itself.
323cbdda60SSimon J. Gerraty#
333cbdda60SSimon J. Gerraty.if !target(__${.PARSEFILE}__)
3412904384SSimon J. Gerraty__${.PARSEFILE}__: .NOTMAIN
353cbdda60SSimon J. Gerraty
363cbdda60SSimon J. Gerraty# set this to -MMD to ignore /usr/include
373cbdda60SSimon J. Gerraty# actually it ignores <> so may not be a great idea
383cbdda60SSimon J. GerratyCFLAGS_MD ?= -MD
393cbdda60SSimon J. Gerraty# -MF etc not available on all gcc versions.
4012904384SSimon J. Gerraty.if ${COMPILER_TYPE:Ugcc} == "gcc" && ${COMPILER_VERSION:U0} < 30000
4112904384SSimon J. GerratyCFLAGS_MF=
4212904384SSimon J. Gerraty.endif
433cbdda60SSimon J. GerratyCFLAGS_MF ?= -MF ${.TARGET:T}.d -MT ${.TARGET:T}
443cbdda60SSimon J. GerratyCFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
453cbdda60SSimon J. GerratyCXXFLAGS += ${CFLAGS_MD} ${CFLAGS_MF}
463cbdda60SSimon J. Gerraty
4712904384SSimon J. GerratyCLEANFILES += .depend *.d
483cbdda60SSimon J. Gerraty
4912904384SSimon J. Gerraty.if ${MAKE_VERSION} >= 20160218
503cbdda60SSimon J. Gerraty
5112904384SSimon J. Gerraty# we have .dinclude and this is all that is required
52be19d90bSSimon J. Gerraty.if empty(_SKIP_BUILD)
53be19d90bSSimon J. Gerraty_all_objs = ${OBJS} ${POBJS} ${SOBJS}
54be19d90bSSimon J. Gerraty.for d in ${_all_objs:M*o:T:O:u:%=%.d}
55e48f47ddSSimon J. Gerraty.dinclude <$d>
56be19d90bSSimon J. Gerraty.endfor
57be19d90bSSimon J. Gerraty.endif
583cbdda60SSimon J. Gerraty
5912904384SSimon J. Gerraty.else				# we lack .dinclude
6012904384SSimon J. Gerraty
6112904384SSimon J. Gerraty.if ${.MAKE.MODE:Unormal:Mmeta} != ""
6212904384SSimon J. Gerraty# ignore .MAKE.DEPENDFILE
6312904384SSimon J. GerratyDEPENDFILE = .depend
6412904384SSimon J. Gerraty.else
6512904384SSimon J. Gerraty# this what bmake > 20100401 will look for
6612904384SSimon J. Gerraty.MAKE.DEPENDFILE ?= .depend
6712904384SSimon J. GerratyDEPENDFILE ?= ${.MAKE.DEPENDFILE}
6812904384SSimon J. Gerraty.endif
6912904384SSimon J. Gerraty
7012904384SSimon J. GerratyCLEANFILES += ${DEPENDFILE}
7112904384SSimon J. Gerraty
7212904384SSimon J. Gerraty# skip generating dependfile for misc targets
7312904384SSimon J. Gerraty.if ${.TARGETS:Uall:M*all} != ""
7412904384SSimon J. Gerraty.END:	${DEPENDFILE}
7512904384SSimon J. Gerraty.endif
7612904384SSimon J. Gerraty
7712904384SSimon J. Gerraty# doing 'make depend' isn't a big win with this model
7812904384SSimon J. Gerraty.if !target(depend)
7912904384SSimon J. Gerratydepend: ${DEPENDFILE}
8012904384SSimon J. Gerraty.endif
8112904384SSimon J. Gerraty
8212904384SSimon J. Gerraty# this is trivial
8312904384SSimon J. Gerraty${DEPENDFILE}: ${OBJS} ${POBJS} ${SOBJS}
8412904384SSimon J. Gerraty	-@for f in ${.ALLSRC:M*o:T:O:u:%=%.d}; do \
8512904384SSimon J. Gerraty		echo ".-include \"$$f\""; \
8612904384SSimon J. Gerraty	done > $@
8712904384SSimon J. Gerraty
883cbdda60SSimon J. Gerraty.endif
89*c59c3bf3SSimon J. Gerraty
90*c59c3bf3SSimon J. Gerraty.-include <ccm.dep.mk>
91*c59c3bf3SSimon J. Gerraty
92be19d90bSSimon J. Gerraty.endif
93