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