bsd.sys.mk revision 262459
1162852Sdes# $FreeBSD: stable/9/share/mk/bsd.sys.mk 262459 2014-02-24 21:22:44Z dim $ 2113908Sdes# 357429Smarkm# This file contains common settings used for building FreeBSD 4113908Sdes# sources. 565668Skris 6113908Sdes# Enable various levels of compiler warning checks. These may be 7113908Sdes# overridden (e.g. if using a non-gcc compiler) by defining NO_WARNS. 8113908Sdes 9113908Sdes# for GCC: http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html 10113908Sdes 11113908Sdes.include <bsd.compiler.mk> 12113908Sdes 13113908Sdes# the default is gnu99 for now 1465668SkrisCSTD?= gnu99 15113908Sdes 16113908Sdes.if ${CSTD} == "k&r" 17113908SdesCFLAGS+= -traditional 18113908Sdes.elif ${CSTD} == "c89" || ${CSTD} == "c90" 19113908SdesCFLAGS+= -std=iso9899:1990 20113908Sdes.elif ${CSTD} == "c94" || ${CSTD} == "c95" 21113908SdesCFLAGS+= -std=iso9899:199409 22113908Sdes.elif ${CSTD} == "c99" 23113908SdesCFLAGS+= -std=iso9899:1999 24113908Sdes.else # CSTD 2557429SmarkmCFLAGS+= -std=${CSTD} 2657429Smarkm.endif # CSTD 2757429Smarkm.if !defined(NO_WARNS) 2857429Smarkm# -pedantic is problematic because it also imposes namespace restrictions 29113908Sdes#CFLAGS+= -pedantic 30113908Sdes.if defined(WARNS) 31113908Sdes.if ${WARNS} >= 1 32113908SdesCWARNFLAGS+= -Wsystem-headers 33113908Sdes.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \ 34113908Sdes || !defined(NO_WERROR.clang)) 35113908SdesCWARNFLAGS+= -Werror 36113908Sdes.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) 37113908Sdes.endif # WARNS >= 1 38113908Sdes.if ${WARNS} >= 2 39113908SdesCWARNFLAGS+= -Wall -Wno-format-y2k 40113908Sdes.endif # WARNS >= 2 41113908Sdes.if ${WARNS} >= 3 42113908SdesCWARNFLAGS+= -W -Wno-unused-parameter -Wstrict-prototypes\ 43113908Sdes -Wmissing-prototypes -Wpointer-arith 44113908Sdes.endif # WARNS >= 3 45113908Sdes.if ${WARNS} >= 4 46113908SdesCWARNFLAGS+= -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\ 47113908Sdes -Wunused-parameter 48113908Sdes.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \ 49113908Sdes || !defined(NO_WCAST_ALIGN.clang)) 50113908SdesCWARNFLAGS+= -Wcast-align 51113908Sdes.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang) 52113908Sdes.endif # WARNS >= 4 53113908Sdes# BDECFLAGS 54113908Sdes.if ${WARNS} >= 6 55113908SdesCWARNFLAGS+= -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\ 56113908Sdes -Wold-style-definition 57113908Sdes.endif # WARNS >= 6 58113908Sdes.if ${WARNS} >= 2 && ${WARNS} <= 4 59113908Sdes# XXX Delete -Wuninitialized by default for now -- the compiler doesn't 60113908Sdes# XXX always get it right. 61113908SdesCWARNFLAGS+= -Wno-uninitialized 62113908Sdes.endif # WARNS >=2 && WARNS <= 4 63113908SdesCWARNFLAGS+= -Wno-pointer-sign 64113908Sdes# Clang has more warnings enabled by default, and when using -Wall, so if WARNS 65113908Sdes# is set to low values, these have to be disabled explicitly. 66113908Sdes.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) 67113908Sdes.if ${WARNS} <= 6 68113908SdesCWARNFLAGS+= -Wno-empty-body -Wno-string-plus-int 69113908Sdes.endif # WARNS <= 6 70113908Sdes.if ${WARNS} <= 3 71113908SdesCWARNFLAGS+= -Wno-tautological-compare -Wno-unused-value\ 72113908Sdes -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion 73113908Sdes.endif # WARNS <= 3 74113908Sdes.if ${WARNS} <= 2 75113908SdesCWARNFLAGS+= -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter 76113908Sdes.endif # WARNS <= 2 77113908Sdes.if ${WARNS} <= 1 78113908SdesCWARNFLAGS+= -Wno-parentheses 79113908Sdes.endif # WARNS <= 1 80113908Sdes.if defined(NO_WARRAY_BOUNDS) 81113908SdesCWARNFLAGS+= -Wno-array-bounds 82113908Sdes.endif # NO_WARRAY_BOUNDS 83113908Sdes.endif # CLANG 84113908Sdes.endif # WARNS 85113908Sdes 86113908Sdes.if defined(FORMAT_AUDIT) 87113908SdesWFORMAT= 1 88113908Sdes.endif # FORMAT_AUDIT 89113908Sdes.if defined(WFORMAT) 90113908Sdes.if ${WFORMAT} > 0 91113908Sdes#CWARNFLAGS+= -Wformat-nonliteral -Wformat-security -Wno-format-extra-args 92113908SdesCWARNFLAGS+= -Wformat=2 -Wno-format-extra-args 93113908Sdes.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) 9457429Smarkm.if ${WARNS} <= 3 9557429SmarkmCWARNFLAGS+= -Wno-format-nonliteral 96113908Sdes.endif # WARNS <= 3 97113908Sdes.endif # CLANG 9857429Smarkm.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \ 99113908Sdes || !defined(NO_WERROR.clang)) 10057429SmarkmCWARNFLAGS+= -Werror 101113908Sdes.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) 102162852Sdes.endif # WFORMAT > 0 103113908Sdes.endif # WFORMAT 104113908Sdes.if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang)) 10557429SmarkmCWARNFLAGS+= -Wno-format 106.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang) 107.endif # !NO_WARNS 108 109.if defined(IGNORE_PRAGMA) 110CWARNFLAGS+= -Wno-unknown-pragmas 111.endif # IGNORE_PRAGMA 112 113.if !defined(EARLY_BUILD) 114.if ${COMPILER_TYPE} == "clang" 115CLANG_NO_IAS= -no-integrated-as 116CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\ 117 -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret 118CFLAGS+= -Qunused-arguments 119# The libc++ headers use c++11 extensions. These are normally silenced because 120# they are treated as system headers, but we explicitly disable that warning 121# suppression when building the base system to catch bugs in our headers. 122# Eventually we'll want to start building the base system C++ code as C++11, 123# but not yet. 124CXXFLAGS+= -Wno-c++11-extensions 125CFLAGS+= ${CFLAGS.clang} 126CXXFLAGS+= ${CXXFLAGS.clang} 127.else # !CLANG 128GCC_MS_EXTENSIONS= -fms-extensions 129CFLAGS+= ${CFLAGS.gcc} 130CXXFLAGS+= ${CXXFLAGS.gcc} 131.endif # CLANG 132.endif # !EARLY_BUILD 133 134.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ 135 ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 136# Don't use -Wstack-protector as it breaks world with -Werror. 137SSP_CFLAGS?= -fstack-protector 138CFLAGS+= ${SSP_CFLAGS} 139.endif # SSP && !IA64 && !ARM && !MIPS 140 141# Allow user-specified additional warning flags 142CFLAGS+= ${CWARNFLAGS} 143 144 145# Tell bmake not to mistake standard targets for things to be searched for 146# or expect to ever be up-to-date. 147PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \ 148 beforelinking build build-tools buildfiles buildincludes \ 149 checkdpadd clean cleandepend cleandir cleanobj configure \ 150 depend dependall distclean distribute exe extract fetch \ 151 html includes install installfiles installincludes lint \ 152 obj objlink objs objwarn patch realall realdepend \ 153 realinstall regress subdir-all subdir-depend subdir-install \ 154 tags whereobj 155 156.PHONY: ${PHONY_NOTMAIN} 157.NOTMAIN: ${PHONY_NOTMAIN} 158