annotate m4/warnings.m4 @ 17473:1175d52f956a

warnings: check -Wfoo rather than -Wno-foo As reported by Christophe Fergeau and others, use of the warnings modules is awkward when probing for negative warning flags. For example, clang recognizes -Wno-unused-command-line-argument, but gcc does not; gcc silently ignores unknown warnings in isolation, but when something else also causes a compilation problem, gcc then compounds the overall message by also complaining about the unrecongized command line option at that time. The gcc manual documents that this behavior is intentional so that someone can add a -Wno-foo silencer to CFLAGS for a warning that older gcc does not understand, and where the warning is undesired under newer gcc; it also documents that probing for the -Wfoo positive form of the error is a reliable way to tell if the negative form will actually suppress anything. Clang will warn for both positive and negative forms of an unknown option. Since common usage includes: for w in $list; do gl_WARN_ADD([$w]) done the solution must be polymorphic to work on both m4 literals and shell variables (similar to AS_VAR_SET polymorphism). * m4/warnings.m4 (gl_COMPILER_OPTION_IF): If name begins with -Wno-, test if the compiler recognizes the positive form instead. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Wed, 14 Aug 2013 17:02:58 -0600
parents 7afa5abee433
children 88b6cb053cd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17473
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
1 # warnings.m4 serial 9
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16838
diff changeset
2 dnl Copyright (C) 2008-2013 Free Software Foundation, Inc.
10789
6a1640251330 Add warnings module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
3 dnl This file is free software; the Free Software Foundation
6a1640251330 Add warnings module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
6a1640251330 Add warnings module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
6a1640251330 Add warnings module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
6
6a1640251330 Add warnings module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
7 dnl From Simon Josefsson
6a1640251330 Add warnings module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
8
10790
8e910025bd67 warnings: Support non-literal arguments, and let the user choose the variable
Paolo Bonzini <bonzini@gnu.org>
parents: 10789
diff changeset
9 # gl_AS_VAR_APPEND(VAR, VALUE)
8e910025bd67 warnings: Support non-literal arguments, and let the user choose the variable
Paolo Bonzini <bonzini@gnu.org>
parents: 10789
diff changeset
10 # ----------------------------
8e910025bd67 warnings: Support non-literal arguments, and let the user choose the variable
Paolo Bonzini <bonzini@gnu.org>
parents: 10789
diff changeset
11 # Provide the functionality of AS_VAR_APPEND if Autoconf does not have it.
8e910025bd67 warnings: Support non-literal arguments, and let the user choose the variable
Paolo Bonzini <bonzini@gnu.org>
parents: 10789
diff changeset
12 m4_ifdef([AS_VAR_APPEND],
8e910025bd67 warnings: Support non-literal arguments, and let the user choose the variable
Paolo Bonzini <bonzini@gnu.org>
parents: 10789
diff changeset
13 [m4_copy([AS_VAR_APPEND], [gl_AS_VAR_APPEND])],
8e910025bd67 warnings: Support non-literal arguments, and let the user choose the variable
Paolo Bonzini <bonzini@gnu.org>
parents: 10789
diff changeset
14 [m4_define([gl_AS_VAR_APPEND],
8e910025bd67 warnings: Support non-literal arguments, and let the user choose the variable
Paolo Bonzini <bonzini@gnu.org>
parents: 10789
diff changeset
15 [AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])])
10789
6a1640251330 Add warnings module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
16
16728
b7fd03492209 warnings.m4: fix errors.
Akim Demaille <akim@lrde.epita.fr>
parents: 16723
diff changeset
17
16838
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
18 # gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED],
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
19 # [PROGRAM = AC_LANG_PROGRAM()])
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
20 # -----------------------------------------------------------------
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
21 # Check if the compiler supports OPTION when compiling PROGRAM.
16728
b7fd03492209 warnings.m4: fix errors.
Akim Demaille <akim@lrde.epita.fr>
parents: 16723
diff changeset
22 #
16838
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
23 # FIXME: gl_Warn must be used unquoted until we can assume Autoconf
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
24 # 2.64 or newer.
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
25 AC_DEFUN([gl_COMPILER_OPTION_IF],
16723
376ee9a0ad8d warnings.m4: check the compiler, not the preprocessor
Akim Demaille <akim@lrde.epita.fr>
parents: 16201
diff changeset
26 [AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl
16728
b7fd03492209 warnings.m4: fix errors.
Akim Demaille <akim@lrde.epita.fr>
parents: 16723
diff changeset
27 AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl
17473
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
28 AS_LITERAL_IF([$1],
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
29 [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))],
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
30 [gl_positive="$1"
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
31 case $gl_positive in
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
32 -Wno-*) gl_positive=`echo ".$gl_positive" | sed 's/^.//; s/^-Wno-/-W/'`;;
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
33 esac
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
34 m4_pushdef([gl_Positive], [$gl_positive])])dnl
16723
376ee9a0ad8d warnings.m4: check the compiler, not the preprocessor
Akim Demaille <akim@lrde.epita.fr>
parents: 16201
diff changeset
35 AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]), [
16728
b7fd03492209 warnings.m4: fix errors.
Akim Demaille <akim@lrde.epita.fr>
parents: 16723
diff changeset
36 gl_save_compiler_FLAGS="$gl_Flags"
17473
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
37 gl_AS_VAR_APPEND(m4_defn([gl_Flags]),
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
38 [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["])
16838
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
39 AC_COMPILE_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])],
15476
d569119b11e7 include-next, warnings: support older autoconf
Eric Blake <eblake@redhat.com>
parents: 14751
diff changeset
40 [AS_VAR_SET(gl_Warn, [yes])],
d569119b11e7 include-next, warnings: support older autoconf
Eric Blake <eblake@redhat.com>
parents: 14751
diff changeset
41 [AS_VAR_SET(gl_Warn, [no])])
16728
b7fd03492209 warnings.m4: fix errors.
Akim Demaille <akim@lrde.epita.fr>
parents: 16723
diff changeset
42 gl_Flags="$gl_save_compiler_FLAGS"
10789
6a1640251330 Add warnings module.
Simon Josefsson <simon@josefsson.org>
parents:
diff changeset
43 ])
16838
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
44 AS_VAR_IF(gl_Warn, [yes], [$2], [$3])
17473
1175d52f956a warnings: check -Wfoo rather than -Wno-foo
Eric Blake <eblake@redhat.com>
parents: 17401
diff changeset
45 m4_popdef([gl_Positive])dnl
16728
b7fd03492209 warnings.m4: fix errors.
Akim Demaille <akim@lrde.epita.fr>
parents: 16723
diff changeset
46 AS_VAR_POPDEF([gl_Flags])dnl
10790
8e910025bd67 warnings: Support non-literal arguments, and let the user choose the variable
Paolo Bonzini <bonzini@gnu.org>
parents: 10789
diff changeset
47 AS_VAR_POPDEF([gl_Warn])dnl
8e910025bd67 warnings: Support non-literal arguments, and let the user choose the variable
Paolo Bonzini <bonzini@gnu.org>
parents: 10789
diff changeset
48 ])
16838
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
49
17401
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
50 # gl_UNKNOWN_WARNINGS_ARE_ERRORS
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
51 # ------------------------------
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
52 # Clang doesn't complain about unknown warning options unless one also
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
53 # specifies -Wunknown-warning-option -Werror. Detect this.
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
54 AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS],
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
55 [gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option],
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
56 [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'],
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
57 [gl_unknown_warnings_are_errors=])])
16838
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
58
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
59 # gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS],
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
60 # [PROGRAM = AC_LANG_PROGRAM()])
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
61 # ---------------------------------------------
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
62 # Adds parameter to WARN_CFLAGS if the compiler supports it when
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
63 # compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]).
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
64 #
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
65 # If VARIABLE is a variable name, AC_SUBST it.
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
66 AC_DEFUN([gl_WARN_ADD],
17401
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
67 [AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS])
7afa5abee433 warnings: port to clang
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
68 gl_COMPILER_OPTION_IF([$1],
16838
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
69 [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CFLAGS]], [[$2]]), [" $1"])],
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
70 [],
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
71 [$3])
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
72 m4_ifval([$2],
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
73 [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
74 [AC_SUBST([WARN_CFLAGS])])dnl
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
75 ])
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
76
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
77 # Local Variables:
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
78 # mode: autoconf
a43ad261663e warnings.m4: provide a means to specify the program to compile.
Akim Demaille <akim@lrde.epita.fr>
parents: 16728
diff changeset
79 # End: