1dnl @synopsis AX_CFLAGS_GCC_OPTION (optionflag [,[shellvar][,[A][,[NA]]]) 2dnl 3dnl AX_CFLAGS_GCC_OPTION(-fvomit-frame) would show a message as like 4dnl "checking CFLAGS for gcc -fvomit-frame ... yes" and adds the 5dnl optionflag to CFLAGS if it is understood. You can override the 6dnl shellvar-default of CFLAGS of course. The order of arguments stems 7dnl from the explicit macros like AX_CFLAGS_WARN_ALL. 8dnl 9dnl The cousin AX_CXXFLAGS_GCC_OPTION would check for an option to add 10dnl to CXXFLAGS - and it uses the autoconf setup for C++ instead of C 11dnl (since it is possible to use different compilers for C and C++). 12dnl 13dnl The macro is a lot simpler than any special AX_CFLAGS_* macro (or 14dnl ac_cxx_rtti.m4 macro) but allows to check for arbitrary options. 15dnl However, if you use this macro in a few places, it would be great 16dnl if you would make up a new function-macro and submit it to the 17dnl ac-archive. 18dnl 19dnl - $1 option-to-check-for : required ("-option" as non-value) 20dnl - $2 shell-variable-to-add-to : CFLAGS (or CXXFLAGS in the other case) 21dnl - $3 action-if-found : add value to shellvariable 22dnl - $4 action-if-not-found : nothing 23dnl 24dnl note: in earlier versions, $1-$2 were swapped. We try to detect the 25dnl situation and accept a $2=~/-/ as being the old 26dnl option-to-check-for. 27dnl 28dnl also: there are other variants that emerged from the original macro 29dnl variant which did just test an option to be possibly added. 30dnl However, some compilers accept an option silently, or possibly for 31dnl just another option that was not intended. Therefore, we have to do 32dnl a generic test for a compiler family. For gcc we check "-pedantic" 33dnl being accepted which is also understood by compilers who just want 34dnl to be compatible with gcc even when not being made from gcc 35dnl sources. 36dnl 37dnl see also: 38dnl 39dnl AX_CFLAGS_SUN_OPTION AX_CFLAGS_HPUX_OPTION 40dnl AX_CFLAGS_AIX_OPTION AX_CFLAGS_IRIX_OPTION 41dnl 42dnl This descendent modified by Shannon Brown to use AC_LANG_CPLUSPLUS 43dnl instead of AC_LANG_CXX, as well as regexp([],[]) instead of 44dnl m4_regexp([],[]). 45dnl 46dnl @category C 47dnl @author Guido Draheim <guidod@gmx.de> 48dnl @version 2003-11-04 49dnl @license GPLWithACException 50 51AC_DEFUN([AX_CFLAGS_GCC_OPTION_OLD], [dnl 52AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl 53AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$2])dnl 54AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)], 55VAR,[VAR="no, unknown" 56 AC_LANG_SAVE 57 AC_LANG_C 58 ac_save_[]FLAGS="$[]FLAGS" 59for ac_arg dnl 60in "-pedantic % m4_ifval($2,$2,-option)" dnl GCC 61 # 62do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'` 63 AC_TRY_COMPILE([],[return 0;], 64 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break]) 65done 66 FLAGS="$ac_save_[]FLAGS" 67 AC_LANG_RESTORE 68]) 69case ".$VAR" in 70 .ok|.ok,*) m4_ifvaln($3,$3) ;; 71 .|.no|.no,*) m4_ifvaln($4,$4) ;; 72 *) m4_ifvaln($3,$3,[ 73 if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null 74 then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR]) 75 else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"]) 76 m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR" 77 fi ]) ;; 78esac 79AS_VAR_POPDEF([VAR])dnl 80AS_VAR_POPDEF([FLAGS])dnl 81]) 82 83 84dnl the only difference - the LANG selection... and the default FLAGS 85 86AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_OLD], [dnl 87AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl 88AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$2])dnl 89AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)], 90VAR,[VAR="no, unknown" 91 AC_LANG_SAVE 92 AC_LANG_CPLUSPLUS 93 ac_save_[]FLAGS="$[]FLAGS" 94for ac_arg dnl 95in "-pedantic % m4_ifval($2,$2,-option)" dnl GCC 96 # 97do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'` 98 AC_TRY_COMPILE([],[return 0;], 99 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break]) 100done 101 FLAGS="$ac_save_[]FLAGS" 102 AC_LANG_RESTORE 103]) 104case ".$VAR" in 105 .ok|.ok,*) m4_ifvaln($3,$3) ;; 106 .|.no|.no,*) m4_ifvaln($4,$4) ;; 107 *) m4_ifvaln($3,$3,[ 108 if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null 109 then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR]) 110 else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"]) 111 m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR" 112 fi ]) ;; 113esac 114AS_VAR_POPDEF([VAR])dnl 115AS_VAR_POPDEF([FLAGS])dnl 116]) 117 118dnl ------------------------------------------------------------------------- 119 120AC_DEFUN([AX_CFLAGS_GCC_OPTION_NEW], [dnl 121AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl 122AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$1])dnl 123AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)], 124VAR,[VAR="no, unknown" 125 AC_LANG_SAVE 126 AC_LANG_C 127 ac_save_[]FLAGS="$[]FLAGS" 128for ac_arg dnl 129in "-pedantic % m4_ifval($1,$1,-option)" dnl GCC 130 # 131do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'` 132 AC_TRY_COMPILE([],[return 0;], 133 [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break]) 134done 135 FLAGS="$ac_save_[]FLAGS" 136 AC_LANG_RESTORE 137]) 138case ".$VAR" in 139 .ok|.ok,*) m4_ifvaln($3,$3) ;; 140 .|.no|.no,*) m4_ifvaln($4,$4) ;; 141 *) m4_ifvaln($3,$3,[ 142 if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null 143 then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR]) 144 else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"]) 145 m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR" 146 fi ]) ;; 147esac 148AS_VAR_POPDEF([VAR])dnl 149AS_VAR_POPDEF([FLAGS])dnl 150]) 151 152 153dnl the only difference - the LANG selection... and the default FLAGS 154 155AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_NEW], [dnl 156AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl 157AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$1])dnl 158AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)], 159VAR,[VAR="no, unknown" 160 AC_LANG_SAVE 161 AC_LANG_CPLUSPLUS 162 ac_save_[]FLAGS="$[]FLAGS" 163for ac_arg dnl 164in "-pedantic % m4_ifval($1,$1,-option)" dnl GCC 165 # 166do 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]) 169done 170 FLAGS="$ac_save_[]FLAGS" 171 AC_LANG_RESTORE 172]) 173case ".$VAR" in 174 .ok|.ok,*) m4_ifvaln($3,$3) ;; 175 .|.no|.no,*) m4_ifvaln($4,$4) ;; 176 *) m4_ifvaln($3,$3,[ 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" 181 fi ]) ;; 182esac 183AS_VAR_POPDEF([VAR])dnl 184AS_VAR_POPDEF([FLAGS])dnl 185]) 186 187AC_DEFUN([AX_CFLAGS_GCC_OPTION],[ifelse(regexp([$2],[-]),-1, 188[AX_CFLAGS_GCC_OPTION_NEW($@)],[AX_CFLAGS_GCC_OPTION_OLD($@)])]) 189 190AC_DEFUN([AX_CXXFLAGS_GCC_OPTION],[ifelse(regexp([$2],[-]),-1, 191[AX_CXXFLAGS_GCC_OPTION_NEW($@)],[AX_CXXFLAGS_GCC_OPTION_OLD($@)])]) 192