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