Annotation of src/share/mk/bsd.sys.mk, Revision 1.276
1.276 ! christos 1: # $NetBSD: bsd.sys.mk,v 1.275 2018/02/02 01:02:41 mrg Exp $
1.1 christos 2: #
1.58 tv 3: # Build definitions used for NetBSD source tree builds.
1.2 cgd 4:
1.94 lukem 5: .if !defined(_BSD_SYS_MK_)
6: _BSD_SYS_MK_=1
1.96 lukem 7:
1.236 christos 8: .if !empty(.INCLUDEDFROMFILE:MMakefile*)
9: error1:
10: @(echo "bsd.sys.mk should not be included from Makefiles" >& 2; exit 1)
11: .endif
12: .if !defined(_BSD_OWN_MK_)
13: error2:
14: @(echo "bsd.own.mk must be included before bsd.sys.mk" >& 2; exit 1)
15: .endif
1.233 christos 16:
1.252 christos 17: # XXX: LLVM does not support -iremap and -fdebug-*
18: .if ${MKREPRO:Uno} == "yes" && ${MKLLVM:Uno} != "yes"
1.246 christos 19: .export NETBSDSRCDIR DESTDIR X11SRCDIR
1.250 christos 20:
1.247 christos 21: .if !empty(DESTDIR)
1.250 christos 22: CPPFLAGS+= -Wp,-iremap,${DESTDIR}:
1.247 christos 23: REPROFLAGS+= -fdebug-prefix-map=\$$DESTDIR=
24: .endif
1.250 christos 25:
1.262 christos 26: CPPFLAGS+= -Wp,-fno-canonical-system-headers
1.250 christos 27: CPPFLAGS+= -Wp,-iremap,${NETBSDSRCDIR}:/usr/src
28: CPPFLAGS+= -Wp,-iremap,${X11SRCDIR}:/usr/xsrc
1.248 dholland 29: REPROFLAGS+= -fdebug-prefix-map=\$$NETBSDSRCDIR=/usr/src
1.247 christos 30: REPROFLAGS+= -fdebug-prefix-map=\$$X11SRCDIR=/usr/xsrc
1.263 christos 31: LINTFLAGS+= -R${NETBSDSRCDIR}=/usr/src -R${X11SRCDIR}=/usr/xsrc
1.276 ! christos 32: LINTFLAGS+= -R${DESTDIR}=
1.250 christos 33:
1.261 christos 34: REPROFLAGS+= -fdebug-regex-map='/usr/src/(.*)/obj.*=/usr/obj/\1'
1.269 christos 35: REPROFLAGS+= -fdebug-regex-map='/usr/src/(.*)/obj.*/(.*)=/usr/obj/\1/\2'
1.250 christos 36:
1.247 christos 37: CFLAGS+= ${REPROFLAGS}
38: CXXFLAGS+= ${REPROFLAGS}
1.193 joerg 39: .endif
40:
1.238 plunky 41: # NetBSD sources use C99 style, with some GCC extensions.
1.273 christos 42: # Coverity does not like -std=gnu99
43: .if !defined(COVERITY_TOP_CONFIG)
1.238 plunky 44: CFLAGS+= ${${ACTIVE_CC} == "clang":? -std=gnu99 :}
45: CFLAGS+= ${${ACTIVE_CC} == "gcc":? -std=gnu99 :}
46: CFLAGS+= ${${ACTIVE_CC} == "pcc":? -std=gnu99 :}
1.273 christos 47: .endif
1.194 christos 48:
1.35 christos 49: .if defined(WARNS)
1.201 joerg 50: CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wno-sign-compare -Wno-pointer-sign :}
1.35 christos 51: .if ${WARNS} > 0
1.60 tv 52: CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
53: #CFLAGS+= -Wmissing-declarations -Wredundant-decls -Wnested-externs
1.82 thorpej 54: # Add -Wno-sign-compare. -Wsign-compare is included in -Wall as of GCC 3.3,
1.95 christos 55: # but our sources aren't up for it yet. Also, add -Wno-traditional because
56: # gcc includes #elif in the warnings, which is 'this code will not compile
57: # in a traditional environment' warning, as opposed to 'this code behaves
58: # differently in traditional and ansi environments' which is the warning
59: # we wanted, and now we don't get anymore.
1.195 joerg 60: CFLAGS+= -Wno-sign-compare
1.265 christos 61: # Don't suppress warnings coming from constructs in system headers.
62: # Our system headers should be clean and we want to warn about things like:
63: # isdigit((char)1)
1.268 joerg 64: CFLAGS+= ${${ACTIVE_CC} == "gcc" :? -Wsystem-headers :}
1.239 plunky 65: CFLAGS+= ${${ACTIVE_CC} == "gcc" :? -Wno-traditional :}
1.164 lukem 66: .if !defined(NOGCCERROR)
67: # Set assembler warnings to be fatal
1.264 maya 68: CFLAGS+= ${${ACTIVE_CC} == "gcc" :? -Wa,--fatal-warnings :}
1.164 lukem 69: .endif
1.259 christos 70:
71: .if ${MKRELRO:Uno} != "no"
72: LDFLAGS+= -Wl,-z,relro
73: .endif
74: .if ${MKRELRO:Uno} == "full"
75: LDFLAGS+= -Wl,-z,now
76: .endif
77:
1.159 lukem 78: # Set linker warnings to be fatal
1.162 tsutsui 79: # XXX no proper way to avoid "FOO is a patented algorithm" warnings
80: # XXX on linking static libs
81: .if (!defined(MKPIC) || ${MKPIC} != "no") && \
82: (!defined(LDSTATIC) || ${LDSTATIC} != "-static")
1.205 mrg 83: # XXX there are some strange problems not yet resolved
1.217 joerg 84: . if !defined(HAVE_GCC) || defined(HAVE_LLVM)
1.159 lukem 85: LDFLAGS+= -Wl,--fatal-warnings
1.205 mrg 86: . endif
1.119 lukem 87: .endif
1.162 tsutsui 88: .endif
1.258 christos 89:
90: LDFLAGS+= -Wl,--warn-shared-textrel
91:
1.35 christos 92: .if ${WARNS} > 1
1.79 msaitoh 93: CFLAGS+= -Wreturn-type -Wswitch -Wshadow
1.56 lukem 94: .endif
95: .if ${WARNS} > 2
1.60 tv 96: CFLAGS+= -Wcast-qual -Wwrite-strings
1.137 christos 97: CFLAGS+= -Wextra -Wno-unused-parameter
1.201 joerg 98: # Readd -Wno-sign-compare to override -Wextra with clang
99: CFLAGS+= -Wno-sign-compare
1.123 he 100: CXXFLAGS+= -Wabi
101: CXXFLAGS+= -Wold-style-cast
1.122 he 102: CXXFLAGS+= -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder \
1.200 joerg 103: -Wno-deprecated -Woverloaded-virtual -Wsign-promo -Wsynth
104: CXXFLAGS+= ${${ACTIVE_CXX} == "gcc":? -Wno-non-template-friend -Wno-pmf-conversions :}
1.35 christos 105: .endif
1.212 joerg 106: .if ${WARNS} > 3 && (defined(HAVE_GCC) || defined(HAVE_LLVM))
1.215 matt 107: .if ${WARNS} > 4
108: CFLAGS+= -Wold-style-definition
109: .endif
1.254 mrg 110: .if ${WARNS} > 5
1.224 christos 111: CFLAGS+= -Wconversion
112: .endif
1.208 christos 113: CFLAGS+= -Wsign-compare -Wformat=2
1.212 joerg 114: CFLAGS+= ${${ACTIVE_CC} == "gcc":? -Wno-format-zero-length :}
1.209 joerg 115: .endif
116: .if ${WARNS} > 3 && defined(HAVE_LLVM)
117: CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wpointer-sign -Wmissing-noreturn :}
1.115 matt 118: .endif
1.240 mrg 119: .if (defined(HAVE_GCC) \
1.226 matt 120: && (${MACHINE_ARCH} == "coldfire" || \
1.272 mrg 121: ${MACHINE_CPU} == "sh3" || \
122: ${MACHINE_CPU} == "m68k"))
1.210 chs 123: # XXX GCC 4.5 for sh3 and m68k (which we compile with -Os) is extra noisy for
1.207 uwe 124: # cases it should be better with
1.206 mrg 125: CFLAGS+= -Wno-uninitialized
1.230 christos 126: CFLAGS+= -Wno-maybe-uninitialized
127: .endif
1.206 mrg 128: .endif
1.41 sommerfe 129:
1.199 joerg 130: CWARNFLAGS+= ${CWARNFLAGS.${ACTIVE_CC}}
131:
1.61 tv 132: CPPFLAGS+= ${AUDIT:D-D__AUDIT__}
1.202 joerg 133: _NOWERROR= ${defined(NOGCCERROR) || (${ACTIVE_CC} == "clang" && defined(NOCLANGERROR)):?yes:no}
1.203 joerg 134: CFLAGS+= ${${_NOWERROR} == "no" :?-Werror:} ${CWARNFLAGS}
1.53 tv 135: LINTFLAGS+= ${DESTDIR:D-d ${DESTDIR}/usr/include}
1.47 simonb 136:
1.255 christos 137: .if !defined(NOSSP) && (${USE_SSP:Uno} != "no") && (${BINDIR:Ux} != "/usr/mdec")
1.274 christos 138: . if !defined(KERNSRCDIR) && !defined(KERN) # not for kernels / kern modules
1.151 tls 139: CPPFLAGS+= -D_FORTIFY_SOURCE=2
1.274 christos 140: . endif
1.273 christos 141: . if !defined(COVERITY_TOP_CONFIG)
1.196 joerg 142: COPTS+= -fstack-protector -Wstack-protector
1.237 martin 143:
1.256 mrg 144: # GCC 4.8 on m68k erroneously does not protect functions with
1.237 martin 145: # variables needing special alignement, see
146: # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59674
147: # (the underlying issue for sh and vax may be different, needs more
148: # investigation, symptoms are similar but for different sources)
1.275 mrg 149: # also true for GCC 5, assume GCC 6 too.
1.274 christos 150: . if "${ACTIVE_CC}" == "gcc" && \
1.275 mrg 151: ( ${HAVE_GCC} == "5" || \
152: ${HAVE_GCC} == "6" ) && \
1.256 mrg 153: ( ${MACHINE_CPU} == "sh3" || \
154: ${MACHINE_ARCH} == "vax" || \
155: ${MACHINE_CPU} == "m68k" || \
156: ${MACHINE_CPU} == "or1k" )
1.237 martin 157: COPTS+= -Wno-error=stack-protector
1.274 christos 158: . endif
1.237 martin 159:
1.219 joerg 160: COPTS+= ${${ACTIVE_CC} == "clang":? --param ssp-buffer-size=1 :}
1.196 joerg 161: COPTS+= ${${ACTIVE_CC} == "gcc":? --param ssp-buffer-size=1 :}
1.274 christos 162: . endif
1.143 tls 163: .endif
1.145 tls 164:
1.197 joerg 165: .if ${MKSOFTFLOAT:Uno} != "no"
1.270 chs 166: # sh3 defaults to soft-float and specifies hard-float a different way
167: .if ${MACHINE_CPU} != "sh3"
1.242 joerg 168: COPTS+= ${${ACTIVE_CC} == "gcc":? -msoft-float :}
1.47 simonb 169: FOPTS+= -msoft-float
1.270 chs 170: .endif
1.226 matt 171: .elif ${MACHINE_ARCH} == "coldfire"
172: COPTS+= -mhard-float
173: FOPTS+= -mhard-float
1.70 ross 174: .endif
175:
1.260 matt 176: #.if !empty(MACHINE_ARCH:Mearmv7*)
177: #COPTS+= -mthumb
178: #FOPTS+= -mthumb
179: #.endif
180:
1.197 joerg 181: .if ${MKIEEEFP:Uno} != "no"
1.70 ross 182: .if ${MACHINE_ARCH} == "alpha"
183: CFLAGS+= -mieee
184: FFLAGS+= -mieee
185: .endif
1.81 mrg 186: .endif
187:
188: .if ${MACHINE} == "sparc64" && ${MACHINE_ARCH} == "sparc"
189: CFLAGS+= -Wa,-Av8plus
1.3 scottr 190: .endif
1.87 thorpej 191:
1.189 mrg 192: .if !defined(NOGCCERROR)
1.188 matt 193: .if (${MACHINE_ARCH} == "mips64el") || (${MACHINE_ARCH} == "mips64eb")
1.220 joerg 194: CPUFLAGS+= -Wa,--fatal-warnings
1.188 matt 195: .endif
1.189 mrg 196: .endif
1.188 matt 197:
198: #.if ${MACHINE} == "sbmips"
199: #CFLAGS+= -mips64 -mtune=sb1
200: #.endif
201:
202: #.if (${MACHINE_ARCH} == "mips64el" || ${MACHINE_ARCH} == "mips64eb") && \
203: # (defined(MKPIC) && ${MKPIC} == "no")
204: #CPUFLAGS+= -mno-abicalls -fno-PIC
205: #.endif
1.87 thorpej 206: CFLAGS+= ${CPUFLAGS}
1.114 simonb 207: AFLAGS+= ${CPUFLAGS}
1.4 thorpej 208:
1.251 christos 209: .if !defined(NOPIE) && (!defined(LDSTATIC) || ${LDSTATIC} != "-static")
1.174 christos 210: # Position Independent Executable flags
1.257 martin 211: PIE_CFLAGS?= -fPIE
212: PIE_LDFLAGS?= -pie ${${ACTIVE_CC} == "gcc":? -shared-libgcc :}
213: PIE_AFLAGS?= -fPIE
1.192 pooka 214: .endif
1.174 christos 215:
1.77 simonb 216: ELF2ECOFF?= elf2ecoff
1.74 lukem 217: MKDEP?= mkdep
1.229 mrg 218: MKDEPCXX?= mkdep
1.74 lukem 219: OBJCOPY?= objcopy
1.117 riz 220: OBJDUMP?= objdump
1.139 christos 221: PAXCTL?= paxctl
1.74 lukem 222: STRIP?= strip
1.109 matt 223:
1.124 jwise 224: .SUFFIXES: .o .ln .lo .c .cc .cpp .cxx .C .m ${YHEADER:D.h}
1.93 lukem 225:
226: # C
227: .c.o:
1.104 lukem 228: ${_MKTARGET_COMPILE}
1.93 lukem 229: ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
1.190 darran 230: .if defined(CTFCONVERT)
231: ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
232: .endif
1.112 lukem 233:
1.93 lukem 234: .c.ln:
1.104 lukem 235: ${_MKTARGET_COMPILE}
1.214 christos 236: ${LINT} ${LINTFLAGS} ${LINTFLAGS.${.IMPSRC:T}} \
1.111 lukem 237: ${CPPFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \
238: ${CPPFLAGS.${.IMPSRC:T}:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \
239: -i ${.IMPSRC}
1.29 tv 240:
1.103 lukem 241: # C++
242: .cc.o .cpp.o .cxx.o .C.o:
1.104 lukem 243: ${_MKTARGET_COMPILE}
1.103 lukem 244: ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
245:
1.13 lukem 246: # Objective C
247: # (Defined here rather than in <sys.mk> because `.m' is not just
248: # used for Objective C source)
249: .m.o:
1.104 lukem 250: ${_MKTARGET_COMPILE}
1.129 mrg 251: ${COMPILE.m} ${OBJCOPTS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC}
1.190 darran 252: .if defined(CTFCONVERT)
253: ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
254: .endif
1.29 tv 255:
256: # Host-compiled C objects
1.76 bjh21 257: # The intermediate step is necessary for Sun CC, which objects to calling
258: # object files anything but *.o
1.29 tv 259: .c.lo:
1.104 lukem 260: ${_MKTARGET_COMPILE}
1.110 lukem 261: ${HOST_COMPILE.c} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
1.76 bjh21 262: mv ${.TARGET}.o ${.TARGET}
1.98 lukem 263:
1.124 jwise 264: # C++
265: .cc.lo .cpp.lo .cxx.lo .C.lo:
266: ${_MKTARGET_COMPILE}
267: ${HOST_COMPILE.cc} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
268: mv ${.TARGET}.o ${.TARGET}
269:
1.98 lukem 270: # Assembly
271: .s.o:
1.104 lukem 272: ${_MKTARGET_COMPILE}
1.98 lukem 273: ${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
1.190 darran 274: .if defined(CTFCONVERT)
275: ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
276: .endif
1.107 lukem 277:
1.98 lukem 278: .S.o:
1.104 lukem 279: ${_MKTARGET_COMPILE}
1.98 lukem 280: ${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
1.190 darran 281: .if defined(CTFCONVERT)
282: ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
283: .endif
1.13 lukem 284:
1.52 tv 285: # Lex
1.167 christos 286: LFLAGS+= ${LPREFIX.${.IMPSRC:T}:D-P${LPREFIX.${.IMPSRC:T}}}
287: LFLAGS+= ${LPREFIX:D-P${LPREFIX}}
1.1 christos 288:
289: .l.c:
1.104 lukem 290: ${_MKTARGET_LEX}
1.1 christos 291: ${LEX.l} -o${.TARGET} ${.IMPSRC}
292:
293: # Yacc
1.167 christos 294: YFLAGS+= ${YPREFIX.${.IMPSRC:T}:D-p${YPREFIX.${.IMPSRC:T}}} ${YHEADER.${.IMPSRC:T}:D-d}
1.52 tv 295: YFLAGS+= ${YPREFIX:D-p${YPREFIX}} ${YHEADER:D-d}
296:
1.33 lukem 297: .y.c:
1.104 lukem 298: ${_MKTARGET_YACC}
1.33 lukem 299: ${YACC.y} -o ${.TARGET} ${.IMPSRC}
1.55 tv 300:
301: .ifdef YHEADER
1.187 christos 302: .if empty(.MAKEFLAGS:M-n)
1.55 tv 303: .y.h: ${.TARGET:.h=.c}
304: .endif
1.187 christos 305: .endif
1.64 thorpej 306:
1.211 christos 307: # Objcopy
1.241 matt 308: .if ${MACHINE_ARCH} == aarch64eb
309: # AARCH64 big endian needs to preserve $x/$d symbols for the linker.
1.244 joerg 310: OBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][dx]' -K '[$$][dx]\.*'
1.260 matt 311: .elif ${MACHINE_CPU} == "arm"
1.231 matt 312: # ARM big endian needs to preserve $a/$d/$t symbols for the linker.
1.244 joerg 313: OBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][adt]' -K '[$$][adt]\.*'
1.241 matt 314: .endif
1.271 ozaki-r 315:
316: .if ${MKSTRIPSYM:Uyes} == "yes"
1.241 matt 317: OBJCOPYLIBFLAGS?=${"${.TARGET:M*.po}" != "":?-X:-x} ${OBJCOPYLIBFLAGS_EXTRA}
1.271 ozaki-r 318: .else
319: OBJCOPYLIBFLAGS?=-X ${OBJCOPYLIBFLAGS_EXTRA}
320: .endif
1.211 christos 321:
1.94 lukem 322: .endif # !defined(_BSD_SYS_MK_)
CVSweb <webmaster@jp.NetBSD.org>