Use `scheme-mode` for the Guile init file
[emacs.git] / m4 / warnings.m4
blobfe7af01fc500a3aeef916b1010f7da69b109eb2e
1 # warnings.m4
2 # serial 20
3 dnl Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl From Simon Josefsson
10 AC_PREREQ([2.64])
12 # gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED],
13 #                       [PROGRAM = AC_LANG_PROGRAM()])
14 # -----------------------------------------------------------------
15 # Check if the compiler supports OPTION when compiling PROGRAM.
17 # The effects of this macro depend on the current language (_AC_LANG).
18 AC_DEFUN([gl_COMPILER_OPTION_IF],
20 AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl
21 AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl
22 AS_LITERAL_IF([$1],
23   [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))],
24   [gl_positive="$1"
25 case $gl_positive in
26   -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;;
27 esac
28 m4_pushdef([gl_Positive], [$gl_positive])])dnl
29 AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], [gl_Warn], [
30   gl_saved_compiler_FLAGS="$gl_Flags"
31   AS_VAR_APPEND(m4_defn([gl_Flags]),
32     [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["])
33   AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([[]])])],
34                  [AS_VAR_SET([gl_Warn], [yes])],
35                  [AS_VAR_SET([gl_Warn], [no])])
36   gl_Flags="$gl_saved_compiler_FLAGS"
38 AS_VAR_IF(gl_Warn, [yes], [$2], [$3])
39 m4_popdef([gl_Positive])dnl
40 AS_VAR_POPDEF([gl_Flags])dnl
41 AS_VAR_POPDEF([gl_Warn])dnl
44 # gl_UNKNOWN_WARNINGS_ARE_ERRORS
45 # ------------------------------
46 # Clang doesn't complain about unknown warning options unless one also
47 # specifies -Wunknown-warning-option -Werror.  Detect this.
49 # The effects of this macro depend on the current language (_AC_LANG).
50 AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS],
51 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
53 # Specialization for _AC_LANG = C. This macro can be AC_REQUIREd.
54 AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C)],
56   AC_LANG_PUSH([C])
57   gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
58   AC_LANG_POP([C])
61 # Specialization for _AC_LANG = C++. This macro can be AC_REQUIREd.
62 AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++)],
64   AC_LANG_PUSH([C++])
65   gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
66   AC_LANG_POP([C++])
69 # Specialization for _AC_LANG = Objective C. This macro can be AC_REQUIREd.
70 AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)],
72   AC_LANG_PUSH([Objective C])
73   gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
74   AC_LANG_POP([Objective C])
77 AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL],
78 [gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option],
79    [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'],
80    [gl_unknown_warnings_are_errors=])])
82 # gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS],
83 #             [PROGRAM = AC_LANG_PROGRAM()])
84 # -----------------------------------------------------------
85 # Adds OPTION to VARIABLE (which defaults to WARN_CFLAGS or WARN_CXXFLAGS)
86 # if the compiler supports it when compiling PROGRAM.
88 # If VARIABLE is a variable name, AC_SUBST it.
90 # The effects of this macro depend on the current language (_AC_LANG).
92 # Example: gl_WARN_ADD([-Wparentheses]).
93 AC_DEFUN([gl_WARN_ADD],
94 [AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)])
95 gl_COMPILER_OPTION_IF([$1],
96   [AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]]), [" $1"])],
97   [],
98   [$3])
99 m4_ifval([$2],
100          [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
101          [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl
105 # gl_CC_INHIBIT_WARNINGS
106 # sets and substitutes a variable GL_CFLAG_INHIBIT_WARNINGS, to a $(CC) option
107 # that reverts all preceding -W* options, if available.
108 # This is expected to be '-w' at least on gcc, clang, AIX xlc, xlclang, Sun cc,
109 # "compile cl" (MSVC), "compile clang-cl" (MSVC-compatible clang). Or it can be
110 # empty.
111 AC_DEFUN([gl_CC_INHIBIT_WARNINGS],
113   AC_REQUIRE([AC_PROG_CC])
114   AC_CACHE_CHECK([for C compiler option to inhibit all warnings],
115     [gl_cv_cc_winhibit],
116     [rm -f conftest*
117      echo 'int dummy;' > conftest.c
118      AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
119      AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -w -c conftest.c 2>conftest2.err]) >/dev/null
120      if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
121        gl_cv_cc_winhibit='-w'
122      else
123        gl_cv_cc_winhibit=none
124      fi
125      rm -f conftest*
126     ])
127   case "$gl_cv_cc_winhibit" in
128     none) GL_CFLAG_INHIBIT_WARNINGS='' ;;
129     *)
130       GL_CFLAG_INHIBIT_WARNINGS="$gl_cv_cc_winhibit"
131       dnl If all warnings are inhibited, there's no point in having the GCC
132       dnl analyzer enabled. This saves RAM requirements and CPU consumption.
133       gl_WARN_ADD([-fno-analyzer], [GL_CFLAG_INHIBIT_WARNINGS])
134       ;;
135   esac
136   AC_SUBST([GL_CFLAG_INHIBIT_WARNINGS])
139 # gl_CXX_INHIBIT_WARNINGS
140 # sets and substitutes a variable GL_CXXFLAG_INHIBIT_WARNINGS, to a $(CC) option
141 # that reverts all preceding -W* options, if available.
142 AC_DEFUN([gl_CXX_INHIBIT_WARNINGS],
144   dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
145   if test -n "$CXX" && test "$CXX" != no; then
146     AC_CACHE_CHECK([for C++ compiler option to inhibit all warnings],
147       [gl_cv_cxx_winhibit],
148       [rm -f conftest*
149        echo 'int dummy;' > conftest.cc
150        AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
151        AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -w -c conftest.cc 2>conftest2.err]) >/dev/null
152        if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
153          gl_cv_cxx_winhibit='-w'
154        else
155          gl_cv_cxx_winhibit=none
156        fi
157        rm -f conftest*
158       ])
159     case "$gl_cv_cxx_winhibit" in
160       none) GL_CXXFLAG_INHIBIT_WARNINGS='' ;;
161       *)
162         GL_CXXFLAG_INHIBIT_WARNINGS="$gl_cv_cxx_winhibit"
163         dnl If all warnings are inhibited, there's no point in having the GCC
164         dnl analyzer enabled. This saves RAM requirements and CPU consumption.
165         gl_WARN_ADD([-fno-analyzer], [GL_CXXFLAG_INHIBIT_WARNINGS])
166         ;;
167     esac
168   else
169     GL_CXXFLAG_INHIBIT_WARNINGS=''
170   fi
171   AC_SUBST([GL_CXXFLAG_INHIBIT_WARNINGS])
175 # Local Variables:
176 # mode: autoconf
177 # End: