1# $NetBSD: bsd.sys.mk,v 1.250 2016/01/10 16:22:57 christos Exp $ 2# 3# Build definitions used for NetBSD source tree builds. 4 5.if !defined(_BSD_SYS_MK_) 6_BSD_SYS_MK_=1 7 8.if !empty(.INCLUDEDFROMFILE:MMakefile*) 9error1: 10 @(echo "bsd.sys.mk should not be included from Makefiles" >& 2; exit 1) 11.endif 12.if !defined(_BSD_OWN_MK_) 13error2: 14 @(echo "bsd.own.mk must be included before bsd.sys.mk" >& 2; exit 1) 15.endif 16 17.if ${MKREPRO:Uno} == "yes" 18.export NETBSDSRCDIR DESTDIR X11SRCDIR 19 20.if !empty(DESTDIR) 21CPPFLAGS+= -Wp,-iremap,${DESTDIR}: 22REPROFLAGS+= -fdebug-prefix-map=\$$DESTDIR= 23.endif 24 25CPPFLAGS+= -Wp,-iremap,${NETBSDSRCDIR}:/usr/src 26CPPFLAGS+= -Wp,-iremap,${X11SRCDIR}:/usr/xsrc 27REPROFLAGS+= -fdebug-prefix-map=\$$NETBSDSRCDIR=/usr/src 28REPROFLAGS+= -fdebug-prefix-map=\$$X11SRCDIR=/usr/xsrc 29 30REPROFLAGS+= -fdebug-regex-map='/usr/src/(.*)/obj.${MACHINE}=/usr/obj/\1' 31 32CFLAGS+= ${REPROFLAGS} 33CXXFLAGS+= ${REPROFLAGS} 34.endif 35 36# NetBSD sources use C99 style, with some GCC extensions. 37CFLAGS+= ${${ACTIVE_CC} == "clang":? -std=gnu99 :} 38CFLAGS+= ${${ACTIVE_CC} == "gcc":? -std=gnu99 :} 39CFLAGS+= ${${ACTIVE_CC} == "pcc":? -std=gnu99 :} 40 41.if defined(WARNS) 42CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wno-sign-compare -Wno-pointer-sign :} 43.if ${WARNS} > 0 44CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith 45#CFLAGS+= -Wmissing-declarations -Wredundant-decls -Wnested-externs 46# Add -Wno-sign-compare. -Wsign-compare is included in -Wall as of GCC 3.3, 47# but our sources aren't up for it yet. Also, add -Wno-traditional because 48# gcc includes #elif in the warnings, which is 'this code will not compile 49# in a traditional environment' warning, as opposed to 'this code behaves 50# differently in traditional and ansi environments' which is the warning 51# we wanted, and now we don't get anymore. 52CFLAGS+= -Wno-sign-compare 53CFLAGS+= ${${ACTIVE_CC} == "gcc" :? -Wno-traditional :} 54.if !defined(NOGCCERROR) 55# Set assembler warnings to be fatal 56CFLAGS+= -Wa,--fatal-warnings 57.endif 58# Set linker warnings to be fatal 59# XXX no proper way to avoid "FOO is a patented algorithm" warnings 60# XXX on linking static libs 61.if (!defined(MKPIC) || ${MKPIC} != "no") && \ 62 (!defined(LDSTATIC) || ${LDSTATIC} != "-static") 63# XXX there are some strange problems not yet resolved 64. if !defined(HAVE_GCC) || defined(HAVE_LLVM) 65LDFLAGS+= -Wl,--fatal-warnings 66. endif 67.endif 68.endif 69.if ${WARNS} > 1 70CFLAGS+= -Wreturn-type -Wswitch -Wshadow 71.endif 72.if ${WARNS} > 2 73CFLAGS+= -Wcast-qual -Wwrite-strings 74CFLAGS+= -Wextra -Wno-unused-parameter 75# Readd -Wno-sign-compare to override -Wextra with clang 76CFLAGS+= -Wno-sign-compare 77CXXFLAGS+= -Wabi 78CXXFLAGS+= -Wold-style-cast 79CXXFLAGS+= -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder \ 80 -Wno-deprecated -Woverloaded-virtual -Wsign-promo -Wsynth 81CXXFLAGS+= ${${ACTIVE_CXX} == "gcc":? -Wno-non-template-friend -Wno-pmf-conversions :} 82.endif 83.if ${WARNS} > 3 && (defined(HAVE_GCC) || defined(HAVE_LLVM)) 84.if ${WARNS} > 4 85CFLAGS+= -Wold-style-definition 86.endif 87.if ${WARNS} > 5 && !(defined(HAVE_GCC) && ${HAVE_GCC} <= 45) 88CFLAGS+= -Wconversion 89.endif 90CFLAGS+= -Wsign-compare -Wformat=2 91CFLAGS+= ${${ACTIVE_CC} == "gcc":? -Wno-format-zero-length :} 92.endif 93.if ${WARNS} > 3 && defined(HAVE_LLVM) 94CFLAGS+= ${${ACTIVE_CC} == "clang":? -Wpointer-sign -Wmissing-noreturn :} 95.endif 96.if (defined(HAVE_GCC) \ 97 && (${MACHINE_ARCH} == "coldfire" || \ 98 ${MACHINE_ARCH} == "sh3eb" || \ 99 ${MACHINE_ARCH} == "sh3el" || \ 100 ${MACHINE_ARCH} == "m68k" || \ 101 ${MACHINE_ARCH} == "m68000")) 102# XXX GCC 4.5 for sh3 and m68k (which we compile with -Os) is extra noisy for 103# cases it should be better with 104CFLAGS+= -Wno-uninitialized 105.if ${HAVE_GCC} >= 48 106CFLAGS+= -Wno-maybe-uninitialized 107.endif 108.endif 109.endif 110 111CWARNFLAGS+= ${CWARNFLAGS.${ACTIVE_CC}} 112 113CPPFLAGS+= ${AUDIT:D-D__AUDIT__} 114_NOWERROR= ${defined(NOGCCERROR) || (${ACTIVE_CC} == "clang" && defined(NOCLANGERROR)):?yes:no} 115CFLAGS+= ${${_NOWERROR} == "no" :?-Werror:} ${CWARNFLAGS} 116LINTFLAGS+= ${DESTDIR:D-d ${DESTDIR}/usr/include} 117 118.if (${USE_SSP:Uno} != "no") && (${BINDIR:Ux} != "/usr/mdec") 119.if !defined(KERNSRCDIR) && !defined(KERN) # not for kernels nor kern modules 120CPPFLAGS+= -D_FORTIFY_SOURCE=2 121.endif 122COPTS+= -fstack-protector -Wstack-protector 123 124# gcc 4.8 on m68k erroneously does not protect functions with 125# variables needing special alignement, see 126# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59674 127# (the underlying issue for sh and vax may be different, needs more 128# investigation, symptoms are similar but for different sources) 129.if "${ACTIVE_CC}" == "gcc" && "${HAVE_GCC}" == "48" && \ 130 ( ${MACHINE_CPU} == "sh3" || \ 131 ${MACHINE_ARCH} == "vax" || \ 132 ${MACHINE_CPU} == "m68k" || \ 133 ${MACHINE_CPU} == "or1k" ) 134COPTS+= -Wno-error=stack-protector 135.endif 136 137COPTS+= ${${ACTIVE_CC} == "clang":? --param ssp-buffer-size=1 :} 138COPTS+= ${${ACTIVE_CC} == "gcc":? --param ssp-buffer-size=1 :} 139.endif 140 141.if ${MKSOFTFLOAT:Uno} != "no" 142COPTS+= ${${ACTIVE_CC} == "gcc":? -msoft-float :} 143FOPTS+= -msoft-float 144.elif ${MACHINE_ARCH} == "coldfire" 145COPTS+= -mhard-float 146FOPTS+= -mhard-float 147.endif 148 149.if ${MKIEEEFP:Uno} != "no" 150.if ${MACHINE_ARCH} == "alpha" 151CFLAGS+= -mieee 152FFLAGS+= -mieee 153.endif 154.endif 155 156.if ${MACHINE} == "sparc64" && ${MACHINE_ARCH} == "sparc" 157CFLAGS+= -Wa,-Av8plus 158.endif 159 160.if !defined(NOGCCERROR) 161.if (${MACHINE_ARCH} == "mips64el") || (${MACHINE_ARCH} == "mips64eb") 162CPUFLAGS+= -Wa,--fatal-warnings 163.endif 164.endif 165 166#.if ${MACHINE} == "sbmips" 167#CFLAGS+= -mips64 -mtune=sb1 168#.endif 169 170#.if (${MACHINE_ARCH} == "mips64el" || ${MACHINE_ARCH} == "mips64eb") && \ 171# (defined(MKPIC) && ${MKPIC} == "no") 172#CPUFLAGS+= -mno-abicalls -fno-PIC 173#.endif 174CFLAGS+= ${CPUFLAGS} 175AFLAGS+= ${CPUFLAGS} 176 177.if !defined(LDSTATIC) || ${LDSTATIC} != "-static" 178# Position Independent Executable flags 179PIE_CFLAGS?= -fPIC 180PIE_LDFLAGS?= -Wl,-pie ${${ACTIVE_CC} == "gcc":? -shared-libgcc :} 181PIE_AFLAGS?= -fPIC 182.endif 183 184ELF2ECOFF?= elf2ecoff 185MKDEP?= mkdep 186MKDEPCXX?= mkdep 187OBJCOPY?= objcopy 188OBJDUMP?= objdump 189PAXCTL?= paxctl 190STRIP?= strip 191 192.SUFFIXES: .o .ln .lo .c .cc .cpp .cxx .C .m ${YHEADER:D.h} 193 194# C 195.c.o: 196 ${_MKTARGET_COMPILE} 197 ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} 198.if defined(CTFCONVERT) 199 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 200.endif 201 202.c.ln: 203 ${_MKTARGET_COMPILE} 204 ${LINT} ${LINTFLAGS} ${LINTFLAGS.${.IMPSRC:T}} \ 205 ${CPPFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \ 206 ${CPPFLAGS.${.IMPSRC:T}:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} \ 207 -i ${.IMPSRC} 208 209# C++ 210.cc.o .cpp.o .cxx.o .C.o: 211 ${_MKTARGET_COMPILE} 212 ${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} 213 214# Objective C 215# (Defined here rather than in <sys.mk> because `.m' is not just 216# used for Objective C source) 217.m.o: 218 ${_MKTARGET_COMPILE} 219 ${COMPILE.m} ${OBJCOPTS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} 220.if defined(CTFCONVERT) 221 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 222.endif 223 224# Host-compiled C objects 225# The intermediate step is necessary for Sun CC, which objects to calling 226# object files anything but *.o 227.c.lo: 228 ${_MKTARGET_COMPILE} 229 ${HOST_COMPILE.c} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} 230 mv ${.TARGET}.o ${.TARGET} 231 232# C++ 233.cc.lo .cpp.lo .cxx.lo .C.lo: 234 ${_MKTARGET_COMPILE} 235 ${HOST_COMPILE.cc} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} 236 mv ${.TARGET}.o ${.TARGET} 237 238# Assembly 239.s.o: 240 ${_MKTARGET_COMPILE} 241 ${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} 242.if defined(CTFCONVERT) 243 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 244.endif 245 246.S.o: 247 ${_MKTARGET_COMPILE} 248 ${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} 249.if defined(CTFCONVERT) 250 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET} 251.endif 252 253# Lex 254LFLAGS+= ${LPREFIX.${.IMPSRC:T}:D-P${LPREFIX.${.IMPSRC:T}}} 255LFLAGS+= ${LPREFIX:D-P${LPREFIX}} 256 257.l.c: 258 ${_MKTARGET_LEX} 259 ${LEX.l} -o${.TARGET} ${.IMPSRC} 260 261# Yacc 262YFLAGS+= ${YPREFIX.${.IMPSRC:T}:D-p${YPREFIX.${.IMPSRC:T}}} ${YHEADER.${.IMPSRC:T}:D-d} 263YFLAGS+= ${YPREFIX:D-p${YPREFIX}} ${YHEADER:D-d} 264 265.y.c: 266 ${_MKTARGET_YACC} 267 ${YACC.y} -o ${.TARGET} ${.IMPSRC} 268 269.ifdef YHEADER 270.if empty(.MAKEFLAGS:M-n) 271.y.h: ${.TARGET:.h=.c} 272.endif 273.endif 274 275# Objcopy 276.if ${MACHINE_ARCH} == aarch64eb 277# AARCH64 big endian needs to preserve $x/$d symbols for the linker. 278OBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][dx]' -K '[$$][dx]\.*' 279.elif !empty(MACHINE_ARCH:M*arm*eb) 280# ARM big endian needs to preserve $a/$d/$t symbols for the linker. 281OBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][adt]' -K '[$$][adt]\.*' 282.endif 283OBJCOPYLIBFLAGS?=${"${.TARGET:M*.po}" != "":?-X:-x} ${OBJCOPYLIBFLAGS_EXTRA} 284 285.endif # !defined(_BSD_SYS_MK_) 286