1 dnl @synopsis AX_CFLAGS_GCC_OPTION (optionflag [,[shellvar][,[A][,[NA]]])
3 dnl AX_CFLAGS_GCC_OPTION(-fvomit-frame) would show a message as like
4 dnl "checking CFLAGS for gcc -fvomit-frame ... yes" and adds the
5 dnl optionflag to CFLAGS if it is understood. You can override the
6 dnl shellvar-default of CFLAGS of course. The order of arguments stems
7 dnl from the explicit macros like AX_CFLAGS_WARN_ALL.
9 dnl The cousin AX_CXXFLAGS_GCC_OPTION would check for an option to add
10 dnl to CXXFLAGS - and it uses the autoconf setup for C++ instead of C
11 dnl (since it is possible to use different compilers for C and C++).
13 dnl The macro is a lot simpler than any special AX_CFLAGS_* macro (or
14 dnl ac_cxx_rtti.m4 macro) but allows to check for arbitrary options.
15 dnl However, if you use this macro in a few places, it would be great
16 dnl if you would make up a new function-macro and submit it to the
19 dnl - $1 option-to-check-for : required ("-option" as non-value)
20 dnl - $2 shell-variable-to-add-to : CFLAGS (or CXXFLAGS in the other case)
21 dnl - $3 action-if-found : add value to shellvariable
22 dnl - $4 action-if-not-found : nothing
24 dnl note: in earlier versions, $1-$2 were swapped. We try to detect the
25 dnl situation and accept a $2=~/-/ as being the old
26 dnl option-to-check-for.
28 dnl also: there are other variants that emerged from the original macro
29 dnl variant which did just test an option to be possibly added.
30 dnl However, some compilers accept an option silently, or possibly for
31 dnl just another option that was not intended. Therefore, we have to do
32 dnl a generic test for a compiler family. For gcc we check "-pedantic"
33 dnl being accepted which is also understood by compilers who just want
34 dnl to be compatible with gcc even when not being made from gcc
39 dnl AX_CFLAGS_SUN_OPTION AX_CFLAGS_HPUX_OPTION
40 dnl AX_CFLAGS_AIX_OPTION AX_CFLAGS_IRIX_OPTION
43 dnl @author Guido U. Draheim <guidod@gmx.de>
44 dnl @version 2006-12-12
45 dnl @license GPLWithACException
47 AC_DEFUN([AX_CFLAGS_GCC_OPTION_OLD], [dnl
48 AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
49 AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$2])dnl
50 AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
51 VAR,[VAR="no, unknown"
54 ac_save_[]FLAGS="$[]FLAGS"
56 in "-pedantic -Werror % m4_ifval($2,$2,-option)" dnl GCC
57 "-pedantic % m4_ifval($2,$2,-option) %% no, obsolete" dnl new GCC
59 do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
60 AC_TRY_COMPILE([],[return 0;],
61 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
63 FLAGS="$ac_save_[]FLAGS"
67 .ok|.ok,*) m4_ifvaln($3,$3) ;;
68 .|.no|.no,*) m4_ifvaln($4,$4) ;;
70 if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
71 then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
72 else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
73 m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
76 AS_VAR_POPDEF([VAR])dnl
77 AS_VAR_POPDEF([FLAGS])dnl
81 dnl the only difference - the LANG selection... and the default FLAGS
83 AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_OLD], [dnl
84 AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
85 AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$2])dnl
86 AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
87 VAR,[VAR="no, unknown"
90 ac_save_[]FLAGS="$[]FLAGS"
92 in "-pedantic -Werror % m4_ifval($2,$2,-option)" dnl GCC
93 "-pedantic % m4_ifval($2,$2,-option) %% no, obsolete" dnl new GCC
95 do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
96 AC_TRY_COMPILE([],[return 0;],
97 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
99 FLAGS="$ac_save_[]FLAGS"
103 .ok|.ok,*) m4_ifvaln($3,$3) ;;
104 .|.no|.no,*) m4_ifvaln($4,$4) ;;
106 if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
107 then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
108 else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
109 m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
112 AS_VAR_POPDEF([VAR])dnl
113 AS_VAR_POPDEF([FLAGS])dnl
116 dnl -------------------------------------------------------------------------
118 AC_DEFUN([AX_CFLAGS_GCC_OPTION_NEW], [dnl
119 AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
120 AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$1])dnl
121 AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
122 VAR,[VAR="no, unknown"
125 ac_save_[]FLAGS="$[]FLAGS"
127 in "-pedantic -Werror % m4_ifval($1,$1,-option)" dnl GCC
128 "-pedantic % m4_ifval($1,$1,-option) %% no, obsolete" dnl new GCC
130 do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
131 AC_TRY_COMPILE([],[return 0;],
132 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
134 FLAGS="$ac_save_[]FLAGS"
138 .ok|.ok,*) m4_ifvaln($3,$3) ;;
139 .|.no|.no,*) m4_ifvaln($4,$4) ;;
141 if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
142 then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
143 else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
144 m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
147 AS_VAR_POPDEF([VAR])dnl
148 AS_VAR_POPDEF([FLAGS])dnl
152 dnl the only difference - the LANG selection... and the default FLAGS
154 AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_NEW], [dnl
155 AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
156 AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$1])dnl
157 AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
158 VAR,[VAR="no, unknown"
161 ac_save_[]FLAGS="$[]FLAGS"
163 in "-pedantic -Werror % m4_ifval($1,$1,-option)" dnl GCC
164 "-pedantic % m4_ifval($1,$1,-option) %% no, obsolete" dnl new GCC
166 do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
167 AC_TRY_COMPILE([],[return 0;],
168 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
170 FLAGS="$ac_save_[]FLAGS"
174 .ok|.ok,*) m4_ifvaln($3,$3) ;;
175 .|.no|.no,*) m4_ifvaln($4,$4) ;;
177 if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
178 then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
179 else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
180 m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
183 AS_VAR_POPDEF([VAR])dnl
184 AS_VAR_POPDEF([FLAGS])dnl
187 AC_DEFUN([AX_CFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
188 [AX_CFLAGS_GCC_OPTION_NEW($@)],[AX_CFLAGS_GCC_OPTION_OLD($@)])])
190 AC_DEFUN([AX_CXXFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
191 [AX_CXXFLAGS_GCC_OPTION_NEW($@)],[AX_CXXFLAGS_GCC_OPTION_OLD($@)])])