source: m4/ax_cflags_warn_all.m4 @ 7803326

release-1.8release-1.9
Last change on this file since 7803326 was 378ede7, checked in by Anders Kaseorg <andersk@mit.edu>, 10 years ago
Update autoconf macros from autoconf-archive Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 8.1 KB
Line 
1# ===========================================================================
2#    http://www.gnu.org/software/autoconf-archive/ax_cflags_warn_all.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_CFLAGS_WARN_ALL   [(shellvar [,default, [A/NA]])]
8#   AX_CXXFLAGS_WARN_ALL [(shellvar [,default, [A/NA]])]
9#   AX_FCFLAGS_WARN_ALL  [(shellvar [,default, [A/NA]])]
10#
11# DESCRIPTION
12#
13#   Try to find a compiler option that enables most reasonable warnings.
14#
15#   For the GNU compiler it will be -Wall (and -ansi -pedantic) The result
16#   is added to the shellvar being CFLAGS, CXXFLAGS, or FCFLAGS by default.
17#
18#   Currently this macro knows about the GCC, Solaris, Digital Unix, AIX,
19#   HP-UX, IRIX, NEC SX-5 (Super-UX 10), Cray J90 (Unicos 10.0.0.8), and
20#   Intel compilers.  For a given compiler, the Fortran flags are much more
21#   experimental than their C equivalents.
22#
23#    - $1 shell-variable-to-add-to : CFLAGS, CXXFLAGS, or FCFLAGS
24#    - $2 add-value-if-not-found : nothing
25#    - $3 action-if-found : add value to shellvariable
26#    - $4 action-if-not-found : nothing
27#
28# LICENSE
29#
30#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
31#   Copyright (c) 2010 Rhys Ulerich <rhys.ulerich@gmail.com>
32#
33#   This program is free software; you can redistribute it and/or modify it
34#   under the terms of the GNU General Public License as published by the
35#   Free Software Foundation; either version 3 of the License, or (at your
36#   option) any later version.
37#
38#   This program is distributed in the hope that it will be useful, but
39#   WITHOUT ANY WARRANTY; without even the implied warranty of
40#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
41#   Public License for more details.
42#
43#   You should have received a copy of the GNU General Public License along
44#   with this program. If not, see <http://www.gnu.org/licenses/>.
45#
46#   As a special exception, the respective Autoconf Macro's copyright owner
47#   gives unlimited permission to copy, distribute and modify the configure
48#   scripts that are the output of Autoconf when processing the Macro. You
49#   need not follow the terms of the GNU General Public License when using
50#   or distributing such scripts, even though portions of the text of the
51#   Macro appear in them. The GNU General Public License (GPL) does govern
52#   all other use of the material that constitutes the Autoconf Macro.
53#
54#   This special exception to the GPL applies to versions of the Autoconf
55#   Macro released by the Autoconf Archive. When you make and distribute a
56#   modified version of the Autoconf Macro, you may extend this special
57#   exception to the GPL to apply to your modified version as well.
58
59#serial 10
60
61AC_DEFUN([AX_CFLAGS_WARN_ALL],[dnl
62AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
63AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_warn_all])dnl
64AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
65VAR,[VAR="no, unknown"
66 AC_LANG_PUSH([C])
67 ac_save_[]FLAGS="$[]FLAGS"
68for ac_arg dnl
69in "-pedantic  % -Wall"       dnl   GCC
70   "-xstrconst % -v"          dnl Solaris C
71   "-std1      % -verbose -w0 -warnprotos" dnl Digital Unix
72   "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
73   "-ansi -ansiE % -fullwarn" dnl IRIX
74   "+ESlit     % +w1"         dnl HP-UX C
75   "-Xc        % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
76   "-h conform % -h msglevel 2" dnl Cray C (Unicos)
77   #
78do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
79   AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
80                     [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
81done
82 FLAGS="$ac_save_[]FLAGS"
83 AC_LANG_POP([C])
84])
85case ".$VAR" in
86     .ok|.ok,*) m4_ifvaln($3,$3) ;;
87   .|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
88        AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
89                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
90   *) m4_ifvaln($3,$3,[
91   if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
92   then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
93   else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
94                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
95   fi ]) ;;
96esac
97AS_VAR_POPDEF([VAR])dnl
98AS_VAR_POPDEF([FLAGS])dnl
99])
100
101dnl the only difference - the LANG selection... and the default FLAGS
102
103AC_DEFUN([AX_CXXFLAGS_WARN_ALL],[dnl
104AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
105AS_VAR_PUSHDEF([VAR],[ax_cv_cxxflags_warn_all])dnl
106AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
107VAR,[VAR="no, unknown"
108 AC_LANG_PUSH([C++])
109 ac_save_[]FLAGS="$[]FLAGS"
110for ac_arg dnl
111in "-pedantic  % -Wall"       dnl   GCC
112   "-xstrconst % -v"          dnl Solaris C
113   "-std1      % -verbose -w0 -warnprotos" dnl Digital Unix
114   "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
115   "-ansi -ansiE % -fullwarn" dnl IRIX
116   "+ESlit     % +w1"         dnl HP-UX C
117   "-Xc        % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
118   "-h conform % -h msglevel 2" dnl Cray C (Unicos)
119   #
120do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
121   AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
122                     [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
123done
124 FLAGS="$ac_save_[]FLAGS"
125 AC_LANG_POP([C++])
126])
127case ".$VAR" in
128     .ok|.ok,*) m4_ifvaln($3,$3) ;;
129   .|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
130        AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
131                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
132   *) m4_ifvaln($3,$3,[
133   if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
134   then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
135   else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
136                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
137   fi ]) ;;
138esac
139AS_VAR_POPDEF([VAR])dnl
140AS_VAR_POPDEF([FLAGS])dnl
141])
142
143dnl the only difference - the LANG selection... and the default FLAGS
144
145AC_DEFUN([AX_FCFLAGS_WARN_ALL],[dnl
146AS_VAR_PUSHDEF([FLAGS],[FCFLAGS])dnl
147AS_VAR_PUSHDEF([VAR],[ax_cv_fcflags_warn_all])dnl
148AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum warnings],
149VAR,[VAR="no, unknown"
150 AC_LANG_PUSH([Fortran])
151 ac_save_[]FLAGS="$[]FLAGS"
152for ac_arg dnl
153in "-warn all  % -warn all"   dnl Intel
154   "-pedantic  % -Wall"       dnl GCC
155   "-xstrconst % -v"          dnl Solaris C
156   "-std1      % -verbose -w0 -warnprotos" dnl Digital Unix
157   "-qlanglvl=ansi % -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
158   "-ansi -ansiE % -fullwarn" dnl IRIX
159   "+ESlit     % +w1"         dnl HP-UX C
160   "-Xc        % -pvctl[,]fullmsg" dnl NEC SX-5 (Super-UX 10)
161   "-h conform % -h msglevel 2" dnl Cray C (Unicos)
162   #
163do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
164   AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
165                     [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
166done
167 FLAGS="$ac_save_[]FLAGS"
168 AC_LANG_POP([Fortran])
169])
170case ".$VAR" in
171     .ok|.ok,*) m4_ifvaln($3,$3) ;;
172   .|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
173        AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
174                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
175   *) m4_ifvaln($3,$3,[
176   if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
177   then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
178   else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
179                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
180   fi ]) ;;
181esac
182AS_VAR_POPDEF([VAR])dnl
183AS_VAR_POPDEF([FLAGS])dnl
184])
185
186dnl  implementation tactics:
187dnl   the for-argument contains a list of options. The first part of
188dnl   these does only exist to detect the compiler - usually it is
189dnl   a global option to enable -ansi or -extrawarnings. All other
190dnl   compilers will fail about it. That was needed since a lot of
191dnl   compilers will give false positives for some option-syntax
192dnl   like -Woption or -Xoption as they think of it is a pass-through
193dnl   to later compile stages or something. The "%" is used as a
194dnl   delimiter. A non-option comment can be given after "%%" marks
195dnl   which will be shown but not added to the respective C/CXXFLAGS.
Note: See TracBrowser for help on using the repository browser.