xref: /minix3/external/bsd/bind/dist/unit/atf-src/m4/compiler-flags.m4 (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1*00b67f09SDavid van Moolenbroekdnl Copyright 2010 Google Inc.
2*00b67f09SDavid van Moolenbroekdnl All rights reserved.
3*00b67f09SDavid van Moolenbroekdnl
4*00b67f09SDavid van Moolenbroekdnl Redistribution and use in source and binary forms, with or without
5*00b67f09SDavid van Moolenbroekdnl modification, are permitted provided that the following conditions are
6*00b67f09SDavid van Moolenbroekdnl met:
7*00b67f09SDavid van Moolenbroekdnl
8*00b67f09SDavid van Moolenbroekdnl * Redistributions of source code must retain the above copyright
9*00b67f09SDavid van Moolenbroekdnl   notice, this list of conditions and the following disclaimer.
10*00b67f09SDavid van Moolenbroekdnl * Redistributions in binary form must reproduce the above copyright
11*00b67f09SDavid van Moolenbroekdnl   notice, this list of conditions and the following disclaimer in the
12*00b67f09SDavid van Moolenbroekdnl   documentation and/or other materials provided with the distribution.
13*00b67f09SDavid van Moolenbroekdnl * Neither the name of Google Inc. nor the names of its contributors
14*00b67f09SDavid van Moolenbroekdnl   may be used to endorse or promote products derived from this software
15*00b67f09SDavid van Moolenbroekdnl   without specific prior written permission.
16*00b67f09SDavid van Moolenbroekdnl
17*00b67f09SDavid van Moolenbroekdnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*00b67f09SDavid van Moolenbroekdnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*00b67f09SDavid van Moolenbroekdnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*00b67f09SDavid van Moolenbroekdnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*00b67f09SDavid van Moolenbroekdnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*00b67f09SDavid van Moolenbroekdnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*00b67f09SDavid van Moolenbroekdnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*00b67f09SDavid van Moolenbroekdnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*00b67f09SDavid van Moolenbroekdnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*00b67f09SDavid van Moolenbroekdnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*00b67f09SDavid van Moolenbroekdnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*00b67f09SDavid van Moolenbroek
29*00b67f09SDavid van Moolenbroekdnl \file compiler-flags.m4
30*00b67f09SDavid van Moolenbroekdnl
31*00b67f09SDavid van Moolenbroekdnl Macros to check for the existence of compiler flags.  The macros in this
32*00b67f09SDavid van Moolenbroekdnl file support both C and C++.
33*00b67f09SDavid van Moolenbroekdnl
34*00b67f09SDavid van Moolenbroekdnl Be aware that, in order to detect a flag accurately, we may need to enable
35*00b67f09SDavid van Moolenbroekdnl strict warning checking in the compiler (i.e. enable -Werror).  Some
36*00b67f09SDavid van Moolenbroekdnl compilers, e.g. Clang, report unknown -W flags as warnings unless -Werror is
37*00b67f09SDavid van Moolenbroekdnl selected.  This fact would confuse the flag checks below because we would
38*00b67f09SDavid van Moolenbroekdnl conclude that a flag is valid while in reality it is not.  To resolve this,
39*00b67f09SDavid van Moolenbroekdnl the macros below will pass -Werror to the compiler along with any other flag
40*00b67f09SDavid van Moolenbroekdnl being checked.
41*00b67f09SDavid van Moolenbroek
42*00b67f09SDavid van Moolenbroek
43*00b67f09SDavid van Moolenbroekdnl Checks for a compiler flag and sets a result variable.
44*00b67f09SDavid van Moolenbroekdnl
45*00b67f09SDavid van Moolenbroekdnl This is an auxiliary macro for the implementation of _KYUA_FLAG.
46*00b67f09SDavid van Moolenbroekdnl
47*00b67f09SDavid van Moolenbroekdnl \param 1 The shell variable containing the compiler name.  Used for
48*00b67f09SDavid van Moolenbroekdnl     reporting purposes only.  C or CXX.
49*00b67f09SDavid van Moolenbroekdnl \param 2 The shell variable containing the flags for the compiler.
50*00b67f09SDavid van Moolenbroekdnl     CFLAGS or CXXFLAGS.
51*00b67f09SDavid van Moolenbroekdnl \param 3 The name of the compiler flag to check for.
52*00b67f09SDavid van Moolenbroekdnl \param 4 The shell variable to set with the result of the test.  Will
53*00b67f09SDavid van Moolenbroekdnl     be set to 'yes' if the flag is valid, 'no' otherwise.
54*00b67f09SDavid van Moolenbroekdnl \param 5 Additional, optional flags to pass to the C compiler while
55*00b67f09SDavid van Moolenbroekdnl     looking for the flag in $3.  We use this here to pass -Werror to the
56*00b67f09SDavid van Moolenbroekdnl     flag checks (unless we are checking for -Werror already).
57*00b67f09SDavid van MoolenbroekAC_DEFUN([_KYUA_FLAG_AUX], [
58*00b67f09SDavid van Moolenbroek    if test x"${$4-unset}" = xunset; then
59*00b67f09SDavid van Moolenbroek        AC_MSG_CHECKING(whether ${$1} supports $3)
60*00b67f09SDavid van Moolenbroek        saved_flags="${$2}"
61*00b67f09SDavid van Moolenbroek        $4=no
62*00b67f09SDavid van Moolenbroek        $2="${$2} $5 $3"
63*00b67f09SDavid van Moolenbroek        AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
64*00b67f09SDavid van Moolenbroek                       AC_MSG_RESULT(yes)
65*00b67f09SDavid van Moolenbroek                       $4=yes,
66*00b67f09SDavid van Moolenbroek                       AC_MSG_RESULT(no))
67*00b67f09SDavid van Moolenbroek        $2="${saved_flags}"
68*00b67f09SDavid van Moolenbroek    fi
69*00b67f09SDavid van Moolenbroek])
70*00b67f09SDavid van Moolenbroek
71*00b67f09SDavid van Moolenbroek
72*00b67f09SDavid van Moolenbroekdnl Checks for a compiler flag and appends it to a result variable.
73*00b67f09SDavid van Moolenbroekdnl
74*00b67f09SDavid van Moolenbroekdnl \param 1 The shell variable containing the compiler name.  Used for
75*00b67f09SDavid van Moolenbroekdnl     reporting purposes only.  CC or CXX.
76*00b67f09SDavid van Moolenbroekdnl \param 2 The shell variable containing the flags for the compiler.
77*00b67f09SDavid van Moolenbroekdnl     CFLAGS or CXXFLAGS.
78*00b67f09SDavid van Moolenbroekdnl \param 3 The name of the compiler flag to check for.
79*00b67f09SDavid van Moolenbroekdnl \param 4 The shell variable to which to append $3 if the flag is valid.
80*00b67f09SDavid van MoolenbroekAC_DEFUN([_KYUA_FLAG], [
81*00b67f09SDavid van Moolenbroek    _KYUA_FLAG_AUX([$1], [$2], [-Werror], [kyua_$1_has_werror])
82*00b67f09SDavid van Moolenbroek    if test "$3" = "-Werror"; then
83*00b67f09SDavid van Moolenbroek        found=${kyua_$1_has_werror}
84*00b67f09SDavid van Moolenbroek    else
85*00b67f09SDavid van Moolenbroek        found=unset
86*00b67f09SDavid van Moolenbroek        if test ${kyua_$1_has_werror} = yes; then
87*00b67f09SDavid van Moolenbroek            _KYUA_FLAG_AUX([$1], [$2], [$3], [found], [-Werror])
88*00b67f09SDavid van Moolenbroek        else
89*00b67f09SDavid van Moolenbroek            _KYUA_FLAG_AUX([$1], [$2], [$3], [found], [])
90*00b67f09SDavid van Moolenbroek        fi
91*00b67f09SDavid van Moolenbroek    fi
92*00b67f09SDavid van Moolenbroek    if test ${found} = yes; then
93*00b67f09SDavid van Moolenbroek        $4="${$4} $3"
94*00b67f09SDavid van Moolenbroek    fi
95*00b67f09SDavid van Moolenbroek])
96*00b67f09SDavid van Moolenbroek
97*00b67f09SDavid van Moolenbroek
98*00b67f09SDavid van Moolenbroekdnl Checks for a C compiler flag and appends it to a variable.
99*00b67f09SDavid van Moolenbroekdnl
100*00b67f09SDavid van Moolenbroekdnl \pre The current language is C.
101*00b67f09SDavid van Moolenbroekdnl
102*00b67f09SDavid van Moolenbroekdnl \param 1 The name of the compiler flag to check for.
103*00b67f09SDavid van Moolenbroekdnl \param 2 The shell variable to which to append $1 if the flag is valid.
104*00b67f09SDavid van MoolenbroekAC_DEFUN([KYUA_CC_FLAG], [
105*00b67f09SDavid van Moolenbroek    AC_LANG_ASSERT([C])
106*00b67f09SDavid van Moolenbroek    _KYUA_FLAG([CC], [CFLAGS], [$1], [$2])
107*00b67f09SDavid van Moolenbroek])
108*00b67f09SDavid van Moolenbroek
109*00b67f09SDavid van Moolenbroek
110*00b67f09SDavid van Moolenbroekdnl Checks for a C++ compiler flag and appends it to a variable.
111*00b67f09SDavid van Moolenbroekdnl
112*00b67f09SDavid van Moolenbroekdnl \pre The current language is C++.
113*00b67f09SDavid van Moolenbroekdnl
114*00b67f09SDavid van Moolenbroekdnl \param 1 The name of the compiler flag to check for.
115*00b67f09SDavid van Moolenbroekdnl \param 2 The shell variable to which to append $1 if the flag is valid.
116*00b67f09SDavid van MoolenbroekAC_DEFUN([KYUA_CXX_FLAG], [
117*00b67f09SDavid van Moolenbroek    AC_LANG_ASSERT([C++])
118*00b67f09SDavid van Moolenbroek    _KYUA_FLAG([CXX], [CXXFLAGS], [$1], [$2])
119*00b67f09SDavid van Moolenbroek])
120*00b67f09SDavid van Moolenbroek
121*00b67f09SDavid van Moolenbroek
122*00b67f09SDavid van Moolenbroekdnl Checks for a set of C compiler flags and appends them to CFLAGS.
123*00b67f09SDavid van Moolenbroekdnl
124*00b67f09SDavid van Moolenbroekdnl The checks are performed independently and only when all the checks are
125*00b67f09SDavid van Moolenbroekdnl done, the output variable is modified.
126*00b67f09SDavid van Moolenbroekdnl
127*00b67f09SDavid van Moolenbroekdnl \param 1 Whitespace-separated list of C flags to check.
128*00b67f09SDavid van MoolenbroekAC_DEFUN([KYUA_CC_FLAGS], [
129*00b67f09SDavid van Moolenbroek    AC_LANG_PUSH([C])
130*00b67f09SDavid van Moolenbroek    valid_cflags=
131*00b67f09SDavid van Moolenbroek    for f in $1; do
132*00b67f09SDavid van Moolenbroek        KYUA_CC_FLAG(${f}, valid_cflags)
133*00b67f09SDavid van Moolenbroek    done
134*00b67f09SDavid van Moolenbroek    if test -n "${valid_cflags}"; then
135*00b67f09SDavid van Moolenbroek        CFLAGS="${CFLAGS} ${valid_cflags}"
136*00b67f09SDavid van Moolenbroek    fi
137*00b67f09SDavid van Moolenbroek    AC_LANG_POP([C])
138*00b67f09SDavid van Moolenbroek])
139*00b67f09SDavid van Moolenbroek
140*00b67f09SDavid van Moolenbroek
141*00b67f09SDavid van Moolenbroekdnl Checks for a set of C++ compiler flags and appends them to CXXFLAGS.
142*00b67f09SDavid van Moolenbroekdnl
143*00b67f09SDavid van Moolenbroekdnl The checks are performed independently and only when all the checks are
144*00b67f09SDavid van Moolenbroekdnl done, the output variable is modified.
145*00b67f09SDavid van Moolenbroekdnl
146*00b67f09SDavid van Moolenbroekdnl \pre The current language is C++.
147*00b67f09SDavid van Moolenbroekdnl
148*00b67f09SDavid van Moolenbroekdnl \param 1 Whitespace-separated list of C flags to check.
149*00b67f09SDavid van MoolenbroekAC_DEFUN([KYUA_CXX_FLAGS], [
150*00b67f09SDavid van Moolenbroek    AC_LANG_PUSH([C++])
151*00b67f09SDavid van Moolenbroek    valid_cxxflags=
152*00b67f09SDavid van Moolenbroek    for f in $1; do
153*00b67f09SDavid van Moolenbroek        KYUA_CXX_FLAG(${f}, valid_cxxflags)
154*00b67f09SDavid van Moolenbroek    done
155*00b67f09SDavid van Moolenbroek    if test -n "${valid_cxxflags}"; then
156*00b67f09SDavid van Moolenbroek        CXXFLAGS="${CXXFLAGS} ${valid_cxxflags}"
157*00b67f09SDavid van Moolenbroek    fi
158*00b67f09SDavid van Moolenbroek    AC_LANG_POP([C++])
159*00b67f09SDavid van Moolenbroek])
160