1 dnl Check whether the C compiler accepts a warning option
2 dnl Copyright (C) 2019 Roland Lutz
4 dnl This program is free software; you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation; either version 2 of the License, or
7 dnl (at your option) any later version.
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 dnl GNU General Public License for more details.
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program; if not, write to the Free Software
16 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 # Usage: AX_PROG_CC_WARNING([foo_bar], [foo-bar])
20 # Checks whether the C compiler accepts -Wfoo-bar and defines the
21 # following shell and output variables depending on the result:
23 # Wfoo_bar_IF_SUPPORTED = -Wfoo-bar or empty
24 # Wno_foo_bar_IF_SUPPORTED = -Wno-foo-bar or empty
25 # Werror_foo_bar_IF_SUPPORTED = -Werror=foo-bar or empty
26 # Wno_error_foo_bar_IF_SUPPORTED = -Wno-error=foo-bar or empty
28 AC_DEFUN([AX_PROG_CC_WARNING], [
29 AC_CACHE_CHECK([whether $CC accepts -W$2],
32 ax_save_CFLAGS=$CFLAGS
34 ax_save_c_werror_flag=$ac_c_werror_flag
36 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
37 [ax_cv_prog_cc_W$1=yes],
39 CFLAGS=$ax_save_CFLAGS
40 ac_c_werror_flag=$ax_save_c_werror_flag])
42 if test "x$ax_cv_prog_cc_W$1" = xyes; then
43 W$1_IF_SUPPORTED="-W$2"
44 Wno_$1_IF_SUPPORTED="-Wno-$2"
45 Werror_$1_IF_SUPPORTED="-Werror=$2"
46 Wno_error_$1_IF_SUPPORTED="-Wno-error=$2"
48 AC_SUBST([W$1_IF_SUPPORTED])
49 AC_SUBST([Wno_$1_IF_SUPPORTED])
50 AC_SUBST([Werror_$1_IF_SUPPORTED])
51 AC_SUBST([Wno_error_$1_IF_SUPPORTED])