autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Turn on compiler warnings by default for AC_PROG_CC, AC_PROG_CXX & A


From: Dale Visser
Subject: Re: Turn on compiler warnings by default for AC_PROG_CC, AC_PROG_CXX & AC_PROG_FC
Date: Fri, 10 Jan 2014 10:43:31 -0500


My apologies. I just realized that I submitted a commit-by-commit patch, when I just wanted to share the overall diff. Please use the following as the basis for discussion:

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index a2368e7..87c70fb 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -7160,7 +7160,7 @@ makes this invalid.  That is why Autoconf stopped issuing
address@hidden table
 
address@hidden
address@hidden AC_PROG_CC (@ovar{compiler-search-list})
address@hidden AC_PROG_CC (@ovar{compiler-search-list}, @dots{})
address@hidden
address@hidden CC
address@hidden CFLAGS
@@ -7213,6 +7213,15 @@ other compilers.  If your package does not like this default, then it is
 acceptable to insert the line @samp{: address@hidden""@}} after @code{AC_INIT}
 and before @code{AC_PROG_CC} to select an empty default instead.
 
+Scan for common flags that enable compiler warnings. If found, append them
+to @code{CFLAGS}. To modify this behaviour, for example, to restore the old
+no-warning-flag behaviour, add parameters which will get shifted by 1,
+and passed on to @code{AC_FLAGS_WARN_ALL}.
+
address@hidden
+AC_PROG_CC([], [], [], [echo No warning flags please.])
address@hidden example
+
 Many Autoconf macros use a compiler, and thus call
address@hidden([AC_PROG_CC])} to ensure that the compiler has been
 determined before the body of the outermost @code{AC_DEFUN} macro.
@@ -7537,7 +7546,7 @@ compiler fix the header files automatically when installed.
address@hidden C++ Compiler Characteristics
 
 
address@hidden AC_PROG_CXX (@ovar{compiler-search-list})
address@hidden AC_PROG_CXX (@ovar{compiler-search-list}, @dots{})
address@hidden
address@hidden CXX
address@hidden CXXFLAGS
@@ -7599,6 +7608,16 @@ systems where G++ does not accept @option{-g}), or @option{-g} for other
 compilers.  If your package does not like this default, then it is
 acceptable to insert the line @samp{: address@hidden""@}} after @code{AC_INIT}
 and before @code{AC_PROG_CXX} to select an empty default instead.
+
+Scan for common flags that enable compiler warnings. If found, append them
+to @code{CXXFLAGS}. To modify this behaviour, for example, to restore the old
+no-warning-flag behaviour, add parameters which will get shifted by 1,
+and passed on to @code{AC_FLAGS_WARN_ALL}.
+
address@hidden
+AC_PROG_CXX([], [], [], [echo No warning flags please.])
address@hidden example
+
address@hidden defmac
 
address@hidden AC_PROG_CXXCPP
@@ -7825,7 +7844,7 @@ The result of the GNU test is cached in the
address@hidden variable.
address@hidden defmac
 
address@hidden AC_PROG_FC (@ovar{compiler-search-list}, @ovar{dialect})
address@hidden AC_PROG_FC (@ovar{compiler-search-list}, @ovar{dialect}, @dots{})
address@hidden
address@hidden FC
address@hidden FCFLAGS
@@ -7863,6 +7882,17 @@ set @code{FCFLAGS} to @option{-g} for all other Fortran compilers.
 The result of the GNU test is cached in the @code{ac_cv_fc_compiler_gnu}
 variable, acceptance of @option{-g} in the @code{ac_cv_prog_fc_g}
 variable.
+
+Scan for common flags that enable compiler warnings. If found, append them
+to @code{FCFLAGS}. To modify this behaviour, for example, to restore the old
+no-warning-flag behaviour, add parameters which will get shifted by 2,
+and passed on to @code{AC_FLAGS_WARN_ALL}.
+
address@hidden
+AC_PROG_FC([], [], [], [], [echo No warning flags please.])
address@hidden example
+
+
address@hidden defmac
 
address@hidden AC_PROG_F77_C_O
@@ -23427,6 +23457,71 @@ The current language does not change.  @code{AC_LANG_PUSH} is preferred
 (@pxref{AC_LANG_PUSH}).
address@hidden defmac
 
address@hidden
address@hidden AC_CFLAGS_WARN_ALL(@var{shell-variable-to-add-to}, @var{add-value-if-not-found}, @var{action-if-found}, @var{action-if-not-found})
address@hidden
+Try to find a C compiler option that enables most reasonable warnings. See
address@hidden for how to use the (optional) parameters. The most
+typical usage is shown below.
+
address@hidden
+AC_CFLAGS_WARN_ALL
address@hidden example
address@hidden defmac
+
address@hidden
address@hidden AC_CXXFLAGS_WARN_ALL(@var{shell-variable-to-add-to}, @var{add-value-if-not-found}, @var{action-if-found}, @var{action-if-not-found})
address@hidden
+Try to find a C++ compiler option that enables most reasonable warnings. See
address@hidden for how to use the (optional) parameters. The most
+typical usage is shown below.
+
address@hidden
+AC_CXXFLAGS_WARN_ALL
address@hidden example
address@hidden defmac
+
address@hidden
address@hidden AC_FCFLAGS_WARN_ALL(@var{shell-variable-to-add-to}, @var{add-value-if-not-found}, @var{action-if-found}, @var{action-if-not-found})
address@hidden
+Try to find a Fortran compiler option that enables most reasonable warnings.
+See @pxref{AC_FLAGS_WARN_ALL} for how to use the (optional) parameters. The most
+typical usage is shown below.
+
address@hidden
+AC_FCFLAGS_WARN_ALL
address@hidden example
address@hidden defmac
+
address@hidden
address@hidden AC_FLAGS_WARN_ALL(@var{shell-variable-to-add-to}, @var{add-value-if-not-found}, @var{action-if-found}, @var{action-if-not-found})
address@hidden
+Try to find a compiler option that enables most reasonable warnings.
+
+Usually not used directly. Instead, use @pxref{AC_CFLAGS_WARN_ALL},
address@hidden, or @pxref{AC_FCFLAGS_WARN_ALL}, all of which perform
+a requisite @pxref{AC_LANG_PUSH}, and then invoke this macro without altering any
+positional parameters they were provided.
+
+The first positional parameter defines the shell variable to use, and
+if not provided, depends on @pxref{AC_LANG_PUSH} having been invoked properly.
+If appropriate warning flag values can be automatically determined for the
+compiler, then the third positional parameter (if present) defines an
+alternate action to take instead of appending to the shell variable. If no
+appropriate warning flag values could be determined, then the second
+positional parameter (if present) defines alternate flags to append to the
+shell variable, unless the fourth positional parameter is present, in which
+case it defines an alternate action to take instead of appending to the shell
+variable.
address@hidden defmac
+
address@hidden AC_APPEND_FLAG(@var{add-value})
address@hidden
+Used internally by @pxref{AC_FLAGS_WARN_ALL}. Behavior is to append the given to
+the shell variable determined or provided in the call to
address@hidden, but only if it is not already present there.
address@hidden defmac
+
address@hidden AC_LINK_FILES (@address@hidden, @address@hidden)
address@hidden
 This is an obsolete version of @code{AC_CONFIG_LINKS}
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 25780f9..c018c92 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -424,11 +424,17 @@ AU_DEFUN([ac_cv_prog_gcc],
 [ac_cv_c_compiler_gnu])
 
 
-# AC_PROG_CC([COMPILER ...])
+# AC_PROG_CC([COMPILER ...], ...)
 # --------------------------
 # COMPILER ... is a space separated list of C compilers to search for.
 # This just gives the user an opportunity to specify an alternative
 # search list for the C compiler.
+# Any extra parameters will be passed on to AC_FLAGS_WARN_ALL. If there
+# are no extra parameters, then compiler warnings will be turned on. An
+# example of how to avoid this is invoking
+# AC_PROG_CC([COMPILER ...], [], [], [echo No extra warnings please.])
+# Where the final parameter is providing an alternate action to enabling
+# warning flags.
 AN_MAKEVAR([CC],  [AC_PROG_CC])
 AN_PROGRAM([cc],  [AC_PROG_CC])
 AN_PROGRAM([gcc], [AC_PROG_CC])
@@ -491,6 +497,7 @@ _AC_PROG_CC_C11([ac_prog_cc_stdc=c11
               [ac_prog_cc_stdc=no
                ac_cv_prog_cc_stdc=no])])])
 dnl
+AC_FLAGS_WARN_ALL(m4_shift($@))
 AC_LANG_POP(C)dnl
 ])# AC_PROG_CC
 
@@ -674,7 +681,7 @@ AU_DEFUN([ac_cv_prog_gxx],
 [ac_cv_cxx_compiler_gnu])
 
 
-# AC_PROG_CXX([LIST-OF-COMPILERS])
+# AC_PROG_CXX([LIST-OF-COMPILERS], ...)
 # --------------------------------
 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
 # for (if not specified, a default list is used).  This just gives the
@@ -686,6 +693,12 @@ AU_DEFUN([ac_cv_prog_gxx],
 # RCC    Rational C++
 # xlC_r    AIX C Set++ (with support for reentrant code)
 # xlC    AIX C Set++
+# Any extra parameters will be passed on to AC_FLAGS_WARN_ALL. If there
+# are no extra parameters, then compiler warnings will be turned on. An
+# example of how to avoid this is invoking
+# AC_PROG_CXX([LIST-OF-COMPILERS], [], [], [echo No extra warnings please.])
+# Where the final parameter is providing an alternate action to enabling
+# warning flags.
 AN_MAKEVAR([CXX],  [AC_PROG_CXX])
 AN_PROGRAM([CC],   [AC_PROG_CXX])
 AN_PROGRAM([c++],  [AC_PROG_CXX])
@@ -732,6 +745,7 @@ _AC_PROG_CXX_CXX11([ac_prog_cxx_stdcxx=cxx11
                 ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98],
                [ac_prog_cxx_stdcxx=no
                 ac_cv_prog_cxx_stdcxx=no])])
+AC_FLAGS_WARN_ALL(m4_shift($@))
 AC_LANG_POP(C++)dnl
 ])# AC_PROG_CXX
 
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index f20b029..8280e48 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -371,10 +371,16 @@ AC_LANG_POP(Fortran 77)dnl
 ])# AC_PROG_F77
 
 
-# AC_PROG_FC([COMPILERS...], [DIALECT])
+# AC_PROG_FC([COMPILERS...], [DIALECT], ...)
 # -------------------------------------
 # COMPILERS is a space separated list of Fortran 77 compilers to search
 # for, and [DIALECT] is an optional dialect.  See also _AC_PROG_FC.
+# Any extra parameters will be passed on to AC_FLAGS_WARN_ALL. If there
+# are no extra parameters, then compiler warnings will be turned on. An
+# example of how to avoid this is invoking
+# AC_PROG_FC([COMPILERS...], [DIALECT], [], [], [echo No extra warnings please.])
+# Where the final parameter is providing an alternate action to enabling
+# warning flags.
 AC_DEFUN([AC_PROG_FC],
 [AC_LANG_PUSH(Fortran)dnl
 AC_ARG_VAR([FC],    [Fortran compiler command])dnl
@@ -387,6 +393,7 @@ if test $ac_compiler_gnu = yes; then
 else
   GFC=
 fi
+AC_FLAGS_WARN_ALL(m4_shift2($@))
 AC_LANG_POP(Fortran)dnl
 ])# AC_PROG_FC
 
diff --git a/lib/autoconf/lang.m4 b/lib/autoconf/lang.m4
index c99f152..0c86b63 100644
--- a/lib/autoconf/lang.m4
+++ b/lib/autoconf/lang.m4
@@ -719,3 +719,139 @@ ac_objext=$OBJEXT
 AC_DEFUN([AC_LANG_WERROR],
 [m4_divert_text([DEFAULTS], [ac_[]_AC_LANG_ABBREV[]_werror_flag=])
 ac_[]_AC_LANG_ABBREV[]_werror_flag=yes])# AC_LANG_WERROR
+
+#
+# SYNOPSIS
+#
+#   AC_APPEND_FLAG(FLAG, [FLAGS-VARIABLE])
+#
+# DESCRIPTION
+#
+#   FLAG is appended to the FLAGS-VARIABLE shell variable, with a space
+#   added in between.
+#
+#   If FLAGS-VARIABLE is not specified, the current language's flags (e.g.
+#   CFLAGS) is used.  FLAGS-VARIABLE is not changed if it already contains
+#   FLAG.  If FLAGS-VARIABLE is unset in the shell, it is set to exactly
+#   FLAG.
+#
+#   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION.
+#   NOTE: Copied from AX_APPEND_FLAG in autoconf-archive, which had copyright
+#         assigned as follows:
+#
+#           Copyright (c) 2008 Guido U. Draheim <address@hidden>
+#           Copyright (c) 2011 Maarten Bosmans <address@hidden>
+#
+
+#serial 2
+
+AC_DEFUN([AC_APPEND_FLAG],
+[AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])])dnl
+AS_VAR_SET_IF(FLAGS,
+  [case " AS_VAR_GET(FLAGS) " in
+    *" $1 "*)
+      AC_RUN_LOG([: FLAGS already contains $1])
+      ;;
+    *)
+      AC_RUN_LOG([: FLAGS="$FLAGS $1"])
+      AS_VAR_SET(FLAGS, ["AS_VAR_GET(FLAGS) $1"])
+      ;;
+   esac],
+  [AS_VAR_SET(FLAGS,["$1"])])
+AS_VAR_POPDEF([FLAGS])dnl
+])dnl AC_APPEND_FLAG
+
+#
+# SYNOPSIS
+#
+#   AC_CFLAGS_WARN_ALL   [(shellvar [,default, [A/NA]])]
+#   AC_CXXFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]
+#   AC_FCFLAGS_WARN_ALL  [(shellvar [,default, [A/NA]])]
+#
+# DESCRIPTION
+#
+#   Try to find a compiler option that enables most reasonable warnings.
+#
+#   For the GNU compiler it will be -Wall (and -ansi -pedantic) The result
+#   is added to the shellvar being CFLAGS, CXXFLAGS, or FCFLAGS by default.
+#
+#   Currently this macro knows about the GCC, Solaris, Digital Unix, AIX,
+#   HP-UX, IRIX, NEC SX-5 (Super-UX 10), Cray J90 (Unicos 10.0.0.8), and
+#   Intel compilers.  For a given compiler, the Fortran flags are much more
+#   experimental than their C equivalents.
+#
+#    - $1 shell-variable-to-add-to : CFLAGS, CXXFLAGS, or FCFLAGS
+#    - $2 add-value-if-not-found : nothing
+#    - $3 action-if-found : add value to shellvariable
+#    - $4 action-if-not-found : nothing
+#
+#   NOTE: These macros depend on AX_APPEND_FLAG.
+#   NOTE: Based upon AX_*FLAGS_WARN_ALL from autoconf-archive, which had
+#         copyright assigned as follows:
+#
+#           Copyright (c) 2008 Guido U. Draheim <address@hidden>
+#           Copyright (c) 2010 Rhys Ulerich <address@hidden>
+#
+
+#serial 14
+
+AC_DEFUN([AC_FLAGS_WARN_ALL],[dnl
+AS_VAR_PUSHDEF([FLAGS],[_AC_LANG_PREFIX[]FLAGS])dnl
+AS_VAR_PUSHDEF([VAR],[ac_cv_[]_AC_LANG_ABBREV[]flags_warn_all])dnl
+AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
+VAR,[VAR="no, unknown"
+ac_save_[]FLAGS="$[]FLAGS"
+for ac_arg dnl
+in "-warn all  % -warn all"   dnl Intel
+   "-pedantic  % -Wall"       dnl GCC
+   "-xstrconst % -v"          dnl Solaris C
+   "-std1      % -verbose -w0 -warnprotos" dnl Digital Unix
+   "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
+   "-ansi -ansiE % -fullwarn" dnl IRIX
+   "+ESlit     % +w1"         dnl HP-UX C
+   "-Xc        % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
+   "-h conform % -h msglevel 2" dnl Cray C (Unicos)
+   #
+do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
+   _AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
+                     [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
+done
+FLAGS="$ac_save_[]FLAGS"
+])
+AS_VAR_POPDEF([FLAGS])dnl
+AC_REQUIRE([AC_APPEND_FLAG])
+case ".$VAR" in
+     .ok|.ok,*) m4_ifvaln($3,$3) ;;
+   .|.no|.no,*) m4_default($4,[m4_ifval($2,[AC_APPEND_FLAG([$2], [$1])])]) ;;
+   *) m4_default($3,[AC_APPEND_FLAG([$VAR], [$1])]) ;;
+esac
+AS_VAR_POPDEF([VAR])dnl
+])dnl AC_FLAGS_WARN_ALL
+dnl  implementation tactics:
+dnl   the for-argument contains a list of options. The first part of
+dnl   these does only exist to detect the compiler - usually it is
+dnl   a global option to enable -ansi or -extrawarnings. All other
+dnl   compilers will fail about it. That was needed since a lot of
+dnl   compilers will give false positives for some option-syntax
+dnl   like -Woption or -Xoption as they think of it is a pass-through
+dnl   to later compile stages or something. The "%" is used as a
+dnl   delimiter. A non-option comment can be given after "%%" marks
+dnl   which will be shown but not added to the respective C/CXXFLAGS.
+
+AC_DEFUN([AC_CFLAGS_WARN_ALL],[dnl
+AC_LANG_PUSH([C])
+AC_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
+AC_LANG_POP([C])
+])
+
+AC_DEFUN([AC_CXXFLAGS_WARN_ALL],[dnl
+AC_LANG_PUSH([C++])
+AC_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
+AC_LANG_POP([C++])
+])
+
+AC_DEFUN([AC_FCFLAGS_WARN_ALL],[dnl
+AC_LANG_PUSH([Fortran])
+AC_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
+AC_LANG_POP([Fortran])
+])



On Fri, Jan 10, 2014 at 10:30 AM, Dale Visser <address@hidden> wrote:
The inspiration for this comes from an earlier discussion on the 'autoconf' list: http://lists.gnu.org/archive/html/autoconf/2013-10/msg00025.html

The basic idea is to overall enhance the security of code built using autoconf, by turning on compiler warnings that the developers wouldn't otherwise think to.

The patch ports over AX_FLAGS_WARN_ALL from the autoconf archive, and invokes it by default within AC_PROG_CC, AC_PROG_CXX and AC_PROG_FC. Of course, a mechanism is provided for turning off the new behavior, i.e., restoring the classic "no extra warnings" mode.

---
 lib/autoconf/lang.m4 | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)

diff --git a/lib/autoconf/lang.m4 b/lib/autoconf/lang.m4
index c99f152..8d2ba73 100644
--- a/lib/autoconf/lang.m4
+++ b/lib/autoconf/lang.m4
@@ -719,3 +719,139 @@ ac_objext=$OBJEXT
 AC_DEFUN([AC_LANG_WERROR],
 [m4_divert_text([DEFAULTS], [ac_[]_AC_LANG_ABBREV[]_werror_flag=])
 ac_[]_AC_LANG_ABBREV[]_werror_flag=yes])# AC_LANG_WERROR
+
+#
+# SYNOPSIS
+#
+#   AC_APPEND_FLAG(FLAG, [FLAGS-VARIABLE])
+#
+# DESCRIPTION
+#
+#   FLAG is appended to the FLAGS-VARIABLE shell variable, with a space
+#   added in between.
+#
+#   If FLAGS-VARIABLE is not specified, the current language's flags (e.g.
+#   CFLAGS) is used.  FLAGS-VARIABLE is not changed if it already contains
+#   FLAG.  If FLAGS-VARIABLE is unset in the shell, it is set to exactly
+#   FLAG.
+#
+#   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION.
+#   NOTE: Copied from AX_APPEND_FLAG in autoconf-archive, which had copyright
+#         assigned as follows:
+#
+#           Copyright (c) 2008 Guido U. Draheim <address@hidden>
+#           Copyright (c) 2011 Maarten Bosmans <address@hidden>
+#
+
+#serial 2
+
+AC_DEFUN([AC_APPEND_FLAG],
+[AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])])dnl
+AS_VAR_SET_IF(FLAGS,
+  [case " AS_VAR_GET(FLAGS) " in
+    *" $1 "*)
+      AC_RUN_LOG([: FLAGS already contains $1])
+      ;;
+    *)
+      AC_RUN_LOG([: FLAGS="$FLAGS $1"])
+      AS_VAR_SET(FLAGS, ["AS_VAR_GET(FLAGS) $1"])
+      ;;
+   esac],
+  [AS_VAR_SET(FLAGS,["$1"])])
+AS_VAR_POPDEF([FLAGS])dnl
+])dnl AC_APPEND_FLAG
+
+#
+# SYNOPSIS
+#
+#   AC_CFLAGS_WARN_ALL   [(shellvar [,default, [A/NA]])]
+#   AC_CXXFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]
+#   AC_FCFLAGS_WARN_ALL  [(shellvar [,default, [A/NA]])]
+#
+# DESCRIPTION
+#
+#   Try to find a compiler option that enables most reasonable warnings.
+#
+#   For the GNU compiler it will be -Wall (and -ansi -pedantic) The result
+#   is added to the shellvar being CFLAGS, CXXFLAGS, or FCFLAGS by default.
+#
+#   Currently this macro knows about the GCC, Solaris, Digital Unix, AIX,
+#   HP-UX, IRIX, NEC SX-5 (Super-UX 10), Cray J90 (Unicos 10.0.0.8), and
+#   Intel compilers.  For a given compiler, the Fortran flags are much more
+#   experimental than their C equivalents.
+#
+#    - $1 shell-variable-to-add-to : CFLAGS, CXXFLAGS, or FCFLAGS
+#    - $2 add-value-if-not-found : nothing
+#    - $3 action-if-found : add value to shellvariable
+#    - $4 action-if-not-found : nothing
+#
+#   NOTE: These macros depend on AX_APPEND_FLAG.
+#   NOTE: Based upon AX_*FLAGS_WARN_ALL from autoconf-archive, which had
+#         copyright assigned as follows:
+#
+#           Copyright (c) 2008 Guido U. Draheim <address@hidden>
+#           Copyright (c) 2010 Rhys Ulerich <address@hidden>
+#
+
+#serial 14
+
+AC_DEFUN([AC_FLAGS_WARN_ALL],[dnl
+AS_VAR_PUSHDEF([FLAGS],[_AC_LANG_PREFIX[]FLAGS])dnl
+AS_VAR_PUSHDEF([VAR],[ac_cv_[]_AC_LANG_ABBREV[]flags_warn_all])dnl
+AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
+VAR,[VAR="no, unknown"
+ac_save_[]FLAGS="$[]FLAGS"
+for ac_arg dnl
+in "-warn all  % -warn all"   dnl Intel
+   "-pedantic  % -Wall"       dnl GCC
+   "-xstrconst % -v"          dnl Solaris C
+   "-std1      % -verbose -w0 -warnprotos" dnl Digital Unix
+   "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
+   "-ansi -ansiE % -fullwarn" dnl IRIX
+   "+ESlit     % +w1"         dnl HP-UX C
+   "-Xc        % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
+   "-h conform % -h msglevel 2" dnl Cray C (Unicos)
+   #
+do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
+   AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
+                     [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
+done
+FLAGS="$ac_save_[]FLAGS"
+])
+AS_VAR_POPDEF([FLAGS])dnl
+AC_REQUIRE([AC_APPEND_FLAG])
+case ".$VAR" in
+     .ok|.ok,*) m4_ifvaln($3,$3) ;;
+   .|.no|.no,*) m4_default($4,[m4_ifval($2,[AX_APPEND_FLAG([$2], [$1])])]) ;;
+   *) m4_default($3,[AX_APPEND_FLAG([$VAR], [$1])]) ;;
+esac
+AS_VAR_POPDEF([VAR])dnl
+])dnl AC_FLAGS_WARN_ALL
+dnl  implementation tactics:
+dnl   the for-argument contains a list of options. The first part of
+dnl   these does only exist to detect the compiler - usually it is
+dnl   a global option to enable -ansi or -extrawarnings. All other
+dnl   compilers will fail about it. That was needed since a lot of
+dnl   compilers will give false positives for some option-syntax
+dnl   like -Woption or -Xoption as they think of it is a pass-through
+dnl   to later compile stages or something. The "%" is used as a
+dnl   delimiter. A non-option comment can be given after "%%" marks
+dnl   which will be shown but not added to the respective C/CXXFLAGS.
+
+AC_DEFUN([AC_CFLAGS_WARN_ALL],[dnl
+AC_LANG_PUSH([C])
+AC_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
+AC_LANG_POP([C])
+])
+
+AC_DEFUN([AC_CXXFLAGS_WARN_ALL],[dnl
+AC_LANG_PUSH([C++])
+AC_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
+AC_LANG_POP([C++])
+])
+
+AC_DEFUN([AC_FCFLAGS_WARN_ALL],[dnl
+AC_LANG_PUSH([Fortran])
+AC_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
+AC_LANG_POP([Fortran])
+])
--
1.8.3.2


From d03cbf1f4260494590c0c597d76339bfa1ab462d Mon Sep 17 00:00:00 2001
From: Dale Visser <address@hidden>
Date: Fri, 20 Dec 2013 13:10:33 -0500
Subject: [PATCH 02/10] Missed renaming AX_APPEND_FLAG in two locations.

---
 lib/autoconf/lang.m4 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/autoconf/lang.m4 b/lib/autoconf/lang.m4
index 8d2ba73..e17d70f 100644
--- a/lib/autoconf/lang.m4
+++ b/lib/autoconf/lang.m4
@@ -822,8 +822,8 @@ AS_VAR_POPDEF([FLAGS])dnl
 AC_REQUIRE([AC_APPEND_FLAG])
 case ".$VAR" in
      .ok|.ok,*) m4_ifvaln($3,$3) ;;
-   .|.no|.no,*) m4_default($4,[m4_ifval($2,[AX_APPEND_FLAG([$2], [$1])])]) ;;
-   *) m4_default($3,[AX_APPEND_FLAG([$VAR], [$1])]) ;;
+   .|.no|.no,*) m4_default($4,[m4_ifval($2,[AC_APPEND_FLAG([$2], [$1])])]) ;;
+   *) m4_default($3,[AC_APPEND_FLAG([$VAR], [$1])]) ;;
 esac
 AS_VAR_POPDEF([VAR])dnl
 ])dnl AC_FLAGS_WARN_ALL
--
1.8.3.2


From 9a1432215b7ae18b8913e000c77fd5d4618c6b8e Mon Sep 17 00:00:00 2001
From: Dale Visser <address@hidden>
Date: Fri, 20 Dec 2013 16:29:59 -0500
Subject: [PATCH 03/10] Added first attempt at useful documentation for
 FLAGS_WARN_ALL.

---
 doc/autoconf.texi | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index a2368e7..b68d19d 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -23427,6 +23427,71 @@ The current language does not change.  @code{AC_LANG_PUSH} is preferred
 (@pxref{AC_LANG_PUSH}).
address@hidden defmac
 
address@hidden
address@hidden AC_CFLAGS_WARN_ALL(@var{shell-variable-to-add-to}, @var{add-value-if-not-found}, @var{action-if-found}, @var{action-if-not-found})
address@hidden
+Try to find a C compiler option that enables most reasonable warnings. See
address@hidden for how to use the (optional) parameters. The most
+typical usage is shown below.
+
address@hidden
+AC_CFLAGS_WARN_ALL
address@hidden example
address@hidden defmac
+
address@hidden
address@hidden AC_CXXFLAGS_WARN_ALL(@var{shell-variable-to-add-to}, @var{add-value-if-not-found}, @var{action-if-found}, @var{action-if-not-found})
address@hidden
+Try to find a C++ compiler option that enables most reasonable warnings. See
address@hidden for how to use the (optional) parameters. The most
+typical usage is shown below.
+
address@hidden
+AC_CXXFLAGS_WARN_ALL
address@hidden example
address@hidden defmac
+
address@hidden
address@hidden AC_FCFLAGS_WARN_ALL(@var{shell-variable-to-add-to}, @var{add-value-if-not-found}, @var{action-if-found}, @var{action-if-not-found})
address@hidden
+Try to find a Fortran compiler option that enables most reasonable warnings.
+See @pxref{AC_FLAGS_WARN_ALL} for how to use the (optional) parameters. The most
+typical usage is shown below.
+
address@hidden
+AC_FCFLAGS_WARN_ALL
address@hidden example
address@hidden defmac
+
address@hidden
address@hidden AC_FLAGS_WARN_ALL(@var{shell-variable-to-add-to}, @var{add-value-if-not-found}, @var{action-if-found}, @var{action-if-not-found})
address@hidden
+Try to find a compiler option that enables most reasonable warnings.
+
+Usually not used directly. Instead, use @pxref{AC_CFLAGS_WARN_ALL},
address@hidden, or @pxref{AC_FCFLAGS_WARN_ALL}, all of which perform
+a requisite @pxref{AC_LANG_PUSH}, and then invoke this macro without altering any
+positional parameters they were provided.
+
+The first positional parameter defines the shell variable to use, and
+if not provided, depends on @pxref{AC_LANG_PUSH} having been invoked properly.
+If appropriate warning flag values can be automatically determined for the
+compiler, then the third positional parameter (if present) defines an
+alternate action to take instead of appending to the shell variable. If no
+appropriate warning flag values could be determined, then the second
+positional parameter (if present) defines alternate flags to append to the
+shell variable, unless the fourth positional parameter is present, in which
+case it defines an alternate action to take instead of appending to the shell
+variable.
address@hidden defmac
+
address@hidden AC_APPEND_FLAG(@var{add-value})
address@hidden
+Used internally by @pxref{AC_FLAGS_WARN_ALL}. Behavior is to append the given to
+the shell variable determined or provided in the call to
address@hidden, but only if it is not already present there.
address@hidden defmac
+
address@hidden AC_LINK_FILES (@address@hidden, @address@hidden)
address@hidden
 This is an obsolete version of @code{AC_CONFIG_LINKS}
--
1.8.3.2


From 403e3d73c47231304124fc3bdaa619ed2f745695 Mon Sep 17 00:00:00 2001
From: Dale Visser <address@hidden>
Date: Wed, 8 Jan 2014 11:07:31 -0500
Subject: [PATCH 04/10] Figured out how to include AC_FLAGS_WARN_ALL in
 AC_PROG_CC w/o recursive expansion drama.

---
 lib/autoconf/c.m4    | 1 +
 lib/autoconf/lang.m4 | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 25780f9..b01c1f1 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -491,6 +491,7 @@ _AC_PROG_CC_C11([ac_prog_cc_stdc=c11
               [ac_prog_cc_stdc=no
                ac_cv_prog_cc_stdc=no])])])
 dnl
+AC_FLAGS_WARN_ALL
 AC_LANG_POP(C)dnl
 ])# AC_PROG_CC
 
diff --git a/lib/autoconf/lang.m4 b/lib/autoconf/lang.m4
index e17d70f..0c86b63 100644
--- a/lib/autoconf/lang.m4
+++ b/lib/autoconf/lang.m4
@@ -813,7 +813,7 @@ in "-warn all  % -warn all"   dnl Intel
    "-h conform % -h msglevel 2" dnl Cray C (Unicos)
    #
 do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
-   AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
+   _AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
                      [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
 done
 FLAGS="$ac_save_[]FLAGS"
--
1.8.3.2


From f02f187b1b118854ed0d66e5d421cb9287e5b391 Mon Sep 17 00:00:00 2001
From: Dale Visser <address@hidden>
Date: Wed, 8 Jan 2014 14:58:50 -0500
Subject: [PATCH 05/10] Pass any extra arguments to AC_FLAGS_WARN_ALL, e.g.,
 useful for turning off the warning flags.

---
 lib/autoconf/c.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index b01c1f1..bb2e414 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -491,7 +491,7 @@ _AC_PROG_CC_C11([ac_prog_cc_stdc=c11
               [ac_prog_cc_stdc=no
                ac_cv_prog_cc_stdc=no])])])
 dnl
-AC_FLAGS_WARN_ALL
+AC_FLAGS_WARN_ALL(m4_shift($@))
 AC_LANG_POP(C)dnl
 ])# AC_PROG_CC
 
--
1.8.3.2


From 705ca5d539f1bbbfad7d681c972d6b059da84c23 Mon Sep 17 00:00:00 2001
From: Dale Visser <address@hidden>
Date: Wed, 8 Jan 2014 15:52:40 -0500
Subject: [PATCH 06/10] Enabled warnings by default in AC_PROG_CXX.

---
 lib/autoconf/c.m4 | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index bb2e414..2c18463 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -733,6 +733,7 @@ _AC_PROG_CXX_CXX11([ac_prog_cxx_stdcxx=cxx11
                 ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98],
                [ac_prog_cxx_stdcxx=no
                 ac_cv_prog_cxx_stdcxx=no])])
+AC_FLAGS_WARN_ALL(m4_shift($@))
 AC_LANG_POP(C++)dnl
 ])# AC_PROG_CXX
 
--
1.8.3.2


From 4c9afb42c78fc149a1af498b71d3842f20df65c3 Mon Sep 17 00:00:00 2001
From: Dale Visser <address@hidden>
Date: Wed, 8 Jan 2014 16:14:54 -0500
Subject: [PATCH 07/10] Added warnings by default to AC_PROG_FC. Still need to
 test with warning-generating code, but so far verified warnings flag is
 actually added.

---
 lib/autoconf/fortran.m4 | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index f20b029..0dac562 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -387,6 +387,7 @@ if test $ac_compiler_gnu = yes; then
 else
   GFC=
 fi
+AC_FLAGS_WARN_ALL(m4_shift($@))
 AC_LANG_POP(Fortran)dnl
 ])# AC_PROG_FC
 
--
1.8.3.2


From 4f338859104cc5faa8755b448ecb629d9c0bae90 Mon Sep 17 00:00:00 2001
From: Dale Visser <address@hidden>
Date: Thu, 9 Jan 2014 09:33:23 -0500
Subject: [PATCH 08/10] Needed to do m4_shift2 for AC_PROG_FC case.

---
 lib/autoconf/fortran.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 0dac562..94ec01f 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -387,7 +387,7 @@ if test $ac_compiler_gnu = yes; then
 else
   GFC=
 fi
-AC_FLAGS_WARN_ALL(m4_shift($@))
+AC_FLAGS_WARN_ALL(m4_shift2($@))
 AC_LANG_POP(Fortran)dnl
 ])# AC_PROG_FC
 
--
1.8.3.2


From 0588622ada92c5b776829a507386d7355241361f Mon Sep 17 00:00:00 2001
From: Dale Visser <address@hidden>
Date: Thu, 9 Jan 2014 09:48:41 -0500
Subject: [PATCH 09/10] Documented parameter changes in AC_PROG_CC, AC_PROG_CXX
 and AC_PROG_FC.

---
 lib/autoconf/c.m4       | 16 ++++++++++++++--
 lib/autoconf/fortran.m4 |  8 +++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 2c18463..c018c92 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -424,11 +424,17 @@ AU_DEFUN([ac_cv_prog_gcc],
 [ac_cv_c_compiler_gnu])
 
 
-# AC_PROG_CC([COMPILER ...])
+# AC_PROG_CC([COMPILER ...], ...)
 # --------------------------
 # COMPILER ... is a space separated list of C compilers to search for.
 # This just gives the user an opportunity to specify an alternative
 # search list for the C compiler.
+# Any extra parameters will be passed on to AC_FLAGS_WARN_ALL. If there
+# are no extra parameters, then compiler warnings will be turned on. An
+# example of how to avoid this is invoking
+# AC_PROG_CC([COMPILER ...], [], [], [echo No extra warnings please.])
+# Where the final parameter is providing an alternate action to enabling
+# warning flags.
 AN_MAKEVAR([CC],  [AC_PROG_CC])
 AN_PROGRAM([cc],  [AC_PROG_CC])
 AN_PROGRAM([gcc], [AC_PROG_CC])
@@ -675,7 +681,7 @@ AU_DEFUN([ac_cv_prog_gxx],
 [ac_cv_cxx_compiler_gnu])
 
 
-# AC_PROG_CXX([LIST-OF-COMPILERS])
+# AC_PROG_CXX([LIST-OF-COMPILERS], ...)
 # --------------------------------
 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
 # for (if not specified, a default list is used).  This just gives the
@@ -687,6 +693,12 @@ AU_DEFUN([ac_cv_prog_gxx],
 # RCC    Rational C++
 # xlC_r    AIX C Set++ (with support for reentrant code)
 # xlC    AIX C Set++
+# Any extra parameters will be passed on to AC_FLAGS_WARN_ALL. If there
+# are no extra parameters, then compiler warnings will be turned on. An
+# example of how to avoid this is invoking
+# AC_PROG_CXX([LIST-OF-COMPILERS], [], [], [echo No extra warnings please.])
+# Where the final parameter is providing an alternate action to enabling
+# warning flags.
 AN_MAKEVAR([CXX],  [AC_PROG_CXX])
 AN_PROGRAM([CC],   [AC_PROG_CXX])
 AN_PROGRAM([c++],  [AC_PROG_CXX])
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 94ec01f..8280e48 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -371,10 +371,16 @@ AC_LANG_POP(Fortran 77)dnl
 ])# AC_PROG_F77
 
 
-# AC_PROG_FC([COMPILERS...], [DIALECT])
+# AC_PROG_FC([COMPILERS...], [DIALECT], ...)
 # -------------------------------------
 # COMPILERS is a space separated list of Fortran 77 compilers to search
 # for, and [DIALECT] is an optional dialect.  See also _AC_PROG_FC.
+# Any extra parameters will be passed on to AC_FLAGS_WARN_ALL. If there
+# are no extra parameters, then compiler warnings will be turned on. An
+# example of how to avoid this is invoking
+# AC_PROG_FC([COMPILERS...], [DIALECT], [], [], [echo No extra warnings please.])
+# Where the final parameter is providing an alternate action to enabling
+# warning flags.
 AC_DEFUN([AC_PROG_FC],
 [AC_LANG_PUSH(Fortran)dnl
 AC_ARG_VAR([FC],    [Fortran compiler command])dnl
--
1.8.3.2


From 7dc715abed03c77d59a28cd1ddaaa377356080fb Mon Sep 17 00:00:00 2001
From: Dale Visser <address@hidden>
Date: Thu, 9 Jan 2014 10:17:12 -0500
Subject: [PATCH 10/10] Added to documentation about new default behaviour, and
 how one restores the old behaviour.

---
 doc/autoconf.texi | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index b68d19d..87c70fb 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -7160,7 +7160,7 @@ makes this invalid.  That is why Autoconf stopped issuing
address@hidden table
 
address@hidden
address@hidden AC_PROG_CC (@ovar{compiler-search-list})
address@hidden AC_PROG_CC (@ovar{compiler-search-list}, @dots{})
address@hidden
address@hidden CC
address@hidden CFLAGS
@@ -7213,6 +7213,15 @@ other compilers.  If your package does not like this default, then it is
 acceptable to insert the line @samp{: address@hidden""@}} after @code{AC_INIT}
 and before @code{AC_PROG_CC} to select an empty default instead.
 
+Scan for common flags that enable compiler warnings. If found, append them
+to @code{CFLAGS}. To modify this behaviour, for example, to restore the old
+no-warning-flag behaviour, add parameters which will get shifted by 1,
+and passed on to @code{AC_FLAGS_WARN_ALL}.
+
address@hidden
+AC_PROG_CC([], [], [], [echo No warning flags please.])
address@hidden example
+
 Many Autoconf macros use a compiler, and thus call
address@hidden([AC_PROG_CC])} to ensure that the compiler has been
 determined before the body of the outermost @code{AC_DEFUN} macro.
@@ -7537,7 +7546,7 @@ compiler fix the header files automatically when installed.
address@hidden C++ Compiler Characteristics
 
 
address@hidden AC_PROG_CXX (@ovar{compiler-search-list})
address@hidden AC_PROG_CXX (@ovar{compiler-search-list}, @dots{})
address@hidden
address@hidden CXX
address@hidden CXXFLAGS
@@ -7599,6 +7608,16 @@ systems where G++ does not accept @option{-g}), or @option{-g} for other
 compilers.  If your package does not like this default, then it is
 acceptable to insert the line @samp{: address@hidden""@}} after @code{AC_INIT}
 and before @code{AC_PROG_CXX} to select an empty default instead.
+
+Scan for common flags that enable compiler warnings. If found, append them
+to @code{CXXFLAGS}. To modify this behaviour, for example, to restore the old
+no-warning-flag behaviour, add parameters which will get shifted by 1,
+and passed on to @code{AC_FLAGS_WARN_ALL}.
+
address@hidden
+AC_PROG_CXX([], [], [], [echo No warning flags please.])
address@hidden example
+
address@hidden defmac
 
address@hidden AC_PROG_CXXCPP
@@ -7825,7 +7844,7 @@ The result of the GNU test is cached in the
address@hidden variable.
address@hidden defmac
 
address@hidden AC_PROG_FC (@ovar{compiler-search-list}, @ovar{dialect})
address@hidden AC_PROG_FC (@ovar{compiler-search-list}, @ovar{dialect}, @dots{})
address@hidden
address@hidden FC
address@hidden FCFLAGS
@@ -7863,6 +7882,17 @@ set @code{FCFLAGS} to @option{-g} for all other Fortran compilers.
 The result of the GNU test is cached in the @code{ac_cv_fc_compiler_gnu}
 variable, acceptance of @option{-g} in the @code{ac_cv_prog_fc_g}
 variable.
+
+Scan for common flags that enable compiler warnings. If found, append them
+to @code{FCFLAGS}. To modify this behaviour, for example, to restore the old
+no-warning-flag behaviour, add parameters which will get shifted by 2,
+and passed on to @code{AC_FLAGS_WARN_ALL}.
+
address@hidden
+AC_PROG_FC([], [], [], [], [echo No warning flags please.])
address@hidden example
+
+
address@hidden defmac
 
address@hidden AC_PROG_F77_C_O
--
1.8.3.2


 




--
The plural of 'anecdote' is not 'data'.

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]