1
##### http://autoconf-archive.cryp.to/ax_cflags_gcc_option.html
5
# AX_CFLAGS_GCC_OPTION (optionflag [,[shellvar][,[A][,[NA]]])
9
# AX_CFLAGS_GCC_OPTION(-fvomit-frame) would show a message as like
10
# "checking CFLAGS for gcc -fvomit-frame ... yes" and adds the
11
# optionflag to CFLAGS if it is understood. You can override the
12
# shellvar-default of CFLAGS of course. The order of arguments stems
13
# from the explicit macros like AX_CFLAGS_WARN_ALL.
15
# The cousin AX_CXXFLAGS_GCC_OPTION would check for an option to add
16
# to CXXFLAGS - and it uses the autoconf setup for C++ instead of C
17
# (since it is possible to use different compilers for C and C++).
19
# The macro is a lot simpler than any special AX_CFLAGS_* macro (or
20
# ac_cxx_rtti.m4 macro) but allows to check for arbitrary options.
21
# However, if you use this macro in a few places, it would be great
22
# if you would make up a new function-macro and submit it to the
25
# - $1 option-to-check-for : required ("-option" as non-value)
26
# - $2 shell-variable-to-add-to : CFLAGS (or CXXFLAGS in the other case)
27
# - $3 action-if-found : add value to shellvariable
28
# - $4 action-if-not-found : nothing
30
# note: in earlier versions, $1-$2 were swapped. We try to detect the
31
# situation and accept a $2=~/-/ as being the old
32
# option-to-check-for.
34
# also: there are other variants that emerged from the original macro
35
# variant which did just test an option to be possibly added.
36
# However, some compilers accept an option silently, or possibly for
37
# just another option that was not intended. Therefore, we have to do
38
# a generic test for a compiler family. For gcc we check "-pedantic"
39
# being accepted which is also understood by compilers who just want
40
# to be compatible with gcc even when not being made from gcc
45
# AX_CFLAGS_SUN_OPTION AX_CFLAGS_HPUX_OPTION
46
# AX_CFLAGS_AIX_OPTION AX_CFLAGS_IRIX_OPTION
54
# Copyright (c) 2006 Guido U. Draheim <guidod@gmx.de>
56
# This program is free software; you can redistribute it and/or
57
# modify it under the terms of the GNU General Public License as
58
# published by the Free Software Foundation; either version 2 of the
59
# License, or (at your option) any later version.
61
# This program is distributed in the hope that it will be useful, but
62
# WITHOUT ANY WARRANTY; without even the implied warranty of
63
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
64
# General Public License for more details.
66
# You should have received a copy of the GNU General Public License
67
# along with this program; if not, write to the Free Software
68
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
71
# As a special exception, the respective Autoconf Macro's copyright
72
# owner gives unlimited permission to copy, distribute and modify the
73
# configure scripts that are the output of Autoconf when processing
74
# the Macro. You need not follow the terms of the GNU General Public
75
# License when using or distributing such scripts, even though
76
# portions of the text of the Macro appear in them. The GNU General
77
# Public License (GPL) does govern all other use of the material that
78
# constitutes the Autoconf Macro.
80
# This special exception to the GPL applies to versions of the
81
# Autoconf Macro released by the Autoconf Macro Archive. When you
82
# make and distribute a modified version of the Autoconf Macro, you
83
# may extend this special exception to the GPL to apply to your
84
# modified version as well.
86
AC_DEFUN([AX_CFLAGS_GCC_OPTION_OLD], [dnl
87
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
88
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$2])dnl
89
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
90
VAR,[VAR="no, unknown"
93
ac_save_[]FLAGS="$[]FLAGS"
95
in "-pedantic -Werror % m4_ifval($2,$2,-option)" dnl GCC
96
"-pedantic % m4_ifval($2,$2,-option) %% no, obsolete" dnl new GCC
98
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
99
AC_TRY_COMPILE([],[return 0;],
100
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
102
FLAGS="$ac_save_[]FLAGS"
106
.ok|.ok,*) m4_ifvaln($3,$3) ;;
107
.|.no|.no,*) m4_ifvaln($4,$4) ;;
109
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
110
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
111
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
112
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
115
AS_VAR_POPDEF([VAR])dnl
116
AS_VAR_POPDEF([FLAGS])dnl
120
dnl the only difference - the LANG selection... and the default FLAGS
122
AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_OLD], [dnl
123
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
124
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$2])dnl
125
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
126
VAR,[VAR="no, unknown"
129
ac_save_[]FLAGS="$[]FLAGS"
131
in "-pedantic -Werror % m4_ifval($2,$2,-option)" dnl GCC
132
"-pedantic % m4_ifval($2,$2,-option) %% no, obsolete" dnl new GCC
134
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
135
AC_TRY_COMPILE([],[return 0;],
136
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
138
FLAGS="$ac_save_[]FLAGS"
142
.ok|.ok,*) m4_ifvaln($3,$3) ;;
143
.|.no|.no,*) m4_ifvaln($4,$4) ;;
145
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
146
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
147
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
148
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
151
AS_VAR_POPDEF([VAR])dnl
152
AS_VAR_POPDEF([FLAGS])dnl
155
dnl -------------------------------------------------------------------------
157
AC_DEFUN([AX_CFLAGS_GCC_OPTION_NEW], [dnl
158
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
159
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$1])dnl
160
AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
161
VAR,[VAR="no, unknown"
164
ac_save_[]FLAGS="$[]FLAGS"
166
in "-pedantic -Werror % m4_ifval($1,$1,-option)" dnl GCC
167
"-pedantic % m4_ifval($1,$1,-option) %% no, obsolete" dnl new GCC
169
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
170
AC_TRY_COMPILE([],[return 0;],
171
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
173
FLAGS="$ac_save_[]FLAGS"
177
.ok|.ok,*) m4_ifvaln($3,$3) ;;
178
.|.no|.no,*) m4_ifvaln($4,$4) ;;
180
if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
181
then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
182
else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
183
m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
186
AS_VAR_POPDEF([VAR])dnl
187
AS_VAR_POPDEF([FLAGS])dnl
191
dnl the only difference - the LANG selection... and the default FLAGS
193
AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_NEW], [dnl
194
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
195
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$1])dnl
196
AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
197
VAR,[VAR="no, unknown"
200
ac_save_[]FLAGS="$[]FLAGS"
202
in "-pedantic -Werror % m4_ifval($1,$1,-option)" dnl GCC
203
"-pedantic % m4_ifval($1,$1,-option) %% no, obsolete" dnl new GCC
205
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
206
AC_TRY_COMPILE([],[return 0;],
207
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
209
FLAGS="$ac_save_[]FLAGS"
213
.ok|.ok,*) m4_ifvaln($3,$3) ;;
214
.|.no|.no,*) m4_ifvaln($4,$4) ;;
216
if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
217
then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
218
else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
219
m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
222
AS_VAR_POPDEF([VAR])dnl
223
AS_VAR_POPDEF([FLAGS])dnl
226
AC_DEFUN([AX_CFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
227
[AX_CFLAGS_GCC_OPTION_NEW($@)],[AX_CFLAGS_GCC_OPTION_OLD($@)])])
229
AC_DEFUN([AX_CXXFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
230
[AX_CXXFLAGS_GCC_OPTION_NEW($@)],[AX_CXXFLAGS_GCC_OPTION_OLD($@)])])