]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/lutok/m4/compiler-features.m4
MFV r367082:
[FreeBSD/FreeBSD.git] / contrib / lutok / m4 / compiler-features.m4
1 dnl Copyright 2010 Google Inc.
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
30 dnl KYUA_REQUIRE_CXX
31 dnl
32 dnl Ensures the C++ compiler detected by AC_PROG_CXX is present and works.
33 dnl The compiler check should be performed here, but it seems like Autoconf
34 dnl does not allow it.
35 dnl
36 AC_DEFUN([KYUA_REQUIRE_CXX], [
37     AC_CACHE_CHECK([whether the C++ compiler works],
38                    [atf_cv_prog_cxx_works],
39                    [AC_LANG_PUSH([C++])
40                     AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
41                                    [atf_cv_prog_cxx_works=yes],
42                                    [atf_cv_prog_cxx_works=no])
43                     AC_LANG_POP([C++])])
44     if test "${atf_cv_prog_cxx_works}" = no; then
45         AC_MSG_ERROR([C++ compiler cannot create executables])
46     fi
47 ])
48
49 dnl
50 dnl KYUA_ATTRIBUTE_NORETURN
51 dnl
52 dnl Checks if the current compiler has a way to mark functions that do not
53 dnl return and defines ATTRIBUTE_NORETURN to the appropriate string.
54 dnl
55 AC_DEFUN([KYUA_ATTRIBUTE_NORETURN], [
56     dnl This check is overly simple and should be fixed.  For example,
57     dnl Sun's cc does support the noreturn attribute but CC (the C++
58     dnl compiler) does not.  And in that case, CC just raises a warning
59     dnl during compilation, not an error.
60     AC_MSG_CHECKING(whether __attribute__((noreturn)) is supported)
61     AC_RUN_IFELSE([AC_LANG_PROGRAM([], [
62 #if ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2)
63     return 0;
64 #else
65     return 1;
66 #endif
67         ])],
68         [AC_MSG_RESULT(yes)
69          value="__attribute__((noreturn))"],
70         [AC_MSG_RESULT(no)
71          value=""]
72     )
73     AC_SUBST([ATTRIBUTE_NORETURN], [${value}])
74 ])
75
76
77 dnl
78 dnl KYUA_ATTRIBUTE_UNUSED
79 dnl
80 dnl Checks if the current compiler has a way to mark parameters as unused
81 dnl so that the -Wunused-parameter warning can be avoided.
82 dnl
83 AC_DEFUN([KYUA_ATTRIBUTE_UNUSED], [
84     AC_MSG_CHECKING(whether __attribute__((__unused__)) is supported)
85     AC_COMPILE_IFELSE(
86         [AC_LANG_PROGRAM([
87 static void
88 function(int a __attribute__((__unused__)))
89 {
90 }], [
91     function(3);
92     return 0;
93 ])],
94         [AC_MSG_RESULT(yes)
95          value="__attribute__((__unused__))"],
96         [AC_MSG_RESULT(no)
97          value=""]
98     )
99     AC_SUBST([ATTRIBUTE_UNUSED], [${value}])
100 ])