1246149Ssjg# 2246149Ssjg# RCSid: 3321964Ssjg# $Id: auto.dep.mk,v 1.5 2016/04/05 15:58:37 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 21292068Ssjg# set MKDEP_MK=auto.dep.mk 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 48321964Ssjg.if ${MAKE_VERSION} < 20160218 49246149Ssjg# skip generating dependfile for misc targets 50246149Ssjg.if ${.TARGETS:Uall:M*all} != "" 51246149Ssjg.END: ${.MAKE.DEPENDFILE} 52246149Ssjg.endif 53246149Ssjg 54246149Ssjg# doing 'make depend' isn't a big win with this model 55246149Ssjg.if !target(depend) 56246149Ssjgdepend: ${.MAKE.DEPENDFILE} 57246149Ssjg.endif 58246149Ssjg 59246149Ssjg# this is trivial 60246149Ssjg${.MAKE.DEPENDFILE}: ${OBJS} ${POBJS} ${SOBJS} 61246149Ssjg -@for f in ${.ALLSRC:M*o:T:O:u:%=%.d}; do \ 62246149Ssjg echo ".-include \"$$f\""; \ 63246149Ssjg done > $@ 64321964Ssjg.else 65321964Ssjg# we have .dinclude 66321964Ssjg.if empty(_SKIP_BUILD) 67321964Ssjg_all_objs = ${OBJS} ${POBJS} ${SOBJS} 68321964Ssjg.for d in ${_all_objs:M*o:T:O:u:%=%.d} 69321964Ssjg.dinclude <$d> 70321964Ssjg.endfor 71321964Ssjg.endif 72246149Ssjg 73246149Ssjg.endif 74321964Ssjg.endif 75