etc/protocols - sync with NetBSD-8
[minix.git] / share / mk / bsd.dep.mk
blobc6cb5001980044967429583c01776b89ca783b6b
1 # $NetBSD: bsd.dep.mk,v 1.82 2014/12/01 01:34:30 erh Exp $
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)
6 CC?= clang
7 .endif
9 .if exists(/usr/pkg/bin/gcc) || exists(/usr/bin/gcc)
10 CC?= gcc
11 .endif
13 MKDEP?= CC=${CC:Q} mkdep
14 MKDEPCXX?= CC=${CXX:Q} mkdep
15 .endif # defined(__MINIX)
17 ##### Basic targets
18 realdepend: beforedepend .depend afterdepend
19 .ORDER: beforedepend .depend afterdepend
21 beforedepend .depend afterdepend: # ensure existence
23 ##### Default values
24 MKDEP?= mkdep
25 MKDEPCXX?= mkdep
26 MKDEP_SUFFIXES?= .o .d
28 ##### Build rules
29 # some of the rules involve .h sources, so remove them from mkdep line
31 .if defined(SRCS) && !empty(SRCS)
32 __acpp_flags= ${_ASM_TRADITIONAL_CPP}
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
40 beforedepend: ${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}
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)
53 .NOPATH: .depend ${__DPSRCS.d}
55 .if !empty(__DPSRCS.d) # {
56 ${__DPSRCS.d}: ${__DPSRCS.notd} ${DPSRCS}
57 .endif # }
59 MKDEPSUFFLAGS=-s ${MKDEP_SUFFIXES:Q}
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
73 .depend: ${__DPSRCS.d}
74 ${_MKTARGET_CREATE}
75 rm -f .depend
76 ${MKDEP} ${_MKDEP_MERGEFLAGS} -d -f ${.TARGET} ${__DPSRCS.d}
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
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)
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}
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}
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}
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}
124 .endif # defined(SRCS) && !empty(SRCS) # }
126 ##### Clean rules
127 .if defined(SRCS) && !empty(SRCS)
128 CLEANDIRFILES+= .depend ${__DPSRCS.d} ${__DPSRCS.d:.d=.d.tmp} ${.CURDIR}/tags ${CLEANDEPEND}
129 .endif
131 ##### Custom rules
132 .if !target(tags)
133 tags: ${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
141 ##### Pull in related .mk logic
142 .include <bsd.clean.mk>