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