1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
# $NetBSD: bsd.sys.mk,v 1.314 2023/06/03 21:24:57 lukem Exp $
#
# Build definitions used for NetBSD source tree builds.
.if !defined(_BSD_SYS_MK_)
_BSD_SYS_MK_=1
.if !empty(.INCLUDEDFROMFILE:MMakefile*)
error1:
@(echo "bsd.sys.mk should not be included from Makefiles" >& 2; exit 1)
.endif
.if !defined(_BSD_OWN_MK_)
error2:
@(echo "bsd.own.mk must be included before bsd.sys.mk" >& 2; exit 1)
.endif
# XXX: LLVM does not support -iremap and -fdebug-*
.if ${MKREPRO:Uno} == "yes" && ${MKLLVM:Uno} != "yes"
.export NETBSDSRCDIR DESTDIR X11SRCDIR
.if !empty(DESTDIR)
CPPFLAGS+= -Wp,-iremap,${DESTDIR}:
REPROFLAGS+= -fdebug-prefix-map=\$$DESTDIR=
.endif
CPPFLAGS+= -Wp,-fno-canonical-system-headers
CPPFLAGS+= -Wp,-iremap,${NETBSDSRCDIR}:/usr/src
CPPFLAGS+= -Wp,-iremap,${X11SRCDIR}:/usr/xsrc
REPROFLAGS+= -fdebug-prefix-map=\$$NETBSDSRCDIR=/usr/src
REPROFLAGS+= -fdebug-prefix-map=\$$X11SRCDIR=/usr/xsrc
.if defined(MAKEOBJDIRPREFIX)
NETBSDOBJDIR= ${MAKEOBJDIRPREFIX}${NETBSDSRCDIR}
.endif
.if defined(NETBSDOBJDIR)
.export NETBSDOBJDIR
REPROFLAGS+= -fdebug-prefix-map=\$$NETBSDOBJDIR=/usr/obj
.endif
LINTFLAGS+= -R${NETBSDSRCDIR}=/usr/src -R${X11SRCDIR}=/usr/xsrc
LINTFLAGS+= -R${DESTDIR}=
# XXX: Cannot handle MAKEOBJDIR, yet.
REPROFLAGS+= -fdebug-regex-map='/usr/src/(.*)/obj$$=/usr/obj/\1'
REPROFLAGS+= -fdebug-regex-map='/usr/src/(.*)/obj/(.*)=/usr/obj/\1/\2'
REPROFLAGS+= -fdebug-regex-map='/usr/src/(.*)/obj\..*=/usr/obj/\1'
REPROFLAGS+= -fdebug-regex-map='/usr/src/(.*)/obj\..*/(.*)=/usr/obj/\1/\2'
CFLAGS+= ${REPROFLAGS}
CXXFLAGS+= ${REPROFLAGS}
.endif
# NetBSD sources use C99 style, with some GCC extensions.
# Coverity does not like -std=gnu99
.if !defined(COVERITY_TOP_CONFIG)
CFLAGS+= ${${ACTIVE_CC} == "clang":? -std=gnu99 :}
CFLAGS+= ${${ACTIVE_CC} == "gcc":? -std=gnu99 :}
CFLAGS+= ${${ACTIVE_CC} == "pcc":? -std=gnu99 :}
.endif
.if defined(WARNS)
CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wno-sign-compare -Wno-pointer-sign :}
.if ${WARNS} > 0
CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
#CFLAGS+= -Wmissing-declarations -Wredundant-decls -Wnested-externs
# Add -Wno-sign-compare. -Wsign-compare is included in -Wall as of GCC 3.3,
# but our sources aren't up for it yet. Also, add -Wno-traditional because
# gcc includes #elif in the warnings, which is 'this code will not compile
# in a traditional environment' warning, as opposed to 'this code behaves
# differently in traditional and ansi environments' which is the warning
# we wanted, and now we don't get anymore.
CFLAGS+= -Wno-sign-compare
# Don't suppress warnings coming from constructs in system headers.
# Our system headers should be clean and we want to warn about things like:
# isdigit((char)1)
CFLAGS+= ${${ACTIVE_CC} == "gcc" :? -Wsystem-headers :}
CFLAGS+= ${${ACTIVE_CC} == "gcc" :? -Wno-traditional :}
.if !defined(NOGCCERROR)
# Set assembler warnings to be fatal
CFLAGS+= ${${ACTIVE_CC} == "gcc" :? -Wa,--fatal-warnings :}
.endif
# Set linker warnings to be fatal
# XXX no proper way to avoid "FOO is a patented algorithm" warnings
# XXX on linking static libs
.if (!defined(MKPIC) || ${MKPIC} != "no") && \
(!defined(LDSTATIC) || ${LDSTATIC} != "-static")
# XXX there are some strange problems not yet resolved
. if !defined(HAVE_GCC) || defined(HAVE_LLVM)
LDFLAGS+= -Wl,--fatal-warnings
. endif
.endif
.endif
LDFLAGS+= -Wl,--warn-shared-textrel
.if ${WARNS} > 1
CFLAGS+= -Wreturn-type -Wswitch -Wshadow
.endif
.if ${WARNS} > 2
CFLAGS+= -Wcast-qual -Wwrite-strings
CFLAGS+= -Wextra -Wno-unused-parameter
# Readd -Wno-sign-compare to override -Wextra with clang
CFLAGS+= -Wno-sign-compare
.if "${ACTIVE_CC}" == "gcc" && ${HAVE_GCC} < 8
# XXX: Won't warn about anything. -Wabi warns about differences from
# the most up-to-date ABI, which in g++ 8 is used by default.
CXXFLAGS+= -Wabi
.endif
CXXFLAGS+= -Wold-style-cast
CXXFLAGS+= -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder \
-Wno-deprecated -Woverloaded-virtual -Wsign-promo -Wsynth
CXXFLAGS+= ${${ACTIVE_CXX} == "gcc":? -Wno-non-template-friend -Wno-pmf-conversions :}
.endif
.if ${WARNS} > 3 && (defined(HAVE_GCC) || defined(HAVE_LLVM))
.if ${WARNS} > 4
CFLAGS+= -Wold-style-definition
.endif
.if ${WARNS} > 5
CFLAGS+= -Wconversion
.endif
CFLAGS+= -Wsign-compare -Wformat=2
CFLAGS+= ${${ACTIVE_CC} == "gcc":? -Wno-format-zero-length :}
.endif
.if ${WARNS} > 3 && defined(HAVE_LLVM)
CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wpointer-sign -Wmissing-noreturn :}
.endif
.if (defined(HAVE_GCC) \
&& (${MACHINE_ARCH} == "coldfire" || \
${MACHINE_CPU} == "sh3" || \
${MACHINE_CPU} == "m68k"))
# XXX GCC 4.5 for sh3 and m68k (which we compile with -Os) is extra noisy for
# cases it should be better with
CFLAGS+= -Wno-uninitialized
CFLAGS+= -Wno-maybe-uninitialized
.endif
.endif
.if ${MKRELRO:Uno} != "no"
LDFLAGS+= -Wl,-z,relro
.endif
.if ${MKRELRO:Uno} == "full" && ${NOFULLRELRO:Uno} == "no"
LDFLAGS+= -Wl,-z,now
.endif
.if ${MKSANITIZER:Uno} == "yes"
SANITIZERFLAGS:= -fsanitize=${USE_SANITIZER} ${SANITIZERFLAGS}
.else
SANITIZERFLAGS= # empty
.endif
.if ${MKLIBCSANITIZER:Uno} == "yes"
LIBCSANITIZERFLAGS:= -fsanitize=${USE_LIBCSANITIZER} ${LIBCSANITIZERFLAGS}
LIBCSANITIZERFLAGS+= -fno-sanitize=vptr # Unsupported in micro-UBSan
.else
LIBCSANITIZERFLAGS= # empty
.endif
CWARNFLAGS+= ${CWARNFLAGS.${ACTIVE_CC}}
CPPFLAGS+= ${AUDIT:D-D__AUDIT__}
_NOWERROR= ${defined(NOGCCERROR) || (${ACTIVE_CC} == "clang" && defined(NOCLANGERROR)):?yes:no}
CFLAGS+= ${${_NOWERROR} == "no" :?-Werror:} ${CWARNFLAGS}
.if !empty(DESTDIR)
LINTFLAGS+= -d ${DESTDIR}
.endif
.if !defined(NOSSP) && (${USE_SSP:Uno} != "no") && (${BINDIR:Ux} != "/usr/mdec")
. if !defined(KERNSRCDIR) && !defined(KERN) # not for kernels / kern modules
CPPFLAGS+= -D_FORTIFY_SOURCE=2
. endif
. if !defined(COVERITY_TOP_CONFIG)
COPTS+= -fstack-protector -Wstack-protector
# GCC 4.8 on m68k erroneously does not protect functions with
# variables needing special alignment, see
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59674
# (the underlying issue for sh and vax may be different, needs more
# investigation, symptoms are similar but for different sources)
# also true for GCC 5, assume GCC 6 too.
. if "${ACTIVE_CC}" == "gcc" && \
( ${HAVE_GCC} == "5" || \
${HAVE_GCC} == "6" ) && \
( ${MACHINE_CPU} == "sh3" || \
${MACHINE_ARCH} == "vax" || \
${MACHINE_CPU} == "m68k" || \
${MACHINE_CPU} == "or1k" )
COPTS+= -Wno-error=stack-protector
. endif
COPTS+= ${${ACTIVE_CC} == "clang":? --param ssp-buffer-size=1 :}
COPTS+= ${${ACTIVE_CC} == "gcc":? --param ssp-buffer-size=1 :}
. endif
.endif
.if ${MKSOFTFLOAT:Uno} != "no"
# sh3 defaults to soft-float and specifies hard-float a different way
.if ${MACHINE_CPU} != "sh3"
COPTS+= ${${ACTIVE_CC} == "gcc":? -msoft-float :}
FOPTS+= -msoft-float
.endif
.elif ${MACHINE_ARCH} == "coldfire"
COPTS+= -mhard-float
FOPTS+= -mhard-float
.endif
#.if !empty(MACHINE_ARCH:Mearmv7*)
#COPTS+= -mthumb
#FOPTS+= -mthumb
#.endif
.if ${MKIEEEFP:Uno} != "no"
.if ${MACHINE_ARCH} == "alpha"
CFLAGS+= -mieee
FFLAGS+= -mieee
.endif
.endif
.if ${MACHINE} == "sparc64" && ${MACHINE_ARCH} == "sparc"
CFLAGS+= -Wa,-Av8plus
.endif
.if !defined(NOGCCERROR)
.if ${MACHINE_MIPS64}
CPUFLAGS+= -Wa,--fatal-warnings
.endif
.endif
#.if ${MACHINE} == "sbmips"
#CFLAGS+= -mips64 -mtune=sb1
#.endif
#.if ${MACHINE_MIPS64} && defined(MKPIC) && ${MKPIC} == "no"
#CPUFLAGS+= -mno-abicalls -fno-PIC
#.endif
CFLAGS+= ${CPUFLAGS}
AFLAGS+= ${CPUFLAGS}
.if ${KCOV:U0} > 0
KCOVFLAGS= -fsanitize-coverage=trace-pc,trace-cmp
.for f in subr_kcov.c subr_asan.c subr_csan.c subr_msan.c ubsan.c
KCOVFLAGS.${f}= # empty
.endfor
CFLAGS+= ${KCOVFLAGS.${.IMPSRC:T}:U${KCOVFLAGS}}
.endif
.if !defined(NOPIE) && (!defined(LDSTATIC) || ${LDSTATIC} != "-static")
# Position Independent Executable flags
PIE_CFLAGS?= -fPIE
PIE_LDFLAGS?= -pie ${${ACTIVE_CC} == "gcc":? -shared-libgcc :}
PIE_AFLAGS?= -fPIE
.endif
ARM_ELF2AOUT?= elf2aout
M68K_ELF2AOUT?= elf2aout
MIPS_ELF2ECOFF?= elf2ecoff
MKDEP?= mkdep
MKDEPCXX?= mkdep
OBJCOPY?= objcopy
OBJDUMP?= objdump
PAXCTL?= paxctl
STRIP?= strip
.SUFFIXES: .o .ln .lo .c .cc .cpp .cxx .C .m ${YHEADER:D.h}
# C
.c.o:
${_MKTARGET_COMPILE}
${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
${CTFCONVERT_RUN}
.c.ln:
${_MKTARGET_COMPILE}
${LINT} ${LINTFLAGS} ${LINTFLAGS.${.IMPSRC:T}} \
${CPPFLAGS:C/-([IDUW])[ ]*/-\1/Wg:M-[IDUW]*} \
${CPPFLAGS.${.IMPSRC:T}:C/-([IDUW])[ ]*/-\1/Wg:M-[IDUW]*} \
-i ${.IMPSRC}
# C++
.cc.o .cpp.o .cxx.o .C.o:
${_MKTARGET_COMPILE}
${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
# Objective C
# (Defined here rather than in <sys.mk> because `.m' is not just
# used for Objective C source)
.m.o:
${_MKTARGET_COMPILE}
${COMPILE.m} ${OBJCOPTS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
${CTFCONVERT_RUN}
# Host-compiled C objects
# The intermediate step is necessary for Sun CC, which objects to calling
# object files anything but *.o
.c.lo:
${_MKTARGET_COMPILE}
${HOST_COMPILE.c} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
${MV} ${.TARGET}.o ${.TARGET}
# C++
.cc.lo .cpp.lo .cxx.lo .C.lo:
${_MKTARGET_COMPILE}
${HOST_COMPILE.cc} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
${MV} ${.TARGET}.o ${.TARGET}
# Assembly
.s.o:
${_MKTARGET_COMPILE}
${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
${CTFCONVERT_RUN}
.S.o:
${_MKTARGET_COMPILE}
${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} ${OBJECT_TARGET}
${CTFCONVERT_RUN}
# Lex
LFLAGS+= ${LPREFIX.${.IMPSRC:T}:D-P${LPREFIX.${.IMPSRC:T}}}
LFLAGS+= ${LPREFIX:D-P${LPREFIX}} ${LFLAGS.${.IMPSRC:T}}
.l.c:
${_MKTARGET_LEX}
${LEX.l} -o${.TARGET} ${.IMPSRC}
# Yacc
YFLAGS+= ${YPREFIX.${.IMPSRC:T}:D-p${YPREFIX.${.IMPSRC:T}}} ${YHEADER.${.IMPSRC:T}:D-d}
YFLAGS+= ${YPREFIX:D-p${YPREFIX}} ${YHEADER:D-d} ${YFLAGS.${.IMPSRC:T}}
.y.c:
${_MKTARGET_YACC}
${YACC.y} -o ${.TARGET} ${.IMPSRC}
.ifdef YHEADER
.if empty(.MAKEFLAGS:M-n)
.y.h: ${.TARGET:.h=.c}
.endif
.endif
# Objcopy
.if ${MACHINE_ARCH} == aarch64eb
# AARCH64 big endian needs to preserve $x/$d symbols for the linker.
OBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][dx]' -K '[$$][dx]\.*'
.elif ${MACHINE_CPU} == "arm"
# ARM big endian needs to preserve $a/$d/$t symbols for the linker.
OBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][adt]' -K '[$$][adt]\.*'
.endif
.if ${MKSTRIPSYM} != "no"
OBJCOPYLIBFLAGS?=${"${.TARGET:M*.po}" != "":?-X:-x} ${OBJCOPYLIBFLAGS_EXTRA}
.else
OBJCOPYLIBFLAGS?=-X ${OBJCOPYLIBFLAGS_EXTRA}
.endif
.endif # !defined(_BSD_SYS_MK_)
|