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