1dnl Copyright 2010 Google Inc.
2dnl All rights reserved.
3dnl
4dnl Redistribution and use in source and binary forms, with or without
5dnl modification, are permitted provided that the following conditions are
6dnl met:
7dnl
8dnl * Redistributions of source code must retain the above copyright
9dnl   notice, this list of conditions and the following disclaimer.
10dnl * Redistributions in binary form must reproduce the above copyright
11dnl   notice, this list of conditions and the following disclaimer in the
12dnl   documentation and/or other materials provided with the distribution.
13dnl * Neither the name of Google Inc. nor the names of its contributors
14dnl   may be used to endorse or promote products derived from this software
15dnl   without specific prior written permission.
16dnl
17dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29dnl
30dnl KYUA_REQUIRE_CXX
31dnl
32dnl Ensures the C++ compiler detected by AC_PROG_CXX is present and works.
33dnl The compiler check should be performed here, but it seems like Autoconf
34dnl does not allow it.
35dnl
36AC_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
49dnl
50dnl KYUA_ATTRIBUTE_NORETURN
51dnl
52dnl Checks if the current compiler has a way to mark functions that do not
53dnl return and defines ATTRIBUTE_NORETURN to the appropriate string.
54dnl
55AC_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
77dnl
78dnl KYUA_ATTRIBUTE_UNUSED
79dnl
80dnl Checks if the current compiler has a way to mark parameters as unused
81dnl so that the -Wunused-parameter warning can be avoided.
82dnl
83AC_DEFUN([KYUA_ATTRIBUTE_UNUSED], [
84    AC_MSG_CHECKING(whether __attribute__((__unused__)) is supported)
85    AC_COMPILE_IFELSE(
86        [AC_LANG_PROGRAM([
87static void
88function(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])
101