|
| 1 | +# config/check_decls.m4 |
| 2 | + |
| 3 | +# This file redefines the standard Autoconf macro AC_CHECK_DECL, |
| 4 | +# and adds a supporting function _AC_UNDECLARED_WARNING, to make |
| 5 | +# AC_CHECK_DECLS behave correctly when checking for built-in library |
| 6 | +# functions with clang. |
| 7 | + |
| 8 | +# This is based on commit 82ef7805faffa151e724aa76c245ec590d174580 |
| 9 | +# in the Autoconf git repository, adapted to work with Autoconf 2.63. |
| 10 | +# It's still mostly their code, so |
| 11 | +# it's distributed under Autoconf's license: |
| 12 | + |
| 13 | +# This file is part of Autoconf. This program is free |
| 14 | +# software; you can redistribute it and/or modify it under the |
| 15 | +# terms of the GNU General Public License as published by the |
| 16 | +# Free Software Foundation, either version 3 of the License, or |
| 17 | +# (at your option) any later version. |
| 18 | +# |
| 19 | +# This program is distributed in the hope that it will be useful, |
| 20 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +# GNU General Public License for more details. |
| 23 | +# |
| 24 | +# Under Section 7 of GPL version 3, you are granted additional |
| 25 | +# permissions described in the Autoconf Configure Script Exception, |
| 26 | +# version 3.0, as published by the Free Software Foundation. |
| 27 | +# |
| 28 | +# You should have received a copy of the GNU General Public License |
| 29 | +# and a copy of the Autoconf Configure Script Exception along with |
| 30 | +# this program; see the files COPYINGv3 and COPYING.EXCEPTION |
| 31 | +# respectively. If not, see <http://www.gnu.org/licenses/>. |
| 32 | + |
| 33 | +# Written by David MacKenzie, with help from |
| 34 | +# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor, |
| 35 | +# Roland McGrath, Noah Friedman, david d zuhn, and many others. |
| 36 | + |
| 37 | + |
| 38 | +# _AC_UNDECLARED_WARNING |
| 39 | +# ---------------------- |
| 40 | +# Set ac_[]_AC_LANG_ABBREV[]_decl_warn_flag=yes if the compiler uses a warning, |
| 41 | +# not a more-customary error, to report some undeclared identifiers. Fail when |
| 42 | +# an affected compiler warns also on valid input. _AC_PROG_PREPROC_WORKS_IFELSE |
| 43 | +# solves a related problem. |
| 44 | +AC_DEFUN([_AC_UNDECLARED_WARNING], |
| 45 | +[# The Clang compiler raises a warning for an undeclared identifier that matches |
| 46 | +# a compiler builtin function. All extant Clang versions are affected, as of |
| 47 | +# Clang 3.6.0. Test a builtin known to every version. This problem affects the |
| 48 | +# C and Objective C languages, but Clang does report an error under C++ and |
| 49 | +# Objective C++. |
| 50 | +# |
| 51 | +# Passing -fno-builtin to the compiler would suppress this problem. That |
| 52 | +# strategy would have the advantage of being insensitive to stray warnings, but |
| 53 | +# it would make tests less realistic. |
| 54 | +AC_CACHE_CHECK([how $CC reports undeclared, standard C functions], |
| 55 | +[ac_cv_[]_AC_LANG_ABBREV[]_decl_report], |
| 56 | +[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[(void) strchr;])], |
| 57 | +[AS_IF([test -s conftest.err],[dnl |
| 58 | + # For AC_CHECK_DECL to react to warnings, the compiler must be silent on |
| 59 | + # valid AC_CHECK_DECL input. No library function is consistently available |
| 60 | + # on freestanding implementations, so test against a dummy declaration. |
| 61 | + # Include always-available headers on the off chance that they somehow |
| 62 | + # elicit warnings. |
| 63 | +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([dnl |
| 64 | +#include <float.h> |
| 65 | +#include <limits.h> |
| 66 | +#include <stdarg.h> |
| 67 | +#include <stddef.h> |
| 68 | +extern void ac_decl (int, char *);], |
| 69 | +[@%:@ifdef __cplusplus |
| 70 | + (void) ac_decl ((int) 0, (char *) 0); |
| 71 | + (void) ac_decl; |
| 72 | +@%:@else |
| 73 | + (void) ac_decl; |
| 74 | +@%:@endif |
| 75 | +])], |
| 76 | +[AS_IF([test -s conftest.err], |
| 77 | +[AC_MSG_FAILURE([cannot detect from compiler exit status or warnings])], |
| 78 | +[ac_cv_[]_AC_LANG_ABBREV[]_decl_report=warning])], |
| 79 | +[AC_MSG_FAILURE([cannot compile a simple declaration test])])], |
| 80 | +[AC_MSG_FAILURE([compiler does not report undeclared identifiers])])], |
| 81 | +[ac_cv_[]_AC_LANG_ABBREV[]_decl_report=error])]) |
| 82 | +
|
| 83 | +case $ac_cv_[]_AC_LANG_ABBREV[]_decl_report in |
| 84 | + warning) ac_[]_AC_LANG_ABBREV[]_decl_warn_flag=yes ;; |
| 85 | + *) ac_[]_AC_LANG_ABBREV[]_decl_warn_flag= ;; |
| 86 | +esac |
| 87 | +])# _AC_UNDECLARED_WARNING |
| 88 | + |
| 89 | +# AC_CHECK_DECL |
| 90 | +# ------------- |
| 91 | +# Replace Autoconf 2.63's standard definition of AC_CHECK_DECL, |
| 92 | +# setting it up to treat warnings as errors if necessary. |
| 93 | +m4_define([AC_CHECK_DECL], |
| 94 | +[dnl Initialize each $ac_[]_AC_LANG_ABBREV[]_decl_warn_flag once. |
| 95 | +AC_DEFUN([_AC_UNDECLARED_WARNING_]_AC_LANG_ABBREV, |
| 96 | +[_AC_UNDECLARED_WARNING])dnl |
| 97 | +AC_REQUIRE([_AC_UNDECLARED_WARNING_]_AC_LANG_ABBREV)dnl |
| 98 | +AS_VAR_PUSHDEF([ac_Symbol],[ac_cv_have_decl_$1])dnl |
| 99 | +AC_CACHE_CHECK([whether$1 is declared],[ac_Symbol], |
| 100 | +[ac_save_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag |
| 101 | +ac_[]_AC_LANG_ABBREV[]_werror_flag="$ac_[]_AC_LANG_ABBREV[]_decl_warn_flag$ac_[]_AC_LANG_ABBREV[]_werror_flag" |
| 102 | +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])], |
| 103 | +[#ifndef$1 |
| 104 | + (void)$1; |
| 105 | +#endif |
| 106 | +])], |
| 107 | +[AS_VAR_SET([ac_Symbol],[yes])], |
| 108 | +[AS_VAR_SET([ac_Symbol],[no])]) |
| 109 | +ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_save_werror_flag]) |
| 110 | +AS_VAR_IF([ac_Symbol],[yes],[$2],[$3])[]dnl |
| 111 | +AS_VAR_POPDEF([ac_Symbol])dnl |
| 112 | +])# AC_CHECK_DECL |