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