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