1# $NetBSD: bsd.dep.mk,v 1.82 2014/12/01 01:34:30 erh Exp $ 2 3##### Basic targets 4realdepend: beforedepend .depend afterdepend 5.ORDER: beforedepend .depend afterdepend 6 7beforedepend .depend afterdepend: # ensure existence 8 9##### Default values 10MKDEP?= mkdep 11MKDEPCXX?= mkdep 12MKDEP_SUFFIXES?= .o .d 13 14##### Build rules 15# some of the rules involve .h sources, so remove them from mkdep line 16 17.if defined(SRCS) && !empty(SRCS) 18__acpp_flags= ${_ASM_TRADITIONAL_CPP} 19 20.if defined(NODPSRCS) 21.for f in ${SRCS} ${DPSRCS} 22.if "${NODPSRCS:M${f}}" == "" 23__DPSRCS.all+= ${f:C/\.(c|m|s|S|C|cc|cpp|cxx)$/.d/} 24.endif 25.endfor 26beforedepend: ${DPSRCS} 27.else 28__DPSRCS.all+= ${SRCS:C/\.(c|m|s|S|C|cc|cpp|cxx)$/.d/} \ 29 ${DPSRCS:C/\.(c|m|s|S|C|cc|cpp|cxx)$/.d/} 30.endif 31__DPSRCS.d= ${__DPSRCS.all:O:u:M*.d} 32__DPSRCS.notd= ${__DPSRCS.all:O:u:N*.d} 33 34.NOPATH: .depend ${__DPSRCS.d} 35 36.if !empty(__DPSRCS.d) # { 37${__DPSRCS.d}: ${__DPSRCS.notd} ${DPSRCS} 38.endif # } 39 40MKDEPSUFFLAGS=-s ${MKDEP_SUFFIXES:Q} 41 42.if defined(MKDEPINCLUDES) && ${MKDEPINCLUDES} != "no" 43.STALE: 44 @echo Rebuilding dependency file: ${.ALLSRC} 45 @rm -f ${.ALLSRC} 46 @(cd ${.CURDIR} && ${MAKE} depend) 47_MKDEP_MERGEFLAGS=-i 48_MKDEP_FILEFLAGS=${MKDEPSUFFLAGS} 49.else 50_MKDEP_MERGEFLAGS=${MKDEPSUFFLAGS} 51_MKDEP_FILEFLAGS= 52.endif 53 54.depend: ${__DPSRCS.d} 55 ${_MKTARGET_CREATE} 56 rm -f .depend 57 ${MKDEP} ${_MKDEP_MERGEFLAGS} -d -f ${.TARGET} ${__DPSRCS.d} 58 59.SUFFIXES: .d .s .S .c .C .cc .cpp .cxx .m 60 61.c.d: 62 ${_MKTARGET_CREATE} 63 ${MKDEP} -f ${.TARGET}.tmp ${_MKDEP_FILEFLAGS} -- ${MKDEPFLAGS} \ 64 ${CFLAGS:M-std=*} ${CFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \ 65 ${CPPFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \ 66 ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} && \ 67 mv ${.TARGET}.tmp ${.TARGET} 68 69.m.d: 70 ${_MKTARGET_CREATE} 71 ${MKDEP} -f ${.TARGET}.tmp ${_MKDEP_FILEFLAGS} -- ${MKDEPFLAGS} \ 72 ${OBJCFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \ 73 ${CPPFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \ 74 ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} && \ 75 mv ${.TARGET}.tmp ${.TARGET} 76 77.s.d .S.d: 78 ${_MKTARGET_CREATE} 79 ${MKDEP} -f ${.TARGET}.tmp ${_MKDEP_FILEFLAGS} -- ${MKDEPFLAGS} \ 80 ${AFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \ 81 ${CPPFLAGS} ${AFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} \ 82 ${__acpp_flags} ${.IMPSRC} && \ 83 mv ${.TARGET}.tmp ${.TARGET} 84 85.C.d .cc.d .cpp.d .cxx.d: 86 ${_MKTARGET_CREATE} 87 ${MKDEPCXX} -f ${.TARGET}.tmp ${_MKDEP_FILEFLAGS} -- ${MKDEPFLAGS} \ 88 ${CXXFLAGS:M-std=*} ${CXXFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \ 89 ${CPPFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \ 90 ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} && \ 91 mv ${.TARGET}.tmp ${.TARGET} 92 93.endif # defined(SRCS) && !empty(SRCS) # } 94 95##### Clean rules 96.if defined(SRCS) && !empty(SRCS) 97CLEANDIRFILES+= .depend ${__DPSRCS.d} ${__DPSRCS.d:.d=.d.tmp} ${.CURDIR}/tags ${CLEANDEPEND} 98.endif 99 100##### Custom rules 101.if !target(tags) 102tags: ${SRCS} 103.if defined(SRCS) && !empty(SRCS) 104 ${_MKTARGET_CREATE} 105 -cd "${.CURDIR}"; ctags -f /dev/stdout ${.ALLSRC:N*.h} | \ 106 ${TOOL_SED} "s;\${.CURDIR}/;;" > tags 107.endif 108.endif 109 110##### Pull in related .mk logic 111.include <bsd.clean.mk> 112