| 1 |
# serial 1 |
| 2 |
dnl Copyright 2017 Zack Weinberg <zackw at panix.com>. |
| 3 |
dnl Partially based on Autoconf, copyright 1992-2017 Free Software Foundation. |
| 4 |
dnl |
| 5 |
dnl This program is free software; you can redistribute it and/or |
| 6 |
dnl modify it under the terms of the GNU General Public License as |
| 7 |
dnl published by the Free Software Foundation, either version 3 of the |
| 8 |
dnl License, or (at your option) any later version. |
| 9 |
dnl |
| 10 |
dnl This program is distributed in the hope that it will be useful, |
| 11 |
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
dnl GNU General Public License for more details. |
| 14 |
dnl |
| 15 |
dnl Under Section 7 of GPL version 3, you are granted additional |
| 16 |
dnl permissions described in the Autoconf Configure Script Exception, |
| 17 |
dnl version 3.0, as published by the Free Software Foundation. |
| 18 |
dnl |
| 19 |
dnl Because only two files in this source tree are released |
| 20 |
dnl under GPLv3 with exceptions, neither the GPLv3 nor the exception are |
| 21 |
dnl distributed with this source tree. Copies can be retrieved from |
| 22 |
dnl https://www.gnu.org/licenses/ |
| 23 |
dnl |
| 24 |
dnl Autoconf core has no good way of enabling compiler warnings. |
| 25 |
dnl This is a cut-down version of the elaborate thing in the extras |
| 26 |
dnl archive, which we do not need nearly all of. |
| 27 |
dnl |
| 28 |
dnl Partly based on: |
| 29 |
dnl https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cflags.html |
| 30 |
|
| 31 |
AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF |
| 32 |
|
| 33 |
AC_DEFUN([zw_SIMPLE_ENABLE_WARNINGS], |
| 34 |
[ |
| 35 |
AC_ARG_ENABLE( |
| 36 |
[werror], |
| 37 |
AS_HELP_STRING( |
| 38 |
[--disable-werror], |
| 39 |
[do not treat all warnings as errors] |
| 40 |
), |
| 41 |
[case "${enableval}" in |
| 42 |
yes) warnings_are_errors=true ;; |
| 43 |
no) warnings_are_errors=false ;; |
| 44 |
*) AC_MSG_ERROR([bad value ${enableval} for --enable-werror]) ;; |
| 45 |
esac], |
| 46 |
[warnings_are_errors=true] |
| 47 |
) |
| 48 |
|
| 49 |
# Always pass -Werror=unknown-warning-option to get Clang to fail |
| 50 |
# on bad flags, otherwise they are always appended to the |
| 51 |
# warn_cflags variable, and Clang warns on them for every |
| 52 |
# compilation unit. If this is passed to GCC, it will explode, so |
| 53 |
# the flag must be enabled conditionally. |
| 54 |
AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[ |
| 55 |
ax_compiler_flags_test="-Werror=unknown-warning-option" |
| 56 |
],[ |
| 57 |
ax_compiler_flags_test="" |
| 58 |
]) |
| 59 |
|
| 60 |
# Don't enable -pedantic if we don't have C11, or we may get junk |
| 61 |
# warnings about static_assert. |
| 62 |
ax_candidate_warnings="dnl |
| 63 |
-Wall dnl |
| 64 |
-Wextra dnl |
| 65 |
-Walloc-zero dnl |
| 66 |
-Walloca dnl |
| 67 |
-Wbad-function-cast dnl |
| 68 |
-Wcast-align dnl |
| 69 |
-Wcast-qual dnl |
| 70 |
-Wconversion dnl |
| 71 |
-Wformat=2 dnl |
| 72 |
-Wformat-overflow=2 dnl |
| 73 |
-Wformat-signedness dnl |
| 74 |
-Wformat-truncation=1 dnl |
| 75 |
-Wlogical-op dnl |
| 76 |
-Wmissing-declarations dnl |
| 77 |
-Wmissing-prototypes dnl |
| 78 |
-Wnested-externs dnl |
| 79 |
-Wnull-dereference dnl |
| 80 |
-Wold-style-definition dnl |
| 81 |
-Wpointer-arith dnl |
| 82 |
-Wrestrict dnl |
| 83 |
-Wshadow dnl |
| 84 |
-Wstrict-overflow=2 dnl |
| 85 |
-Wstrict-prototypes dnl |
| 86 |
-Wundef dnl |
| 87 |
-Wvla dnl |
| 88 |
-Wwrite-strings dnl |
| 89 |
" |
| 90 |
if test x$ac_prog_cc_stdc = xc11; then |
| 91 |
ax_candidate_warnings="$ax_candidate_warnings -Wpedantic" |
| 92 |
fi |
| 93 |
if test x$warnings_are_errors = xtrue; then |
| 94 |
ax_candidate_warnings="$ax_candidate_warnings -Werror" |
| 95 |
fi |
| 96 |
|
| 97 |
# If we are building for OSX, turn -Wdeprecated-declarations off. |
| 98 |
# Apple is a little too trigger-happy with deprecations. |
| 99 |
case "$host_os" in |
| 100 |
(*darwin*) |
| 101 |
ax_candidate_warnings="$ax_candidate_warnings -Wno-deprecated-declarations" |
| 102 |
;; |
| 103 |
esac |
| 104 |
|
| 105 |
AX_APPEND_COMPILE_FLAGS( |
| 106 |
[$ax_candidate_warnings], [WARN_CFLAGS], |
| 107 |
[$ax_compiler_flags_test]) |
| 108 |
|
| 109 |
AC_SUBST(WARN_CFLAGS) |
| 110 |
|
| 111 |
if test $cross_compiling = yes; then |
| 112 |
# Repeat the above logic for the build compiler. |
| 113 |
|
| 114 |
save_cross_compiling=$cross_compiling |
| 115 |
save_ac_tool_prefix=$ac_tool_prefix |
| 116 |
save_CC="$CC" |
| 117 |
save_CFLAGS="$CFLAGS" |
| 118 |
save_CPPFLAGS="$CPPFLAGS" |
| 119 |
save_LDFLAGS="$LDFLAGS" |
| 120 |
|
| 121 |
cross_compiling=no |
| 122 |
ac_tool_prefix= |
| 123 |
CC="$CC_FOR_BUILD" |
| 124 |
CFLAGS="$CFLAGS_FOR_BUILD" |
| 125 |
CPPFLAGS="$CPPFLAGS_FOR_BUILD" |
| 126 |
LDFLAGS="$LDFLAGS_FOR_BUILD" |
| 127 |
|
| 128 |
pushdef([_AC_LANG_ABBREV],[build_c]) |
| 129 |
|
| 130 |
AX_CHECK_COMPILE_FLAG([-Werror=unknown-warning-option],[ |
| 131 |
ax_compiler_flags_test="-Werror=unknown-warning-option" |
| 132 |
],[ |
| 133 |
ax_compiler_flags_test="" |
| 134 |
]) |
| 135 |
AX_APPEND_COMPILE_FLAGS( |
| 136 |
[$ax_candidate_warnings], [WARN_CFLAGS_FOR_BUILD], |
| 137 |
[$ax_compiler_flags_test]) |
| 138 |
|
| 139 |
popdef([_AC_LANG_ABBREV]) |
| 140 |
|
| 141 |
AC_SUBST(WARN_CFLAGS_FOR_BUILD) |
| 142 |
|
| 143 |
cross_compiling=$save_cross_compiling |
| 144 |
ac_tool_prefix=$save_ac_tool_prefix |
| 145 |
CC="$save_CC" |
| 146 |
CFLAGS="$save_CFLAGS" |
| 147 |
CPPFLAGS="$save_CPPFLAGS" |
| 148 |
LDFLAGS="$save_LDFLAGS" |
| 149 |
fi # cross_compiling |
| 150 |
]) |