Debian Codegraph @

m4/warnings.m4

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