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
5 dnl the optionflag to CFLAGS if it is understood. You can override
6 dnl the shellvar-default of CFLAGS of course. The order of arguments
7 dnl stems from the explicit macros like AX_CFLAGS_WARN_ALL.
9 dnl The macro is a lot simpler than any special AX_CFLAGS_* macro (or
10 dnl ac_cxx_rtti.m4 macro) but allows to check for arbitrary options.
11 dnl However, if you use this macro in a few places, it would be great
12 dnl if you would make up a new function-macro and submit it to the
15 dnl - $1 option-to-check-for : required ("-option" as non-value)
16 dnl - $2 shell-variable-to-add-to : CFLAGS
17 dnl - $3 action-if-found : add value to shellvariable
18 dnl - $4 action-if-not-found : nothing
20 dnl note: in earlier versions, $1-$2 were swapped. We try to detect the
21 dnl situation and accept a $2=~/-/ as being the old option-to-check-for.
23 dnl also: there are other variants that emerged from the original macro
24 dnl variant which did just test an option to be possibly added. However,
25 dnl some compilers accept an option silently, or possibly for just
26 dnl another option that was not intended. Therefore, we have to do a
27 dnl generic test for a compiler family. For gcc we check "-pedantic"
28 dnl being accepted which is also understood by compilers who just want
29 dnl to be compatible with gcc even when not being made from gcc sources.
32 dnl AX_CFLAGS_SUN_OPTION AX_CFLAGS_HPUX_OPTION
33 dnl AX_CFLAGS_AIX_OPTION AX_CFLAGS_IRIX_OPTION
35 dnl @, tested, experimental
36 dnl @version $Id: ax_cflags_gcc_option.m4,v 1.5 2003/11/29 08:13:25 guidod Exp $
37 dnl @author Guido Draheim <guidod@gmx.de>
38 dnl http://ac-archive.sourceforge.net/C_Support/ax_cflags_gcc_option.m4
40 AC_DEFUN([AX_CFLAGS_GCC_OPTION_OLD], [dnl
41 AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
42 AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$2])dnl
43 AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
44 VAR,[VAR="no, unknown"
47 ac_save_[]FLAGS="$[]FLAGS"
49 in "-pedantic % m4_ifval($2,$2,-option)" dnl GCC
51 do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
52 AC_TRY_COMPILE([],[return 0;],
53 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
55 FLAGS="$ac_save_[]FLAGS"
59 .ok|.ok,*) m4_ifvaln($3,$3) ;;
60 .|.no|.no,*) m4_ifvaln($4,$4) ;;
62 if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
63 then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
64 else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
65 m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
68 AS_VAR_POPDEF([VAR])dnl
69 AS_VAR_POPDEF([FLAGS])dnl
73 dnl -------------------------------------------------------------------------
75 AC_DEFUN([AX_CFLAGS_GCC_OPTION_NEW], [dnl
76 AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
77 AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$1])dnl
78 AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
79 VAR,[VAR="no, unknown"
82 ac_save_[]FLAGS="$[]FLAGS"
84 in "-pedantic % m4_ifval($1,$1,-option)" dnl GCC
86 do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
87 AC_TRY_COMPILE([],[return 0;],
88 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
90 FLAGS="$ac_save_[]FLAGS"
94 .ok|.ok,*) m4_ifvaln($3,$3) ;;
95 .|.no|.no,*) m4_ifvaln($4,$4) ;;
97 if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
98 then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
99 else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
100 m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
103 AS_VAR_POPDEF([VAR])dnl
104 AS_VAR_POPDEF([FLAGS])dnl
108 AC_DEFUN([AX_CFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
109 [AX_CFLAGS_GCC_OPTION_NEW($@)],[AX_CFLAGS_GCC_OPTION_OLD($@)])])