You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
8.9 KiB

  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_cflags_gcc_option.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CFLAGS_GCC_OPTION (optionflag [,[shellvar][,[A][,[NA]]])
  8. #
  9. # DESCRIPTION
  10. #
  11. # AX_CFLAGS_GCC_OPTION(-fomit-frame-pointer) would show a message like
  12. # "checking CFLAGS for gcc -fomit-frame-pointer ... yes" and add the
  13. # optionflag to CFLAGS if it is understood. You can override the
  14. # shellvar-default of CFLAGS of course. The order of arguments stems from
  15. # the explicit macros like AX_CFLAGS_WARN_ALL.
  16. #
  17. # The cousin AX_CXXFLAGS_GCC_OPTION would check for an option to add to
  18. # CXXFLAGS - and it uses the autoconf setup for C++ instead of C (since it
  19. # is possible to use different compilers for C and C++).
  20. #
  21. # The macro is a lot simpler than any special AX_CFLAGS_* macro (or
  22. # ax_cxx_rtti.m4 macro) but allows to check for arbitrary options.
  23. # However, if you use this macro in a few places, it would be great if you
  24. # would make up a new function-macro and submit it to the ac-archive.
  25. #
  26. # - $1 option-to-check-for : required ("-option" as non-value)
  27. # - $2 shell-variable-to-add-to : CFLAGS (or CXXFLAGS in the other case)
  28. # - $3 action-if-found : add value to shellvariable
  29. # - $4 action-if-not-found : nothing
  30. #
  31. # Note: in earlier versions, $1-$2 were swapped. We try to detect the
  32. # situation and accept a $2=~/-/ as being the old option-to-check-for.
  33. #
  34. # There are other variants that emerged from the original macro variant
  35. # which did just test an option to be possibly added. However, some
  36. # compilers accept an option silently, or possibly for just another option
  37. # that was not intended. Therefore, we have to do a generic test for a
  38. # compiler family. For gcc we check "-pedantic" being accepted which is
  39. # also understood by compilers who just want to be compatible with gcc
  40. # even when not being made from gcc sources.
  41. #
  42. # See also: AX_CFLAGS_SUN_OPTION, AX_CFLAGS_HPUX_OPTION,
  43. # AX_CFLAGS_AIX_OPTION, and AX_CFLAGS_IRIX_OPTION.
  44. #
  45. # LICENSE
  46. #
  47. # Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
  48. #
  49. # This program is free software; you can redistribute it and/or modify it
  50. # under the terms of the GNU General Public License as published by the
  51. # Free Software Foundation; either version 2 of the License, or (at your
  52. # option) any later version.
  53. #
  54. # This program is distributed in the hope that it will be useful, but
  55. # WITHOUT ANY WARRANTY; without even the implied warranty of
  56. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  57. # Public License for more details.
  58. #
  59. # You should have received a copy of the GNU General Public License along
  60. # with this program. If not, see <http://www.gnu.org/licenses/>.
  61. #
  62. # As a special exception, the respective Autoconf Macro's copyright owner
  63. # gives unlimited permission to copy, distribute and modify the configure
  64. # scripts that are the output of Autoconf when processing the Macro. You
  65. # need not follow the terms of the GNU General Public License when using
  66. # or distributing such scripts, even though portions of the text of the
  67. # Macro appear in them. The GNU General Public License (GPL) does govern
  68. # all other use of the material that constitutes the Autoconf Macro.
  69. #
  70. # This special exception to the GPL applies to versions of the Autoconf
  71. # Macro released by the Autoconf Archive. When you make and distribute a
  72. # modified version of the Autoconf Macro, you may extend this special
  73. # exception to the GPL to apply to your modified version as well.
  74. #serial 12
  75. AC_DEFUN([AX_CFLAGS_GCC_OPTION_OLD], [dnl
  76. AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
  77. AS_VAR_PUSHDEF([VAR],[ax_cv_cflags_gcc_option_$2])dnl
  78. AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
  79. VAR,[AS_VAR_SET([VAR],["no, unknown"])
  80. AC_LANG_SAVE
  81. AC_LANG_C
  82. ac_save_[]FLAGS="$[]FLAGS"
  83. for ac_arg dnl
  84. in "-pedantic -Werror % m4_ifval($2,$2,-option)" dnl GCC
  85. "-pedantic % m4_ifval($2,$2,-option) %% no, obsolete" dnl new GCC
  86. #
  87. do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
  88. AC_TRY_COMPILE([],[return 0;],
  89. [AS_VAR_SET([VAR],[`echo $ac_arg | sed -e 's,.*% *,,'`]); break])
  90. done
  91. FLAGS="$ac_save_[]FLAGS"
  92. AC_LANG_RESTORE
  93. ])
  94. m4_ifdef([AS_VAR_COPY],[AS_VAR_COPY([var],[VAR])],[var=AS_VAR_GET([VAR])])
  95. case ".$var" in
  96. .ok|.ok,*) m4_ifvaln($3,$3) ;;
  97. .|.no|.no,*) m4_ifvaln($4,$4) ;;
  98. *) m4_ifvaln($3,$3,[
  99. if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $var " 2>&1 >/dev/null
  100. then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $var])
  101. else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $var"])
  102. m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $var"
  103. fi ]) ;;
  104. esac
  105. AS_VAR_POPDEF([VAR])dnl
  106. AS_VAR_POPDEF([FLAGS])dnl
  107. ])
  108. dnl the only difference - the LANG selection... and the default FLAGS
  109. AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_OLD], [dnl
  110. AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
  111. AS_VAR_PUSHDEF([VAR],[ax_cv_cxxflags_gcc_option_$2])dnl
  112. AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
  113. VAR,[AS_VAR_SET([VAR],["no, unknown"])
  114. AC_LANG_SAVE
  115. AC_LANG_CPLUSPLUS
  116. ac_save_[]FLAGS="$[]FLAGS"
  117. for ac_arg dnl
  118. in "-pedantic -Werror % m4_ifval($2,$2,-option)" dnl GCC
  119. "-pedantic % m4_ifval($2,$2,-option) %% no, obsolete" dnl new GCC
  120. #
  121. do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
  122. AC_TRY_COMPILE([],[return 0;],
  123. [AS_VAR_SET([VAR],[`echo $ac_arg | sed -e 's,.*% *,,'`]); break])
  124. done
  125. FLAGS="$ac_save_[]FLAGS"
  126. AC_LANG_RESTORE
  127. ])
  128. m4_ifdef([AS_VAR_COPY],[AS_VAR_COPY([var],[VAR])],[var=AS_VAR_GET([VAR])])
  129. case ".$var" in
  130. .ok|.ok,*) m4_ifvaln($3,$3) ;;
  131. .|.no|.no,*) m4_ifvaln($4,$4) ;;
  132. *) m4_ifvaln($3,$3,[
  133. if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $var " 2>&1 >/dev/null
  134. then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $var])
  135. else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $var"])
  136. m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $var"
  137. fi ]) ;;
  138. esac
  139. AS_VAR_POPDEF([VAR])dnl
  140. AS_VAR_POPDEF([FLAGS])dnl
  141. ])
  142. dnl -------------------------------------------------------------------------
  143. AC_DEFUN([AX_CFLAGS_GCC_OPTION_NEW], [dnl
  144. AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
  145. AS_VAR_PUSHDEF([VAR],[ax_cv_cflags_gcc_option_$1])dnl
  146. AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
  147. VAR,[AS_VAR_SET([VAR],["no, unknown"])
  148. AC_LANG_SAVE
  149. AC_LANG_C
  150. ac_save_[]FLAGS="$[]FLAGS"
  151. for ac_arg dnl
  152. in "-pedantic -Werror % m4_ifval($1,$1,-option)" dnl GCC
  153. "-pedantic % m4_ifval($1,$1,-option) %% no, obsolete" dnl new GCC
  154. #
  155. do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
  156. AC_TRY_COMPILE([],[return 0;],
  157. [AS_VAR_SET([VAR],[`echo $ac_arg | sed -e 's,.*% *,,'`]); break])
  158. done
  159. FLAGS="$ac_save_[]FLAGS"
  160. AC_LANG_RESTORE
  161. ])
  162. m4_ifdef([AS_VAR_COPY],[AS_VAR_COPY([var],[VAR])],[var=AS_VAR_GET([VAR])])
  163. case ".$var" in
  164. .ok|.ok,*) m4_ifvaln($3,$3) ;;
  165. .|.no|.no,*) m4_ifvaln($4,$4) ;;
  166. *) m4_ifvaln($3,$3,[
  167. if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $var " 2>&1 >/dev/null
  168. then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $var])
  169. else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $var"])
  170. m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $var"
  171. fi ]) ;;
  172. esac
  173. AS_VAR_POPDEF([VAR])dnl
  174. AS_VAR_POPDEF([FLAGS])dnl
  175. ])
  176. dnl the only difference - the LANG selection... and the default FLAGS
  177. AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_NEW], [dnl
  178. AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
  179. AS_VAR_PUSHDEF([VAR],[ax_cv_cxxflags_gcc_option_$1])dnl
  180. AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
  181. VAR,[AS_VAR_SET([VAR],["no, unknown"])
  182. AC_LANG_SAVE
  183. AC_LANG_CPLUSPLUS
  184. ac_save_[]FLAGS="$[]FLAGS"
  185. for ac_arg dnl
  186. in "-pedantic -Werror % m4_ifval($1,$1,-option)" dnl GCC
  187. "-pedantic % m4_ifval($1,$1,-option) %% no, obsolete" dnl new GCC
  188. #
  189. do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
  190. AC_TRY_COMPILE([],[return 0;],
  191. [AS_VAR_SET([VAR],[`echo $ac_arg | sed -e 's,.*% *,,'`]); break])
  192. done
  193. FLAGS="$ac_save_[]FLAGS"
  194. AC_LANG_RESTORE
  195. ])
  196. m4_ifdef([AS_VAR_COPY],[AS_VAR_COPY([var],[VAR])],[var=AS_VAR_GET([VAR])])
  197. case ".$var" in
  198. .ok|.ok,*) m4_ifvaln($3,$3) ;;
  199. .|.no|.no,*) m4_ifvaln($4,$4) ;;
  200. *) m4_ifvaln($3,$3,[
  201. if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $var " 2>&1 >/dev/null
  202. then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $var])
  203. else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $var"])
  204. m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $var"
  205. fi ]) ;;
  206. esac
  207. AS_VAR_POPDEF([VAR])dnl
  208. AS_VAR_POPDEF([FLAGS])dnl
  209. ])
  210. AC_DEFUN([AX_CFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
  211. [AX_CFLAGS_GCC_OPTION_NEW($@)],[AX_CFLAGS_GCC_OPTION_OLD($@)])])
  212. AC_DEFUN([AX_CXXFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
  213. [AX_CXXFLAGS_GCC_OPTION_NEW($@)],[AX_CXXFLAGS_GCC_OPTION_OLD($@)])])