Debian Codegraph @

m4/warnings.m4

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