xref: /netbsd-src/external/lgpl3/mpc/dist/m4/ax_gcc_option.m4 (revision 8fa80f29617a57ed2098db654a02cc5c7dc15820)
1*8fa80f29Smrg# ===========================================================================
2*8fa80f29Smrg#       http://www.gnu.org/software/autoconf-archive/ax_gcc_option.html
3*8fa80f29Smrg# ===========================================================================
4*8fa80f29Smrg#
5*8fa80f29Smrg# OBSOLETE MACRO
6*8fa80f29Smrg#
7*8fa80f29Smrg#   Deprecated in favor of AX_C_CHECK_FLAG, AX_CXX_CHECK_FLAG,
8*8fa80f29Smrg#   AX_CPP_CHECK_FLAG, AX_CXXCPP_CHECK_FLAG and AX_LD_CHECK_FLAG.
9*8fa80f29Smrg#
10*8fa80f29Smrg# SYNOPSIS
11*8fa80f29Smrg#
12*8fa80f29Smrg#   AX_GCC_OPTION(OPTION,EXTRA-OPTIONS,TEST-PROGRAM,ACTION-IF-SUCCESSFUL,ACTION-IF-NOT-SUCCESFUL)
13*8fa80f29Smrg#
14*8fa80f29Smrg# DESCRIPTION
15*8fa80f29Smrg#
16*8fa80f29Smrg#   AX_GCC_OPTION checks wheter gcc accepts the passed OPTION. If it accepts
17*8fa80f29Smrg#   the OPTION then ACTION-IF-SUCCESSFUL will be executed, otherwise
18*8fa80f29Smrg#   ACTION-IF-UNSUCCESSFUL.
19*8fa80f29Smrg#
20*8fa80f29Smrg#   A typical usage should be the following one:
21*8fa80f29Smrg#
22*8fa80f29Smrg#     AX_GCC_OPTION([-fomit-frame-pointer],[],[],[
23*8fa80f29Smrg#       AC_MSG_NOTICE([The option is supported])],[
24*8fa80f29Smrg#       AC_MSG_NOTICE([No luck this time])
25*8fa80f29Smrg#     ])
26*8fa80f29Smrg#
27*8fa80f29Smrg#   The macro doesn't discriminate between languages so, if you are testing
28*8fa80f29Smrg#   for an option that works for C++ but not for C you should use '-x c++'
29*8fa80f29Smrg#   as EXTRA-OPTIONS:
30*8fa80f29Smrg#
31*8fa80f29Smrg#     AX_GCC_OPTION([-fno-rtti],[-x c++],[],[ ... ],[ ... ])
32*8fa80f29Smrg#
33*8fa80f29Smrg#   OPTION is tested against the following code:
34*8fa80f29Smrg#
35*8fa80f29Smrg#     int main()
36*8fa80f29Smrg#     {
37*8fa80f29Smrg#             return 0;
38*8fa80f29Smrg#     }
39*8fa80f29Smrg#
40*8fa80f29Smrg#   The optional TEST-PROGRAM comes handy when the default main() is not
41*8fa80f29Smrg#   suited for the option being checked
42*8fa80f29Smrg#
43*8fa80f29Smrg#   So, if you need to test for -fstrict-prototypes option you should
44*8fa80f29Smrg#   probably use the macro as follows:
45*8fa80f29Smrg#
46*8fa80f29Smrg#     AX_GCC_OPTION([-fstrict-prototypes],[-x c++],[
47*8fa80f29Smrg#       int main(int argc, char ** argv)
48*8fa80f29Smrg#       {
49*8fa80f29Smrg#               (void) argc;
50*8fa80f29Smrg#               (void) argv;
51*8fa80f29Smrg#
52*8fa80f29Smrg#               return 0;
53*8fa80f29Smrg#       }
54*8fa80f29Smrg#     ],[ ... ],[ ... ])
55*8fa80f29Smrg#
56*8fa80f29Smrg#   Note that the macro compiles but doesn't link the test program so it is
57*8fa80f29Smrg#   not suited for checking options that are passed to the linker, like:
58*8fa80f29Smrg#
59*8fa80f29Smrg#     -Wl,-L<a-library-path>
60*8fa80f29Smrg#
61*8fa80f29Smrg#   In order to avoid such kind of problems you should think about usinguse
62*8fa80f29Smrg#   the AX_*_CHECK_FLAG family macros
63*8fa80f29Smrg#
64*8fa80f29Smrg# LICENSE
65*8fa80f29Smrg#
66*8fa80f29Smrg#   Copyright (c) 2008 Francesco Salvestrini <salvestrini@users.sourceforge.net>
67*8fa80f29Smrg#   Copyright (c) 2008 Bogdan Drozdowski <bogdandr@op.pl>
68*8fa80f29Smrg#
69*8fa80f29Smrg#   This program is free software; you can redistribute it and/or modify it
70*8fa80f29Smrg#   under the terms of the GNU General Public License as published by the
71*8fa80f29Smrg#   Free Software Foundation; either version 2 of the License, or (at your
72*8fa80f29Smrg#   option) any later version.
73*8fa80f29Smrg#
74*8fa80f29Smrg#   This program is distributed in the hope that it will be useful, but
75*8fa80f29Smrg#   WITHOUT ANY WARRANTY; without even the implied warranty of
76*8fa80f29Smrg#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
77*8fa80f29Smrg#   Public License for more details.
78*8fa80f29Smrg#
79*8fa80f29Smrg#   You should have received a copy of the GNU General Public License along
80*8fa80f29Smrg#   with this program. If not, see <http://www.gnu.org/licenses/>.
81*8fa80f29Smrg#
82*8fa80f29Smrg#   As a special exception, the respective Autoconf Macro's copyright owner
83*8fa80f29Smrg#   gives unlimited permission to copy, distribute and modify the configure
84*8fa80f29Smrg#   scripts that are the output of Autoconf when processing the Macro. You
85*8fa80f29Smrg#   need not follow the terms of the GNU General Public License when using
86*8fa80f29Smrg#   or distributing such scripts, even though portions of the text of the
87*8fa80f29Smrg#   Macro appear in them. The GNU General Public License (GPL) does govern
88*8fa80f29Smrg#   all other use of the material that constitutes the Autoconf Macro.
89*8fa80f29Smrg#
90*8fa80f29Smrg#   This special exception to the GPL applies to versions of the Autoconf
91*8fa80f29Smrg#   Macro released by the Autoconf Archive. When you make and distribute a
92*8fa80f29Smrg#   modified version of the Autoconf Macro, you may extend this special
93*8fa80f29Smrg#   exception to the GPL to apply to your modified version as well.
94*8fa80f29Smrg
95*8fa80f29Smrg#serial 13
96*8fa80f29Smrg
97*8fa80f29SmrgAC_DEFUN([AX_GCC_OPTION], [
98*8fa80f29Smrg  AC_REQUIRE([AC_PROG_CC])
99*8fa80f29Smrg
100*8fa80f29Smrg  AC_MSG_CHECKING([if gcc accepts $1 option])
101*8fa80f29Smrg
102*8fa80f29Smrg  AS_IF([ test "x$GCC" = "xyes" ],[
103*8fa80f29Smrg    AS_IF([ test -z "$3" ],[
104*8fa80f29Smrg      ax_gcc_option_test="int main()
105*8fa80f29Smrg{
106*8fa80f29Smrg	return 0;
107*8fa80f29Smrg}"
108*8fa80f29Smrg    ],[
109*8fa80f29Smrg      ax_gcc_option_test="$3"
110*8fa80f29Smrg    ])
111*8fa80f29Smrg
112*8fa80f29Smrg    # Dump the test program to file
113*8fa80f29Smrg    cat <<EOF > conftest.c
114*8fa80f29Smrg$ax_gcc_option_test
115*8fa80f29SmrgEOF
116*8fa80f29Smrg
117*8fa80f29Smrg    # Dump back the file to the log, useful for debugging purposes
118*8fa80f29Smrg    AC_TRY_COMMAND(cat conftest.c 1>&AS_MESSAGE_LOG_FD)
119*8fa80f29Smrg
120*8fa80f29Smrg    AS_IF([ AC_TRY_COMMAND($CC $2 $1 -c conftest.c 1>&AS_MESSAGE_LOG_FD) ],[
121*8fa80f29Smrg		AC_MSG_RESULT([yes])
122*8fa80f29Smrg	$4
123*8fa80f29Smrg    ],[
124*8fa80f29Smrg		AC_MSG_RESULT([no])
125*8fa80f29Smrg	$5
126*8fa80f29Smrg    ])
127*8fa80f29Smrg  ],[
128*8fa80f29Smrg    AC_MSG_RESULT([no gcc available])
129*8fa80f29Smrg  ])
130*8fa80f29Smrg])
131