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