3 # This file contains common settings used for building FreeBSD
6 # Enable various levels of compiler warning checks. These may be
7 # overridden (e.g. if using a non-gcc compiler) by defining NO_WARNS.
9 # for GCC: http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html
11 .include <bsd.compiler.mk>
13 # the default is gnu99 for now
18 .elif ${CSTD} == "c89" || ${CSTD} == "c90"
19 CFLAGS+= -std=iso9899:1990
20 .elif ${CSTD} == "c94" || ${CSTD} == "c95"
21 CFLAGS+= -std=iso9899:199409
22 .elif ${CSTD} == "c99"
23 CFLAGS+= -std=iso9899:1999
27 .if !defined(NO_WARNS)
28 # -pedantic is problematic because it also imposes namespace restrictions
32 CWARNFLAGS+= -Wsystem-headers
33 .if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
34 || !defined(NO_WERROR.clang))
36 .endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
39 CWARNFLAGS+= -Wall -Wno-format-y2k
42 CWARNFLAGS+= -W -Wno-unused-parameter -Wstrict-prototypes\
43 -Wmissing-prototypes -Wpointer-arith
46 CWARNFLAGS+= -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
48 .if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \
49 || !defined(NO_WCAST_ALIGN.clang))
50 CWARNFLAGS+= -Wcast-align
51 .endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang)
55 CWARNFLAGS+= -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\
56 -Wold-style-definition
58 .if ${WARNS} >= 2 && ${WARNS} <= 4
59 # XXX Delete -Wuninitialized by default for now -- the compiler doesn't
60 # XXX always get it right.
61 CWARNFLAGS+= -Wno-uninitialized
62 .endif # WARNS >=2 && WARNS <= 4
63 CWARNFLAGS+= -Wno-pointer-sign
64 # Clang has more warnings enabled by default, and when using -Wall, so if WARNS
65 # is set to low values, these have to be disabled explicitly.
66 .if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
68 CWARNFLAGS+= -Wno-empty-body -Wno-string-plus-int
69 .if ${COMPILER_VERSION} > 30300
70 CWARNFLAGS+= -Wno-unused-const-variable
74 CWARNFLAGS+= -Wno-tautological-compare -Wno-unused-value\
75 -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion
78 CWARNFLAGS+= -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter
81 CWARNFLAGS+= -Wno-parentheses
83 .if defined(NO_WARRAY_BOUNDS)
84 CWARNFLAGS+= -Wno-array-bounds
85 .endif # NO_WARRAY_BOUNDS
89 .if defined(FORMAT_AUDIT)
94 #CWARNFLAGS+= -Wformat-nonliteral -Wformat-security -Wno-format-extra-args
95 CWARNFLAGS+= -Wformat=2 -Wno-format-extra-args
96 .if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
98 CWARNFLAGS+= -Wno-format-nonliteral
101 .if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
102 || !defined(NO_WERROR.clang))
104 .endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
107 .if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang))
108 CWARNFLAGS+= -Wno-format
109 .endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang)
112 .if defined(IGNORE_PRAGMA)
113 CWARNFLAGS+= -Wno-unknown-pragmas
114 .endif # IGNORE_PRAGMA
116 .if !defined(EARLY_BUILD)
117 .if ${COMPILER_TYPE} == "clang"
118 CLANG_NO_IAS= -no-integrated-as
119 CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\
120 -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret
121 CFLAGS+= -Qunused-arguments
122 .if ${MACHINE_CPUARCH} == "sparc64"
123 # Don't emit .cfi directives, since we must use GNU as on sparc64, for now.
124 CFLAGS+= -fno-dwarf2-cfi-asm
126 # The libc++ headers use c++11 extensions. These are normally silenced because
127 # they are treated as system headers, but we explicitly disable that warning
128 # suppression when building the base system to catch bugs in our headers.
129 # Eventually we'll want to start building the base system C++ code as C++11,
131 CXXFLAGS+= -Wno-c++11-extensions
132 CFLAGS+= ${CFLAGS.clang}
133 CXXFLAGS+= ${CXXFLAGS.clang}
135 GCC_MS_EXTENSIONS= -fms-extensions
136 CFLAGS+= ${CFLAGS.gcc}
137 CXXFLAGS+= ${CXXFLAGS.gcc}
139 .endif # !EARLY_BUILD
141 .if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
142 ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
143 # Don't use -Wstack-protector as it breaks world with -Werror.
144 SSP_CFLAGS?= -fstack-protector
145 CFLAGS+= ${SSP_CFLAGS}
146 .endif # SSP && !IA64 && !ARM && !MIPS
148 # Allow user-specified additional warning flags
149 CFLAGS+= ${CWARNFLAGS}
152 # Tell bmake not to mistake standard targets for things to be searched for
153 # or expect to ever be up-to-date.
154 PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
155 beforelinking build build-tools buildfiles buildincludes \
156 checkdpadd clean cleandepend cleandir cleanobj configure \
157 depend dependall distclean distribute exe extract fetch \
158 html includes install installfiles installincludes lint \
159 obj objlink objs objwarn patch realall realdepend \
160 realinstall regress subdir-all subdir-depend subdir-install \
163 .PHONY: ${PHONY_NOTMAIN}
164 .NOTMAIN: ${PHONY_NOTMAIN}