2 # Copyright © 2004 Scott James Remnant <scott@netsplit.com>
3 # Copyright © 2006, 2009-2011, 2013-2016 Guillem Jover <guillem@debian.org>
5 # DPKG_CHECK_COMPILER_FLAG
6 # ------------------------
7 AC_DEFUN([DPKG_CHECK_COMPILER_FLAG], [
8 m4_define([dpkg_check_flag], m4_bpatsubst([$1], [^-Wno-], [-W]))
12 m4_define([dpkg_compiler], [$CC])
13 m4_define([dpkg_varname], [CFLAGS])
14 m4_define([dpkg_varname_save], [dpkg_save_CFLAGS])
15 m4_define([dpkg_varname_export], [COMPILER_CFLAGS])
16 AS_VAR_PUSHDEF([dpkg_varname_cache], [dpkg_cv_cflags_$1])
19 m4_define([dpkg_compiler], [$CXX])
20 m4_define([dpkg_varname], [CXXFLAGS])
21 m4_define([dpkg_varname_save], [dpkg_save_CXXFLAGS])
22 m4_define([dpkg_varname_export], [COMPILER_CXXFLAGS])
23 AS_VAR_PUSHDEF([dpkg_varname_cache], [dpkg_cv_cxxflags_$1])
25 AC_CACHE_CHECK([whether ]dpkg_compiler[ accepts $1], [dpkg_varname_cache], [
26 AS_VAR_COPY([dpkg_varname_save], [dpkg_varname])
27 AS_VAR_SET([dpkg_varname], ["-Werror dpkg_check_flag"])
31 AS_VAR_SET([dpkg_varname_cache], [yes])
33 AS_VAR_SET([dpkg_varname_cache], [no])
35 AS_VAR_COPY([dpkg_varname], [dpkg_varname_save])
37 AS_VAR_IF([dpkg_varname_cache], [yes], [
38 AS_VAR_APPEND([dpkg_varname_export], [" $1"])
40 AS_VAR_POPDEF([dpkg_varname_cache])
43 # DPKG_CHECK_COMPILER_WARNINGS
44 # ----------------------------
45 # Add configure option to disable additional compiler warnings.
46 AC_DEFUN([DPKG_CHECK_COMPILER_WARNINGS], [
47 DPKG_CHECK_COMPILER_FLAG([-Wall])
48 DPKG_CHECK_COMPILER_FLAG([-Wextra])
50 DPKG_CHECK_COMPILER_FLAG([-Walloc-zero])
51 DPKG_CHECK_COMPILER_FLAG([-Warray-bounds-pointer-arithmetic])
52 DPKG_CHECK_COMPILER_FLAG([-Wassign-enum])
53 DPKG_CHECK_COMPILER_FLAG([-Wbitfield-enum-conversion])
54 DPKG_CHECK_COMPILER_FLAG([-Wcast-align])
55 DPKG_CHECK_COMPILER_FLAG([-Wconditional-uninitialized])
56 DPKG_CHECK_COMPILER_FLAG([-Wdate-time])
57 DPKG_CHECK_COMPILER_FLAG([-Wdocumentation])
58 DPKG_CHECK_COMPILER_FLAG([-Wduplicate-enum])
59 DPKG_CHECK_COMPILER_FLAG([-Wduplicated-branches])
60 DPKG_CHECK_COMPILER_FLAG([-Wduplicated-cond])
61 DPKG_CHECK_COMPILER_FLAG([-Wextra-semi])
62 DPKG_CHECK_COMPILER_FLAG([-Wflexible-array-extensions])
63 DPKG_CHECK_COMPILER_FLAG([-Wfloat-conversion])
64 DPKG_CHECK_COMPILER_FLAG([-Wfloat-equal])
65 DPKG_CHECK_COMPILER_FLAG([-Wformat -Wformat-security])
66 DPKG_CHECK_COMPILER_FLAG([-Wformat=2])
67 DPKG_CHECK_COMPILER_FLAG([-Winit-self])
68 DPKG_CHECK_COMPILER_FLAG([-Wlogical-not-parentheses])
69 DPKG_CHECK_COMPILER_FLAG([-Wlogical-op])
70 DPKG_CHECK_COMPILER_FLAG([-Wmissing-declarations])
71 DPKG_CHECK_COMPILER_FLAG([-Wmissing-format-attribute])
72 DPKG_CHECK_COMPILER_FLAG([-Wmissing-variable-declarations])
73 DPKG_CHECK_COMPILER_FLAG([-Wnewline-eof])
74 DPKG_CHECK_COMPILER_FLAG([-Wno-missing-field-initializers])
75 DPKG_CHECK_COMPILER_FLAG([-Wno-nonnull-compare])
76 DPKG_CHECK_COMPILER_FLAG([-Wno-tautological-constant-out-of-range-compare])
77 DPKG_CHECK_COMPILER_FLAG([-Wno-unused-parameter])
78 DPKG_CHECK_COMPILER_FLAG([-Wnull-dereference])
79 DPKG_CHECK_COMPILER_FLAG([-Wpointer-arith])
80 DPKG_CHECK_COMPILER_FLAG([-Wredundant-decls])
81 DPKG_CHECK_COMPILER_FLAG([-Wregister])
82 DPKG_CHECK_COMPILER_FLAG([-Wrestrict])
83 DPKG_CHECK_COMPILER_FLAG([-Wshadow])
84 DPKG_CHECK_COMPILER_FLAG([-Wshift-negative-value])
85 DPKG_CHECK_COMPILER_FLAG([-Wshift-overflow=2])
86 DPKG_CHECK_COMPILER_FLAG([-Wshift-sign-overflow])
87 DPKG_CHECK_COMPILER_FLAG([-Wsizeof-array-argument])
88 DPKG_CHECK_COMPILER_FLAG([-Wstrict-overflow=2])
89 DPKG_CHECK_COMPILER_FLAG([-Wswitch-bool])
90 DPKG_CHECK_COMPILER_FLAG([-Wvla])
91 DPKG_CHECK_COMPILER_FLAG([-Wwrite-strings])
95 DPKG_CHECK_COMPILER_FLAG([-Wbad-function-cast])
96 DPKG_CHECK_COMPILER_FLAG([-Wc99-c11-compat])
97 DPKG_CHECK_COMPILER_FLAG([-Wc99-compat])
98 DPKG_CHECK_COMPILER_FLAG([-Wc11-extensions])
99 DPKG_CHECK_COMPILER_FLAG([-Wc2x-compat])
100 DPKG_CHECK_COMPILER_FLAG([-Wc2x-extensions])
101 DPKG_CHECK_COMPILER_FLAG([-Wpre-c2x-compat])
102 DPKG_CHECK_COMPILER_FLAG([-Wdeclaration-after-statement])
103 DPKG_CHECK_COMPILER_FLAG([-Wmissing-prototypes])
104 DPKG_CHECK_COMPILER_FLAG([-Wnested-externs])
105 DPKG_CHECK_COMPILER_FLAG([-Wold-style-definition])
106 DPKG_CHECK_COMPILER_FLAG([-Wstrict-prototypes])
109 DPKG_CHECK_COMPILER_FLAG([-Wc++11-compat])
110 DPKG_CHECK_COMPILER_FLAG([-Wc++11-compat-pedantic])
111 DPKG_CHECK_COMPILER_FLAG([-Wc++11-extensions])
112 DPKG_CHECK_COMPILER_FLAG([-Wcast-qual])
113 DPKG_CHECK_COMPILER_FLAG([-Wold-style-cast])
114 AS_IF([test "x$dpkg_cv_cxx11" = "xyes"], [
115 DPKG_CHECK_COMPILER_FLAG([-Wzero-as-null-pointer-constant])
120 # DPKG_COMPILER_WARNINGS
121 # ----------------------
122 # Add configure option to disable additional compiler warnings.
123 AC_DEFUN([DPKG_COMPILER_WARNINGS], [
124 AC_ARG_ENABLE([compiler-warnings],
125 [AS_HELP_STRING([--disable-compiler-warnings],
126 [Disable (detected) additional compiler warnings])],
127 [], [enable_compiler_warnings=yes])
129 AS_IF([test "x$enable_compiler_warnings" = "xyes"], [
130 DPKG_CHECK_COMPILER_WARNINGS
132 DPKG_CHECK_COMPILER_WARNINGS
135 CFLAGS="$COMPILER_CFLAGS $CFLAGS"
136 CXXFLAGS="$COMPILER_CXXFLAGS $CXXFLAGS"
140 # DPKG_COMPILER_OPTIMIZATIONS
141 # ---------------------------
142 # Add configure option to disable optimizations.
143 AC_DEFUN([DPKG_COMPILER_OPTIMIZATIONS], [
144 AC_ARG_ENABLE([compiler-optimizations],
145 [AS_HELP_STRING([--disable-compiler-optimizations],
146 [Disable (detected) compiler optimizations])],
147 [], [enable_compiler_optimizations=yes])
149 AS_IF([test "x$enable_compiler_optimizations" = "xno"], [
150 CFLAGS=$(echo "$CFLAGS" | $SED -e "s/ -O[[1-9]]*\b/ -O0/g")
154 # DPKG_TRY_C99([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
155 # ------------------------------------------------------
156 # Try compiling some C99 code to see whether it works
157 AC_DEFUN([DPKG_TRY_C99], [
160 #include <inttypes.h>
164 /* Variadic macro arguments. */
165 #define variadic_macro(foo, ...) printf(foo, __VA_ARGS__)
169 /* Designated initializers. */
170 struct { int a, b; } foo = { .a = 1, .b = 2 };
172 /* Compound literals. */
173 struct point { int x, y; } p = (struct point){ .x = 0, .y = 1 };
174 p = (struct point){ .x = 2, .y = 4 };
176 /* Trailing comma in enum. */
177 enum { FIRST, SECOND, } quux;
182 /* Specific size type. */
184 size_t size = SIZE_MAX;
185 intmax_t imax = INTMAX_MAX;
187 /* Format modifiers. */
188 rc = printf("%jd", imax);
191 rc = printf("%zu", size);
195 /* Magic __func__ variable. */
196 printf("%s", __func__);
203 # Check whether the compiler can do C99
204 AC_DEFUN([DPKG_C_C99], [
205 AC_CACHE_CHECK([whether $CC supports C99 features], [dpkg_cv_c99], [
206 DPKG_TRY_C99([dpkg_cv_c99=yes], [dpkg_cv_c99=no])
208 AS_IF([test "x$dpkg_cv_c99" != "xyes"], [
209 AC_CACHE_CHECK([for $CC option to accept C99 features], [dpkg_cv_c99_arg], [
212 for arg in "-std=gnu99" "-std=c99" "-c99" "-AC99" "-xc99=all" \
213 "-qlanglvl=extc99"; do
214 CC="$dpkg_save_CC $arg"
215 DPKG_TRY_C99([dpkg_arg_worked=yes], [dpkg_arg_worked=no])
218 AS_IF([test "x$dpkg_arg_worked" = "xyes"], [
219 dpkg_cv_c99_arg="$arg"
224 AS_IF([test "x$dpkg_cv_c99_arg" != "xnone"], [
225 CC="$CC $dpkg_cv_c99_arg"
229 AS_IF([test "x$dpkg_cv_c99" = "xyes"], [
230 AC_DEFINE([HAVE_C99], 1, [Define to 1 if the compiler supports C99.])
232 AC_MSG_ERROR([unsupported required C99 extensions])
236 # DPKG_TRY_CXX11([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
238 # Try compiling some C++11 code to see whether it works.
239 AC_DEFUN([DPKG_TRY_CXX11], [
244 // Null pointer keyword.
248 AC_LANG_POP([C++])dnl
253 # Check whether the compiler can do C++11.
254 AC_DEFUN([DPKG_CXX_CXX11], [
255 AC_CACHE_CHECK([whether $CXX supports C++11], [dpkg_cv_cxx11], [
256 DPKG_TRY_CXX11([dpkg_cv_cxx11=yes], [dpkg_cv_cxx11=no])
258 AS_IF([test "x$dpkg_cv_cxx11" != "xyes"], [
259 AC_CACHE_CHECK([for $CXX option to accept C++11], [dpkg_cv_cxx11_arg], [
260 dpkg_cv_cxx11_arg=none
262 for arg in "-std=gnu++11" "-std=c++11"; do
263 CXX="$dpkg_save_CXX $arg"
264 DPKG_TRY_CXX11([dpkg_arg_worked=yes], [dpkg_arg_worked=no])
267 AS_IF([test "x$dpkg_arg_worked" = "xyes"], [
268 dpkg_cv_cxx11_arg="$arg"; break
272 AS_IF([test "x$dpkg_cv_cxx11_arg" != "xnone"], [
273 CXX="$CXX $dpkg_cv_cxx11_arg"
277 AS_IF([test "x$dpkg_cv_cxx11" = "xyes"], [
278 AC_DEFINE([HAVE_CXX11], 1, [Define to 1 if the compiler supports C++11.])