]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/kyua/m4/compiler-features.m4
sysctl(9): Fix a few mandoc related issues
[FreeBSD/FreeBSD.git] / contrib / kyua / m4 / compiler-features.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
30 dnl KYUA_ATTRIBUTE_NORETURN
31 dnl
32 dnl Checks if the current compiler has a way to mark functions that do not
33 dnl return and defines ATTRIBUTE_NORETURN to the appropriate string.
34 dnl
35 AC_DEFUN([KYUA_ATTRIBUTE_NORETURN], [
36     dnl This check is overly simple and should be fixed.  For example,
37     dnl Sun's cc does support the noreturn attribute but CC (the C++
38     dnl compiler) does not.  And in that case, CC just raises a warning
39     dnl during compilation, not an error.
40     AC_CACHE_CHECK(
41         [whether __attribute__((noreturn)) is supported],
42         [kyua_cv_attribute_noreturn], [
43         AC_RUN_IFELSE([AC_LANG_PROGRAM([], [
44 #if ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2)
45     return 0;
46 #else
47     return 1;
48 #endif
49             ])],
50             [kyua_cv_attribute_noreturn=yes],
51             [kyua_cv_attribute_noreturn=no])
52     ])
53     if test "${kyua_cv_attribute_noreturn}" = yes; then
54         attribute_value="__attribute__((noreturn))"
55     else
56         attribute_value=""
57     fi
58     AC_SUBST([ATTRIBUTE_NORETURN], [${attribute_value}])
59 ])
60
61
62 dnl
63 dnl KYUA_ATTRIBUTE_PURE
64 dnl
65 dnl Checks if the current compiler has a way to mark functions as pure.
66 dnl
67 AC_DEFUN([KYUA_ATTRIBUTE_PURE], [
68     AC_CACHE_CHECK(
69         [whether __attribute__((__pure__)) is supported],
70         [kyua_cv_attribute_pure], [
71         AC_COMPILE_IFELSE(
72             [AC_LANG_PROGRAM([
73 static int function(int, int) __attribute__((__pure__));
74
75 static int
76 function(int a, int b)
77 {
78     return a + b;
79 }], [
80     return function(3, 4);
81 ])],
82             [kyua_cv_attribute_pure=yes],
83             [kyua_cv_attribute_pure=no])
84     ])
85     if test "${kyua_cv_attribute_pure}" = yes; then
86         attribute_value="__attribute__((__pure__))"
87     else
88         attribute_value=""
89     fi
90     AC_SUBST([ATTRIBUTE_PURE], [${attribute_value}])
91 ])
92
93
94 dnl
95 dnl KYUA_ATTRIBUTE_UNUSED
96 dnl
97 dnl Checks if the current compiler has a way to mark parameters as unused
98 dnl so that the -Wunused-parameter warning can be avoided.
99 dnl
100 AC_DEFUN([KYUA_ATTRIBUTE_UNUSED], [
101     AC_CACHE_CHECK(
102         [whether __attribute__((__unused__)) is supported],
103         [kyua_cv_attribute_unused], [
104         AC_COMPILE_IFELSE(
105             [AC_LANG_PROGRAM([
106 static void
107 function(int a __attribute__((__unused__)))
108 {
109 }], [
110     function(3);
111     return 0;
112 ])],
113             [kyua_cv_attribute_unused=yes],
114             [kyua_cv_attribute_unused=no])
115     ])
116     if test "${kyua_cv_attribute_unused}" = yes; then
117         attribute_value="__attribute__((__unused__))"
118     else
119         attribute_value=""
120     fi
121     AC_SUBST([ATTRIBUTE_UNUSED], [${attribute_value}])
122 ])