2N/A# include_next.m4 serial 15
2N/Adnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
2N/Adnl This file is free software; the Free Software Foundation
2N/Adnl gives unlimited permission to copy and/or distribute it,
2N/Adnl with or without modifications, as long as this notice is preserved.
2N/A
2N/Adnl From Paul Eggert and Derek Price.
2N/A
2N/Adnl Sets INCLUDE_NEXT and PRAGMA_SYSTEM_HEADER.
2N/Adnl
2N/Adnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to
2N/Adnl 'include' otherwise.
2N/Adnl
2N/Adnl INCLUDE_NEXT_AS_FIRST_DIRECTIVE expands to 'include_next' if the compiler
2N/Adnl supports it in the special case that it is the first include directive in
2N/Adnl the given file, or to 'include' otherwise.
2N/Adnl
2N/Adnl PRAGMA_SYSTEM_HEADER can be used in files that contain #include_next,
2N/Adnl so as to avoid GCC warnings when the gcc option -pedantic is used.
2N/Adnl '#pragma GCC system_header' has the same effect as if the file was found
2N/Adnl through the include search path specified with '-isystem' options (as
2N/Adnl opposed to the search path specified with '-I' options). Namely, gcc
2N/Adnl does not warn about some things, and on some systems (Solaris and Interix)
2N/Adnl __STDC__ evaluates to 0 instead of to 1. The latter is an undesired side
2N/Adnl effect; we are therefore careful to use 'defined __STDC__' or '1' instead
2N/Adnl of plain '__STDC__'.
2N/A
2N/AAC_DEFUN([gl_INCLUDE_NEXT],
2N/A[
2N/A AC_LANG_PREPROC_REQUIRE()
2N/A AC_CACHE_CHECK([whether the preprocessor supports include_next],
2N/A [gl_cv_have_include_next],
2N/A [rm -rf conftestd1a conftestd1b conftestd2
2N/A mkdir conftestd1a conftestd1b conftestd2
2N/A dnl IBM C 9.0, 10.1 (original versions, prior to the 2009-01 updates) on
2N/A dnl AIX 6.1 support include_next when used as first preprocessor directive
2N/A dnl in a file, but not when preceded by another include directive. Check
2N/A dnl for this bug by including <stdio.h>.
2N/A dnl Additionally, with this same compiler, include_next is a no-op when
2N/A dnl used in a header file that was included by specifying its absolute
2N/A dnl file name. Despite these two bugs, include_next is used in the
2N/A dnl compiler's <math.h>. By virtue of the second bug, we need to use
2N/A dnl include_next as well in this case.
2N/A cat <<EOF > conftestd1a/conftest.h
2N/A#define DEFINED_IN_CONFTESTD1
2N/A#include_next <conftest.h>
2N/A#ifdef DEFINED_IN_CONFTESTD2
2N/Aint foo;
2N/A#else
2N/A#error "include_next doesn't work"
2N/A#endif
2N/AEOF
2N/A cat <<EOF > conftestd1b/conftest.h
2N/A#define DEFINED_IN_CONFTESTD1
2N/A#include <stdio.h>
2N/A#include_next <conftest.h>
2N/A#ifdef DEFINED_IN_CONFTESTD2
2N/Aint foo;
2N/A#else
2N/A#error "include_next doesn't work"
2N/A#endif
2N/AEOF
2N/A cat <<EOF > conftestd2/conftest.h
2N/A#ifndef DEFINED_IN_CONFTESTD1
2N/A#error "include_next test doesn't work"
2N/A#endif
2N/A#define DEFINED_IN_CONFTESTD2
2N/AEOF
2N/A gl_save_CPPFLAGS="$CPPFLAGS"
2N/A CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1b -Iconftestd2"
2N/Adnl We intentionally avoid using AC_LANG_SOURCE here.
2N/A AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[#include <conftest.h>]],
2N/A [gl_cv_have_include_next=yes],
2N/A [CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1a -Iconftestd2"
2N/A AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[#include <conftest.h>]],
2N/A [gl_cv_have_include_next=buggy],
2N/A [gl_cv_have_include_next=no])
2N/A ])
2N/A CPPFLAGS="$gl_save_CPPFLAGS"
2N/A rm -rf conftestd1a conftestd1b conftestd2
2N/A ])
2N/A PRAGMA_SYSTEM_HEADER=
2N/A if test $gl_cv_have_include_next = yes; then
2N/A INCLUDE_NEXT=include_next
2N/A INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
2N/A if test -n "$GCC"; then
2N/A PRAGMA_SYSTEM_HEADER='#pragma GCC system_header'
2N/A fi
2N/A else
2N/A if test $gl_cv_have_include_next = buggy; then
2N/A INCLUDE_NEXT=include
2N/A INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
2N/A else
2N/A INCLUDE_NEXT=include
2N/A INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include
2N/A fi
2N/A fi
2N/A AC_SUBST([INCLUDE_NEXT])
2N/A AC_SUBST([INCLUDE_NEXT_AS_FIRST_DIRECTIVE])
2N/A AC_SUBST([PRAGMA_SYSTEM_HEADER])
2N/A])
2N/A
2N/A# gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
2N/A# ------------------------------------------
2N/A# For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
2N/A# '<foo.h>'; otherwise define it to be
2N/A# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
2N/A# Also, if #include_next works as first preprocessing directive in a file,
2N/A# define NEXT_AS_FIRST_DIRECTIVE_FOO_H to be '<foo.h>'; otherwise define it to
2N/A# be
2N/A# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
2N/A# That way, a header file with the following line:
2N/A# #@INCLUDE_NEXT@ @NEXT_FOO_H@
2N/A# or
2N/A# #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@
2N/A# behaves (after sed substitution) as if it contained
2N/A# #include_next <foo.h>
2N/A# even if the compiler does not support include_next.
2N/A# The three "///" are to pacify Sun C 5.8, which otherwise would say
2N/A# "warning: #include of /usr/include/... may be non-portable".
2N/A# Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
2N/A# Note: This macro assumes that the header file is not empty after
2N/A# preprocessing, i.e. it does not only define preprocessor macros but also
2N/A# provides some type/enum definitions or function/variable declarations.
2N/AAC_DEFUN([gl_CHECK_NEXT_HEADERS],
2N/A[
2N/A AC_REQUIRE([gl_INCLUDE_NEXT])
2N/A AC_REQUIRE([AC_CANONICAL_HOST])
2N/A AC_CHECK_HEADERS_ONCE([$1])
2N/A
2N/A m4_foreach_w([gl_HEADER_NAME], [$1],
2N/A [AS_VAR_PUSHDEF([gl_next_header],
2N/A [gl_cv_next_]m4_defn([gl_HEADER_NAME]))
2N/A if test $gl_cv_have_include_next = yes; then
2N/A AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
2N/A else
2N/A AC_CACHE_CHECK(
2N/A [absolute name of <]m4_defn([gl_HEADER_NAME])[>],
2N/A m4_defn([gl_next_header]),
2N/A [AS_VAR_PUSHDEF([gl_header_exists],
2N/A [ac_cv_header_]m4_defn([gl_HEADER_NAME]))
2N/A if test AS_VAR_GET(gl_header_exists) = yes; then
2N/A AC_LANG_CONFTEST(
2N/A [AC_LANG_SOURCE(
2N/A [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
2N/A )])
2N/A dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
2N/A dnl that contain only a #include of other header files and no
2N/A dnl non-comment tokens of their own. This leads to a failure to
2N/A dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
2N/A dnl and others. The workaround is to force preservation of comments
2N/A dnl through option -C. This ensures all necessary #line directives
2N/A dnl are present. GCC supports option -C as well.
2N/A case "$host_os" in
2N/A aix*) gl_absname_cpp="$ac_cpp -C" ;;
2N/A *) gl_absname_cpp="$ac_cpp" ;;
2N/A esac
2N/A dnl eval is necessary to expand gl_absname_cpp.
2N/A dnl Ultrix and Pyramid sh refuse to redirect output of eval,
2N/A dnl so use subshell.
2N/A AS_VAR_SET([gl_next_header],
2N/A ['"'`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
2N/A sed -n '\#/]m4_defn([gl_HEADER_NAME])[#{
2N/A s#.*"\(.*/]m4_defn([gl_HEADER_NAME])[\)".*#\1#
2N/A s#^/[^/]#//&#
2N/A p
2N/A q
2N/A }'`'"'])
2N/A else
2N/A AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
2N/A fi
2N/A AS_VAR_POPDEF([gl_header_exists])])
2N/A fi
2N/A AC_SUBST(
2N/A AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])),
2N/A [AS_VAR_GET([gl_next_header])])
2N/A if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
2N/A # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
2N/A gl_next_as_first_directive='<'gl_HEADER_NAME'>'
2N/A else
2N/A # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
2N/A gl_next_as_first_directive=AS_VAR_GET([gl_next_header])
2N/A fi
2N/A AC_SUBST(
2N/A AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])),
2N/A [$gl_next_as_first_directive])
2N/A AS_VAR_POPDEF([gl_next_header])])
2N/A])
2N/A
2N/A# Autoconf 2.68 added warnings for our use of AC_COMPILE_IFELSE;
2N/A# this fallback is safe for all earlier autoconf versions.
2N/Am4_define_default([AC_LANG_DEFINES_PROVIDED])