ramdisk Makefile: CLEANFILES fix
[minix.git] / share / mk / bsd.sys.mk
blob68c598d94db5c38b7bbc42d879ffd512d10e0ecb
1 # $NetBSD: bsd.sys.mk,v 1.220 2012/09/23 19:20:44 joerg Exp $
3 # Build definitions used for NetBSD source tree builds.
5 .if !defined(_BSD_SYS_MK_)
6 _BSD_SYS_MK_=1
8 .if ${HOST_OSTYPE:C/\-.*//:U} == "Minix"
9 HOST_CPP?= /usr/lib/cpp
10 HOST_LDFLAGS?= -static
11 .endif
13 .if ${MKREPRO:Uno} == "yes"
14 CPPFLAGS+= -Wp,-iremap,${NETBSDSRCDIR}:/usr/src
15 CPPFLAGS+= -Wp,-iremap,${DESTDIR}/:/
16 CPPFLAGS+= -Wp,-iremap,${X11SRCDIR}:/usr/xsrc
17 .endif
19 # Enable c99 mode by default.
20 # This has the side effect of complaining for missing prototypes
21 # implicit type declarations and missing return statements.
22 .if defined(HAVE_GCC) || defined(HAVE_LLVM)
23 CFLAGS+= -std=gnu99
24 .endif
26 .if defined(WARNS)
27 CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wno-sign-compare -Wno-pointer-sign :}
28 .if ${WARNS} > 0
29 CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
30 #CFLAGS+= -Wmissing-declarations -Wredundant-decls -Wnested-externs
31 # Add -Wno-sign-compare. -Wsign-compare is included in -Wall as of GCC 3.3,
32 # but our sources aren't up for it yet. Also, add -Wno-traditional because
33 # gcc includes #elif in the warnings, which is 'this code will not compile
34 # in a traditional environment' warning, as opposed to 'this code behaves
35 # differently in traditional and ansi environments' which is the warning
36 # we wanted, and now we don't get anymore.
37 CFLAGS+= -Wno-sign-compare
38 CFLAGS+= ${${ACTIVE_CC} != "clang":? -Wno-traditional :}
39 .if !defined(NOGCCERROR)
40 # Set assembler warnings to be fatal
41 #CFLAGS+= -Wa,--fatal-warnings
42 # LSC Clang version 2.9 those not support this flag
43 CFLAGS+= ${${HAVE_LLVM:U"0.0"} != "2.9":? -Wa,--fatal-warnings:}
44 .endif
45 # Set linker warnings to be fatal
46 # XXX no proper way to avoid "FOO is a patented algorithm" warnings
47 # XXX on linking static libs
48 .if (!defined(MKPIC) || ${MKPIC} != "no") && \
49 (!defined(LDSTATIC) || ${LDSTATIC} != "-static")
50 # XXX there are some strange problems not yet resolved
51 . if !defined(HAVE_GCC) || defined(HAVE_LLVM)
52 LDFLAGS+= -Wl,--fatal-warnings
53 . endif
54 .endif
55 .endif
56 .if ${WARNS} > 1
57 CFLAGS+= -Wreturn-type -Wswitch -Wshadow
58 .endif
59 .if ${WARNS} > 2
60 CFLAGS+= -Wcast-qual -Wwrite-strings
61 CFLAGS+= -Wextra -Wno-unused-parameter
62 # Readd -Wno-sign-compare to override -Wextra with clang
63 CFLAGS+= -Wno-sign-compare
64 CXXFLAGS+= -Wabi
65 CXXFLAGS+= -Wold-style-cast
66 CXXFLAGS+= -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder \
67 -Wno-deprecated -Woverloaded-virtual -Wsign-promo -Wsynth
68 CXXFLAGS+= ${${ACTIVE_CXX} == "gcc":? -Wno-non-template-friend -Wno-pmf-conversions :}
69 .endif
70 .if ${WARNS} > 3 && (defined(HAVE_GCC) || defined(HAVE_LLVM))
71 .if ${WARNS} > 4
72 CFLAGS+= -Wold-style-definition
73 .endif
74 CFLAGS+= -Wsign-compare -Wformat=2
75 CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wno-error=format-nonliteral :}
76 CFLAGS+= ${${ACTIVE_CC} == "gcc":? -Wno-format-zero-length :}
77 .endif
78 .if ${WARNS} > 3 && defined(HAVE_LLVM)
79 CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wpointer-sign -Wmissing-noreturn :}
80 .endif
81 .if (defined(HAVE_GCC) && ${HAVE_GCC} == 45 \
82 && (${MACHINE_ARCH} == "sh3eb" || \
83 ${MACHINE_ARCH} == "sh3el" || \
84 ${MACHINE_ARCH} == "m68k" || \
85 ${MACHINE_ARCH} == "m68000"))
86 # XXX GCC 4.5 for sh3 and m68k (which we compile with -Os) is extra noisy for
87 # cases it should be better with
88 CFLAGS+= -Wno-uninitialized
89 .endif
90 .endif
92 CWARNFLAGS+= ${CWARNFLAGS.${ACTIVE_CC}}
94 CPPFLAGS+= ${AUDIT:D-D__AUDIT__}
95 _NOWERROR= ${defined(NOGCCERROR) || (${ACTIVE_CC} == "clang" && defined(NOCLANGERROR)):?yes:no}
96 CFLAGS+= ${${_NOWERROR} == "no" :?-Werror:} ${CWARNFLAGS}
97 LINTFLAGS+= ${DESTDIR:D-d ${DESTDIR}/usr/include}
99 .if (${MACHINE_ARCH} == "alpha") || \
100 (${MACHINE_ARCH} == "hppa") || \
101 (${MACHINE_ARCH} == "ia64") || \
102 (${MACHINE_ARCH} == "mipsel") || (${MACHINE_ARCH} == "mipseb") || \
103 (${MACHINE_ARCH} == "mips64el") || (${MACHINE_ARCH} == "mips64eb")
104 HAS_SSP= no
105 .else
106 HAS_SSP= yes
107 .endif
109 .if ${USE_FORT:Uno} != "no"
110 USE_SSP?= yes
111 .if !defined(KERNSRCDIR) && !defined(KERN) # not for kernels nor kern modules
112 CPPFLAGS+= -D_FORTIFY_SOURCE=2
113 .endif
114 .endif
116 .if (${USE_SSP:Uno} != "no") && (${BINDIR:Ux} != "/usr/mdec")
117 .if ${HAS_SSP} == "yes"
118 COPTS+= -fstack-protector -Wstack-protector
119 .if defined(__MINIX)
120 COPTS+= ${${ACTIVE_CC} == "clang":? -mllvm -stack-protector-buffer-size=1 :}
121 .else
122 COPTS+= ${${ACTIVE_CC} == "clang":? --param ssp-buffer-size=1 :}
123 .endif # defined(__MINIX)
124 COPTS+= ${${ACTIVE_CC} == "gcc":? --param ssp-buffer-size=1 :}
125 .endif
126 .endif
128 .if ${MKSOFTFLOAT:Uno} != "no"
129 COPTS+= -msoft-float
130 FOPTS+= -msoft-float
131 .endif
133 .if ${MKIEEEFP:Uno} != "no"
134 .if ${MACHINE_ARCH} == "alpha"
135 CFLAGS+= -mieee
136 FFLAGS+= -mieee
137 .endif
138 .endif
140 .if ${MACHINE} == "sparc64" && ${MACHINE_ARCH} == "sparc"
141 CFLAGS+= -Wa,-Av8plus
142 .endif
144 .if !defined(NOGCCERROR)
145 .if (${MACHINE_ARCH} == "mips64el") || (${MACHINE_ARCH} == "mips64eb")
146 CPUFLAGS+= -Wa,--fatal-warnings
147 .endif
148 .endif
150 #.if ${MACHINE} == "sbmips"
151 #CFLAGS+= -mips64 -mtune=sb1
152 #.endif
154 #.if (${MACHINE_ARCH} == "mips64el" || ${MACHINE_ARCH} == "mips64eb") && \
155 # (defined(MKPIC) && ${MKPIC} == "no")
156 #CPUFLAGS+= -mno-abicalls -fno-PIC
157 #.endif
158 CFLAGS+= ${CPUFLAGS}
159 AFLAGS+= ${CPUFLAGS}
161 .if !defined(LDSTATIC) || ${LDSTATIC} != "-static"
162 # Position Independent Executable flags
163 PIE_CFLAGS?= -fPIC -DPIC
164 PIE_LDFLAGS?= -Wl,-pie -shared-libgcc
165 PIE_AFLAGS?= -fPIC -DPIC
166 .endif
168 # Helpers for cross-compiling
169 HOST_CC?= cc
170 HOST_CFLAGS?= -O
171 HOST_COMPILE.c?=${HOST_CC} ${HOST_CFLAGS} ${HOST_CPPFLAGS} -c
172 HOST_COMPILE.cc?= ${HOST_CXX} ${HOST_CXXFLAGS} ${HOST_CPPFLAGS} -c
173 .if defined(HOSTPROG_CXX)
174 HOST_LINK.c?= ${HOST_CXX} ${HOST_CXXFLAGS} ${HOST_CPPFLAGS} ${HOST_LDFLAGS}
175 .else
176 HOST_LINK.c?= ${HOST_CC} ${HOST_CFLAGS} ${HOST_CPPFLAGS} ${HOST_LDFLAGS}
177 .endif
179 HOST_CXX?= c++
180 HOST_CXXFLAGS?= -O
182 HOST_CPP?= cpp
183 HOST_CPPFLAGS?=
185 HOST_LD?= ld
186 HOST_LDFLAGS?=
188 HOST_AR?= ar
189 HOST_RANLIB?= ranlib
191 HOST_LN?= ln
193 # HOST_SH must be an absolute path
194 HOST_SH?= /bin/sh
196 ELF2ECOFF?= elf2ecoff
197 MKDEP?= mkdep
198 OBJCOPY?= objcopy
199 OBJDUMP?= objdump
200 PAXCTL?= paxctl
201 STRIP?= strip
203 # TOOL_* variables are defined in bsd.own.mk
205 .SUFFIXES: .o .ln .lo .c .cc .cpp .cxx .C .m ${YHEADER:D.h}
208 .c.o:
209 ${_MKTARGET_COMPILE}
210 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
211 .if defined(CTFCONVERT)
212 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
213 .endif
215 .c.ln:
216 ${_MKTARGET_COMPILE}
217 ${LINT} ${LINTFLAGS} ${LINTFLAGS.${.IMPSRC:T}} \
218 ${CPPFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \
219 ${CPPFLAGS.${.IMPSRC:T}:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \
220 -i ${.IMPSRC}
222 # C++
223 .cc.o .cpp.o .cxx.o .C.o:
224 ${_MKTARGET_COMPILE}
225 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
227 # Objective C
228 # (Defined here rather than in <sys.mk> because `.m' is not just
229 # used for Objective C source)
230 .m.o:
231 ${_MKTARGET_COMPILE}
232 ${COMPILE.m} ${OBJCOPTS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC}
233 .if defined(CTFCONVERT)
234 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
235 .endif
237 # Host-compiled C objects
238 # The intermediate step is necessary for Sun CC, which objects to calling
239 # object files anything but *.o
240 .c.lo:
241 ${_MKTARGET_COMPILE}
242 ${HOST_COMPILE.c} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
243 mv ${.TARGET}.o ${.TARGET}
245 # C++
246 .cc.lo .cpp.lo .cxx.lo .C.lo:
247 ${_MKTARGET_COMPILE}
248 ${HOST_COMPILE.cc} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
249 mv ${.TARGET}.o ${.TARGET}
251 # Assembly
252 .s.o:
253 ${_MKTARGET_COMPILE}
254 ${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
255 .if defined(CTFCONVERT)
256 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
257 .endif
259 .S.o:
260 ${_MKTARGET_COMPILE}
261 ${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
262 .if defined(CTFCONVERT)
263 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
264 .endif
266 # Lex
267 LFLAGS+= ${LPREFIX.${.IMPSRC:T}:D-P${LPREFIX.${.IMPSRC:T}}}
268 LFLAGS+= ${LPREFIX:D-P${LPREFIX}}
270 .l.c:
271 ${_MKTARGET_LEX}
272 ${LEX.l} -o${.TARGET} ${.IMPSRC}
274 # Yacc
275 YFLAGS+= ${YPREFIX.${.IMPSRC:T}:D-p${YPREFIX.${.IMPSRC:T}}} ${YHEADER.${.IMPSRC:T}:D-d}
276 YFLAGS+= ${YPREFIX:D-p${YPREFIX}} ${YHEADER:D-d}
278 .y.c:
279 ${_MKTARGET_YACC}
280 ${YACC.y} -o ${.TARGET} ${.IMPSRC}
282 .ifdef YHEADER
283 .if empty(.MAKEFLAGS:M-n)
284 .y.h: ${.TARGET:.h=.c}
285 .endif
286 .endif
288 # Objcopy
289 OBJCOPYLIBFLAGS?=${"${.TARGET:M*.po}" != "":?-X:-x}
291 .endif # !defined(_BSD_SYS_MK_)