source: m4/ax_check_flag.m4 @ 3234121

release-1.10release-1.8release-1.9
Last change on this file since 3234121 was 82e93c9, checked in by Anders Kaseorg <andersk@mit.edu>, 13 years ago
AX_CHECK_FLAG: Fix to work with autoconf 2.59 • AS_VAR_PUSHDEF([FLAGS], [something containing FLAGS]) caused an infinite loop before v2.65~21. • AS_VAR_APPEND was new in v2.63b~224. • AS_VAR_IF was new in v2.63~27. • AS_ECHO was new in AUTOCONF-2.61a~45, and AC_PROG_GREP in AUTOCONF-2.59c~744, but their use here is more idiomatically replaced with a case pattern anyway. • Before AUTOCONF-2.60b~8, the variable name passed to AC_CACHE_CHECK, AS_VAR_GET, AS_VAR_SET, and AS_VAR_SET_IF must be left unquoted. Signed-off-by: Anders Kaseorg <andersk@mit.edu> (cherry picked from autoconf-archive commit f5ed01f0ce1d9b3be7c0cd92db192bf5c44d7fcb)
  • Property mode set to 100644
File size: 6.0 KB
Line 
1# ===========================================================================
2#       http://www.gnu.org/software/autoconf-archive/ax_check_flag.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_CHECK_PREPROC_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS])
8#   AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS])
9#   AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS])
10#   AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE])
11#   AX_APPEND_COMPILE_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS])
12#   AX_APPEND_LINK_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS])
13#
14# DESCRIPTION
15#
16#   Check whether the given FLAG works with the current language's
17#   preprocessor/compiler/linker, or whether they give an error. (Warnings,
18#   however, are ignored.)
19#
20#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
21#   success/failure.
22#
23#   If EXTRA-FLAGS is defined, it is added to the current language's default
24#   flags (e.g.  CFLAGS) when the check is done.  The check us thus made
25#   with the following flags: "CFLAGS EXTRA-FLAGS FLAG".  EXTRA-FLAGS can
26#   for example be used to force the compiler to issue an error when a bad
27#   flag is given.
28#
29#   AX_APPEND_FLAG appends the FLAG to the FLAG-VARIABLE shell variable or
30#   the current language's flags if not specified.  FLAG is not added to
31#   FLAG-VARIABLE if it is already in the shell variable.
32#
33#   AX_APPEND_COMPILE_FLAGS checks for each FLAG1, FLAG2, etc. using
34#   AX_CHECK_COMPILE_FLAG and if the check is successful the flag is added
35#   to the appropriate FLAGS variable with AX_APPEND_FLAG.  The
36#   FLAGS-VARIABLE and EXTRA-FLAGS arguments are the same as in the other
37#   macros. AX_APPEND_LINK_FLAGS does the same for linker flags.
38#
39#   NOTE: Based on AX_CHECK_COMPILER_FLAGS and AX_CFLAGS_GCC_OPTION.
40#
41# LICENSE
42#
43#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
44#   Copyright (c) 2009 Steven G. Johnson <stevenj@alum.mit.edu>
45#   Copyright (c) 2009 Matteo Frigo
46#   Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
47#
48#   This program is free software: you can redistribute it and/or modify it
49#   under the terms of the GNU General Public License as published by the
50#   Free Software Foundation, either version 3 of the License, or (at your
51#   option) any later version.
52#
53#   This program is distributed in the hope that it will be useful, but
54#   WITHOUT ANY WARRANTY; without even the implied warranty of
55#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
56#   Public License for more details.
57#
58#   You should have received a copy of the GNU General Public License along
59#   with this program. If not, see <http://www.gnu.org/licenses/>.
60#
61#   As a special exception, the respective Autoconf Macro's copyright owner
62#   gives unlimited permission to copy, distribute and modify the configure
63#   scripts that are the output of Autoconf when processing the Macro. You
64#   need not follow the terms of the GNU General Public License when using
65#   or distributing such scripts, even though portions of the text of the
66#   Macro appear in them. The GNU General Public License (GPL) does govern
67#   all other use of the material that constitutes the Autoconf Macro.
68#
69#   This special exception to the GPL applies to versions of the Autoconf
70#   Macro released by the Autoconf Archive. When you make and distribute a
71#   modified version of the Autoconf Macro, you may extend this special
72#   exception to the GPL to apply to your modified version as well.
73
74#serial 3
75
76AC_DEFUN([AX_CHECK_PREPROC_FLAG],
77[AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX
78AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]cppflags_$4_$1])dnl
79AC_CACHE_CHECK([whether _AC_LANG preprocessor accepts $1], CACHEVAR, [
80  ax_check_save_flags=$CPPFLAGS
81  CPPFLAGS="$CPPFLAGS $4 $1"
82  AC_PREPROC_IFELSE([AC_LANG_PROGRAM()],
83    [AS_VAR_SET(CACHEVAR,[yes])],
84    [AS_VAR_SET(CACHEVAR,[no])])
85  CPPFLAGS=$ax_check_save_flags])
86AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
87  [m4_default([$2], :)],
88  [m4_default([$3], :)])
89AS_VAR_POPDEF([CACHEVAR])dnl
90])dnl AX_CHECK_PREPROC_FLAGS
91
92AC_DEFUN([AX_CHECK_COMPILE_FLAG],
93[AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX
94AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
95AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
96  ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
97  _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
98  AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
99    [AS_VAR_SET(CACHEVAR,[yes])],
100    [AS_VAR_SET(CACHEVAR,[no])])
101  _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
102AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
103  [m4_default([$2], :)],
104  [m4_default([$3], :)])
105AS_VAR_POPDEF([CACHEVAR])dnl
106])dnl AX_CHECK_COMPILE_FLAGS
107
108AC_DEFUN([AX_CHECK_LINK_FLAG],
109[AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl
110AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [
111  ax_check_save_flags=$LDFLAGS
112  LDFLAGS="$LDFLAGS $4 $1"
113  AC_LINK_IFELSE([AC_LANG_PROGRAM()],
114    [AS_VAR_SET(CACHEVAR,[yes])],
115    [AS_VAR_SET(CACHEVAR,[no])])
116  LDFLAGS=$ax_check_save_flags])
117AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
118  [m4_default([$2], :)],
119  [m4_default([$3], :)])
120AS_VAR_POPDEF([CACHEVAR])dnl
121])dnl AX_CHECK_LINK_FLAGS
122
123
124AC_DEFUN([AX_APPEND_FLAG],
125[AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX
126AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])])dnl
127AS_VAR_SET_IF(FLAGS,
128  [case " AS_VAR_GET(FLAGS) " in
129    *" $1 "*)
130      AC_RUN_LOG([: FLAGS already contains $1])
131      ;;
132    *)
133      AC_RUN_LOG([: FLAGS="$FLAGS $1"])
134      AS_VAR_SET(FLAGS, ["AS_VAR_GET(FLAGS) $1"])
135      ;;
136   esac],
137  [AS_VAR_SET(FLAGS,["$1"])])
138AS_VAR_POPDEF([FLAGS])dnl
139])dnl AX_APPEND_FLAG
140
141AC_DEFUN([AX_APPEND_COMPILE_FLAGS],
142[for flag in $1; do
143  AX_CHECK_COMPILE_FLAG([$flag], [AX_APPEND_FLAG([$flag], [$2])], [], [$3])
144done
145])dnl AX_APPEND_COMPILE_FLAGS
146
147AC_DEFUN([AX_APPEND_LINK_FLAGS],
148[for flag in $1; do
149  AX_CHECK_LINK_FLAG([$flag], [AX_APPEND_FLAG([$flag], [m4_default([$2], [LDFLAGS])])], [], [$3])
150done
151])dnl AX_APPEND_LINK_FLAGS
Note: See TracBrowser for help on using the repository browser.