xref: /netbsd-src/external/lgpl3/mpc/dist/m4/ax_c_check_flag.m4 (revision 8fa80f29617a57ed2098db654a02cc5c7dc15820)
1*8fa80f29Smrg# ===========================================================================
2*8fa80f29Smrg#      http://www.gnu.org/software/autoconf-archive/ax_c_check_flag.html
3*8fa80f29Smrg# ===========================================================================
4*8fa80f29Smrg#
5*8fa80f29Smrg# SYNOPSIS
6*8fa80f29Smrg#
7*8fa80f29Smrg#   AX_C_CHECK_FLAG(FLAG-TO-CHECK,[PROLOGUE],[BODY],[ACTION-IF-SUCCESS],[ACTION-IF-FAILURE])
8*8fa80f29Smrg#
9*8fa80f29Smrg# DESCRIPTION
10*8fa80f29Smrg#
11*8fa80f29Smrg#   This macro tests if the C compiler supports the flag FLAG-TO-CHECK. If
12*8fa80f29Smrg#   successfull execute ACTION-IF-SUCCESS otherwise ACTION-IF-FAILURE.
13*8fa80f29Smrg#   PROLOGUE and BODY are optional and should be used as in AC_LANG_PROGRAM
14*8fa80f29Smrg#   macro.
15*8fa80f29Smrg#
16*8fa80f29Smrg#   This code is inspired from KDE_CHECK_COMPILER_FLAG macro. Thanks to
17*8fa80f29Smrg#   Bogdan Drozdowski <bogdandr@op.pl> for testing and bug fixes.
18*8fa80f29Smrg#
19*8fa80f29Smrg# LICENSE
20*8fa80f29Smrg#
21*8fa80f29Smrg#   Copyright (c) 2008 Francesco Salvestrini <salvestrini@users.sourceforge.net>
22*8fa80f29Smrg#
23*8fa80f29Smrg#   This program is free software; you can redistribute it and/or modify it
24*8fa80f29Smrg#   under the terms of the GNU General Public License as published by the
25*8fa80f29Smrg#   Free Software Foundation; either version 2 of the License, or (at your
26*8fa80f29Smrg#   option) any later version.
27*8fa80f29Smrg#
28*8fa80f29Smrg#   This program is distributed in the hope that it will be useful, but
29*8fa80f29Smrg#   WITHOUT ANY WARRANTY; without even the implied warranty of
30*8fa80f29Smrg#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
31*8fa80f29Smrg#   Public License for more details.
32*8fa80f29Smrg#
33*8fa80f29Smrg#   You should have received a copy of the GNU General Public License along
34*8fa80f29Smrg#   with this program. If not, see <http://www.gnu.org/licenses/>.
35*8fa80f29Smrg#
36*8fa80f29Smrg#   As a special exception, the respective Autoconf Macro's copyright owner
37*8fa80f29Smrg#   gives unlimited permission to copy, distribute and modify the configure
38*8fa80f29Smrg#   scripts that are the output of Autoconf when processing the Macro. You
39*8fa80f29Smrg#   need not follow the terms of the GNU General Public License when using
40*8fa80f29Smrg#   or distributing such scripts, even though portions of the text of the
41*8fa80f29Smrg#   Macro appear in them. The GNU General Public License (GPL) does govern
42*8fa80f29Smrg#   all other use of the material that constitutes the Autoconf Macro.
43*8fa80f29Smrg#
44*8fa80f29Smrg#   This special exception to the GPL applies to versions of the Autoconf
45*8fa80f29Smrg#   Macro released by the Autoconf Archive. When you make and distribute a
46*8fa80f29Smrg#   modified version of the Autoconf Macro, you may extend this special
47*8fa80f29Smrg#   exception to the GPL to apply to your modified version as well.
48*8fa80f29Smrg
49*8fa80f29Smrg#serial 6
50*8fa80f29Smrg
51*8fa80f29SmrgAC_DEFUN([AX_C_CHECK_FLAG],[
52*8fa80f29Smrg  AC_PREREQ([2.61])
53*8fa80f29Smrg  AC_REQUIRE([AC_PROG_CC])
54*8fa80f29Smrg  AC_REQUIRE([AC_PROG_SED])
55*8fa80f29Smrg
56*8fa80f29Smrg  flag=`echo "$1" | $SED 'y% .=/+-(){}<>:*,%_______________%'`
57*8fa80f29Smrg
58*8fa80f29Smrg  AC_CACHE_CHECK([whether the C compiler accepts the $1 flag],
59*8fa80f29Smrg    [ax_cv_c_check_flag_$flag],[
60*8fa80f29Smrg
61*8fa80f29Smrg    AC_LANG_PUSH([C])
62*8fa80f29Smrg
63*8fa80f29Smrg    save_CFLAGS="$CFLAGS"
64*8fa80f29Smrg    CFLAGS="$CFLAGS $1"
65*8fa80f29Smrg    AC_COMPILE_IFELSE([
66*8fa80f29Smrg      AC_LANG_PROGRAM([$2],[$3])
67*8fa80f29Smrg    ],[
68*8fa80f29Smrg      eval "ax_cv_c_check_flag_$flag=yes"
69*8fa80f29Smrg    ],[
70*8fa80f29Smrg      eval "ax_cv_c_check_flag_$flag=no"
71*8fa80f29Smrg    ])
72*8fa80f29Smrg
73*8fa80f29Smrg    CFLAGS="$save_CFLAGS"
74*8fa80f29Smrg
75*8fa80f29Smrg    AC_LANG_POP
76*8fa80f29Smrg
77*8fa80f29Smrg  ])
78*8fa80f29Smrg
79*8fa80f29Smrg  AS_IF([eval "test \"`echo '$ax_cv_c_check_flag_'$flag`\" = yes"],[
80*8fa80f29Smrg    :
81*8fa80f29Smrg    $4
82*8fa80f29Smrg  ],[
83*8fa80f29Smrg    :
84*8fa80f29Smrg    $5
85*8fa80f29Smrg  ])
86*8fa80f29Smrg])
87