Blame m4/include_next.m4

Packit 8f70b4
# include_next.m4 serial 24
Packit 8f70b4
dnl Copyright (C) 2006-2018 Free Software Foundation, Inc.
Packit 8f70b4
dnl This file is free software; the Free Software Foundation
Packit 8f70b4
dnl gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
dnl with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
dnl From Paul Eggert and Derek Price.
Packit 8f70b4
Packit 8f70b4
dnl Sets INCLUDE_NEXT, INCLUDE_NEXT_AS_FIRST_DIRECTIVE, PRAGMA_SYSTEM_HEADER,
Packit 8f70b4
dnl and PRAGMA_COLUMNS.
Packit 8f70b4
dnl
Packit 8f70b4
dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to
Packit 8f70b4
dnl 'include' otherwise.
Packit 8f70b4
dnl
Packit 8f70b4
dnl INCLUDE_NEXT_AS_FIRST_DIRECTIVE expands to 'include_next' if the compiler
Packit 8f70b4
dnl supports it in the special case that it is the first include directive in
Packit 8f70b4
dnl the given file, or to 'include' otherwise.
Packit 8f70b4
dnl
Packit 8f70b4
dnl PRAGMA_SYSTEM_HEADER can be used in files that contain #include_next,
Packit 8f70b4
dnl so as to avoid GCC warnings when the gcc option -pedantic is used.
Packit 8f70b4
dnl '#pragma GCC system_header' has the same effect as if the file was found
Packit 8f70b4
dnl through the include search path specified with '-isystem' options (as
Packit 8f70b4
dnl opposed to the search path specified with '-I' options). Namely, gcc
Packit 8f70b4
dnl does not warn about some things, and on some systems (Solaris and Interix)
Packit 8f70b4
dnl __STDC__ evaluates to 0 instead of to 1. The latter is an undesired side
Packit 8f70b4
dnl effect; we are therefore careful to use 'defined __STDC__' or '1' instead
Packit 8f70b4
dnl of plain '__STDC__'.
Packit 8f70b4
dnl
Packit 8f70b4
dnl PRAGMA_COLUMNS can be used in files that override system header files, so
Packit 8f70b4
dnl as to avoid compilation errors on HP NonStop systems when the gnulib file
Packit 8f70b4
dnl is included by a system header file that does a "#pragma COLUMNS 80" (which
Packit 8f70b4
dnl has the effect of truncating the lines of that file and all files that it
Packit 8f70b4
dnl includes to 80 columns) and the gnulib file has lines longer than 80
Packit 8f70b4
dnl columns.
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_INCLUDE_NEXT],
Packit 8f70b4
[
Packit 8f70b4
  AC_LANG_PREPROC_REQUIRE()
Packit 8f70b4
  AC_CACHE_CHECK([whether the preprocessor supports include_next],
Packit 8f70b4
    [gl_cv_have_include_next],
Packit 8f70b4
    [rm -rf conftestd1a conftestd1b conftestd2
Packit 8f70b4
     mkdir conftestd1a conftestd1b conftestd2
Packit 8f70b4
     dnl IBM C 9.0, 10.1 (original versions, prior to the 2009-01 updates) on
Packit 8f70b4
     dnl AIX 6.1 support include_next when used as first preprocessor directive
Packit 8f70b4
     dnl in a file, but not when preceded by another include directive. Check
Packit 8f70b4
     dnl for this bug by including <stdio.h>.
Packit 8f70b4
     dnl Additionally, with this same compiler, include_next is a no-op when
Packit 8f70b4
     dnl used in a header file that was included by specifying its absolute
Packit 8f70b4
     dnl file name. Despite these two bugs, include_next is used in the
Packit 8f70b4
     dnl compiler's <math.h>. By virtue of the second bug, we need to use
Packit 8f70b4
     dnl include_next as well in this case.
Packit 8f70b4
     cat <<EOF > conftestd1a/conftest.h
Packit 8f70b4
#define DEFINED_IN_CONFTESTD1
Packit 8f70b4
#include_next <conftest.h>
Packit 8f70b4
#ifdef DEFINED_IN_CONFTESTD2
Packit 8f70b4
int foo;
Packit 8f70b4
#else
Packit 8f70b4
#error "include_next doesn't work"
Packit 8f70b4
#endif
Packit 8f70b4
EOF
Packit 8f70b4
     cat <<EOF > conftestd1b/conftest.h
Packit 8f70b4
#define DEFINED_IN_CONFTESTD1
Packit 8f70b4
#include <stdio.h>
Packit 8f70b4
#include_next <conftest.h>
Packit 8f70b4
#ifdef DEFINED_IN_CONFTESTD2
Packit 8f70b4
int foo;
Packit 8f70b4
#else
Packit 8f70b4
#error "include_next doesn't work"
Packit 8f70b4
#endif
Packit 8f70b4
EOF
Packit 8f70b4
     cat <<EOF > conftestd2/conftest.h
Packit 8f70b4
#ifndef DEFINED_IN_CONFTESTD1
Packit 8f70b4
#error "include_next test doesn't work"
Packit 8f70b4
#endif
Packit 8f70b4
#define DEFINED_IN_CONFTESTD2
Packit 8f70b4
EOF
Packit 8f70b4
     gl_save_CPPFLAGS="$CPPFLAGS"
Packit 8f70b4
     CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1b -Iconftestd2"
Packit 8f70b4
dnl We intentionally avoid using AC_LANG_SOURCE here.
Packit 8f70b4
     AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[#include <conftest.h>]],
Packit 8f70b4
       [gl_cv_have_include_next=yes],
Packit 8f70b4
       [CPPFLAGS="$gl_save_CPPFLAGS -Iconftestd1a -Iconftestd2"
Packit 8f70b4
        AC_COMPILE_IFELSE([AC_LANG_DEFINES_PROVIDED[#include <conftest.h>]],
Packit 8f70b4
          [gl_cv_have_include_next=buggy],
Packit 8f70b4
          [gl_cv_have_include_next=no])
Packit 8f70b4
       ])
Packit 8f70b4
     CPPFLAGS="$gl_save_CPPFLAGS"
Packit 8f70b4
     rm -rf conftestd1a conftestd1b conftestd2
Packit 8f70b4
    ])
Packit 8f70b4
  PRAGMA_SYSTEM_HEADER=
Packit 8f70b4
  if test $gl_cv_have_include_next = yes; then
Packit 8f70b4
    INCLUDE_NEXT=include_next
Packit 8f70b4
    INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
Packit 8f70b4
    if test -n "$GCC"; then
Packit 8f70b4
      PRAGMA_SYSTEM_HEADER='#pragma GCC system_header'
Packit 8f70b4
    fi
Packit 8f70b4
  else
Packit 8f70b4
    if test $gl_cv_have_include_next = buggy; then
Packit 8f70b4
      INCLUDE_NEXT=include
Packit 8f70b4
      INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include_next
Packit 8f70b4
    else
Packit 8f70b4
      INCLUDE_NEXT=include
Packit 8f70b4
      INCLUDE_NEXT_AS_FIRST_DIRECTIVE=include
Packit 8f70b4
    fi
Packit 8f70b4
  fi
Packit 8f70b4
  AC_SUBST([INCLUDE_NEXT])
Packit 8f70b4
  AC_SUBST([INCLUDE_NEXT_AS_FIRST_DIRECTIVE])
Packit 8f70b4
  AC_SUBST([PRAGMA_SYSTEM_HEADER])
Packit 8f70b4
  AC_CACHE_CHECK([whether system header files limit the line length],
Packit 8f70b4
    [gl_cv_pragma_columns],
Packit 8f70b4
    [dnl HP NonStop systems, which define __TANDEM, have this misfeature.
Packit 8f70b4
     AC_EGREP_CPP([choke me],
Packit 8f70b4
       [
Packit 8f70b4
#ifdef __TANDEM
Packit 8f70b4
choke me
Packit 8f70b4
#endif
Packit 8f70b4
       ],
Packit 8f70b4
       [gl_cv_pragma_columns=yes],
Packit 8f70b4
       [gl_cv_pragma_columns=no])
Packit 8f70b4
    ])
Packit 8f70b4
  if test $gl_cv_pragma_columns = yes; then
Packit 8f70b4
    PRAGMA_COLUMNS="#pragma COLUMNS 10000"
Packit 8f70b4
  else
Packit 8f70b4
    PRAGMA_COLUMNS=
Packit 8f70b4
  fi
Packit 8f70b4
  AC_SUBST([PRAGMA_COLUMNS])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
Packit 8f70b4
# ------------------------------------------
Packit 8f70b4
# For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
Packit 8f70b4
# '<foo.h>'; otherwise define it to be
Packit 8f70b4
# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
Packit 8f70b4
# Also, if #include_next works as first preprocessing directive in a file,
Packit 8f70b4
# define NEXT_AS_FIRST_DIRECTIVE_FOO_H to be '<foo.h>'; otherwise define it to
Packit 8f70b4
# be
Packit 8f70b4
# '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
Packit 8f70b4
# That way, a header file with the following line:
Packit 8f70b4
#       #@INCLUDE_NEXT@ @NEXT_FOO_H@
Packit 8f70b4
# or
Packit 8f70b4
#       #@INCLUDE_NEXT_AS_FIRST_DIRECTIVE@ @NEXT_AS_FIRST_DIRECTIVE_FOO_H@
Packit 8f70b4
# behaves (after sed substitution) as if it contained
Packit 8f70b4
#       #include_next <foo.h>
Packit 8f70b4
# even if the compiler does not support include_next.
Packit 8f70b4
# The three "///" are to pacify Sun C 5.8, which otherwise would say
Packit 8f70b4
# "warning: #include of /usr/include/... may be non-portable".
Packit 8f70b4
# Use '""', not '<>', so that the /// cannot be confused with a C99 comment.
Packit 8f70b4
# Note: This macro assumes that the header file is not empty after
Packit 8f70b4
# preprocessing, i.e. it does not only define preprocessor macros but also
Packit 8f70b4
# provides some type/enum definitions or function/variable declarations.
Packit 8f70b4
#
Packit 8f70b4
# This macro also checks whether each header exists, by invoking
Packit 8f70b4
# AC_CHECK_HEADERS_ONCE or AC_CHECK_HEADERS on each argument.
Packit 8f70b4
AC_DEFUN([gl_CHECK_NEXT_HEADERS],
Packit 8f70b4
[
Packit 8f70b4
  gl_NEXT_HEADERS_INTERNAL([$1], [check])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# gl_NEXT_HEADERS(HEADER1 HEADER2 ...)
Packit 8f70b4
# ------------------------------------
Packit 8f70b4
# Like gl_CHECK_NEXT_HEADERS, except do not check whether the headers exist.
Packit 8f70b4
# This is suitable for headers like <stddef.h> that are standardized by C89
Packit 8f70b4
# and therefore can be assumed to exist.
Packit 8f70b4
AC_DEFUN([gl_NEXT_HEADERS],
Packit 8f70b4
[
Packit 8f70b4
  gl_NEXT_HEADERS_INTERNAL([$1], [assume])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# The guts of gl_CHECK_NEXT_HEADERS and gl_NEXT_HEADERS.
Packit 8f70b4
AC_DEFUN([gl_NEXT_HEADERS_INTERNAL],
Packit 8f70b4
[
Packit 8f70b4
  AC_REQUIRE([gl_INCLUDE_NEXT])
Packit 8f70b4
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit 8f70b4
Packit 8f70b4
  m4_if([$2], [check],
Packit 8f70b4
    [AC_CHECK_HEADERS_ONCE([$1])
Packit 8f70b4
    ])
Packit 8f70b4
Packit 8f70b4
dnl FIXME: gl_next_header and gl_header_exists must be used unquoted
Packit 8f70b4
dnl until we can assume autoconf 2.64 or newer.
Packit 8f70b4
  m4_foreach_w([gl_HEADER_NAME], [$1],
Packit 8f70b4
    [AS_VAR_PUSHDEF([gl_next_header],
Packit 8f70b4
                    [gl_cv_next_]m4_defn([gl_HEADER_NAME]))
Packit 8f70b4
     if test $gl_cv_have_include_next = yes; then
Packit 8f70b4
       AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>'])
Packit 8f70b4
     else
Packit 8f70b4
       AC_CACHE_CHECK(
Packit 8f70b4
         [absolute name of <]m4_defn([gl_HEADER_NAME])[>],
Packit 8f70b4
         m4_defn([gl_next_header]),
Packit 8f70b4
         [m4_if([$2], [check],
Packit 8f70b4
            [AS_VAR_PUSHDEF([gl_header_exists],
Packit 8f70b4
                            [ac_cv_header_]m4_defn([gl_HEADER_NAME]))
Packit 8f70b4
             if test AS_VAR_GET(gl_header_exists) = yes; then
Packit 8f70b4
             AS_VAR_POPDEF([gl_header_exists])
Packit 8f70b4
            ])
Packit 8f70b4
           gl_ABSOLUTE_HEADER_ONE(gl_HEADER_NAME)
Packit 8f70b4
           AS_VAR_COPY([gl_header], [gl_cv_absolute_]AS_TR_SH(gl_HEADER_NAME))
Packit 8f70b4
           AS_VAR_SET(gl_next_header, ['"'$gl_header'"'])
Packit 8f70b4
          m4_if([$2], [check],
Packit 8f70b4
            [else
Packit 8f70b4
               AS_VAR_SET(gl_next_header, ['<'gl_HEADER_NAME'>'])
Packit 8f70b4
             fi
Packit 8f70b4
            ])
Packit 8f70b4
         ])
Packit 8f70b4
     fi
Packit 8f70b4
     AC_SUBST(
Packit 8f70b4
       AS_TR_CPP([NEXT_]m4_defn([gl_HEADER_NAME])),
Packit 8f70b4
       [AS_VAR_GET(gl_next_header)])
Packit 8f70b4
     if test $gl_cv_have_include_next = yes || test $gl_cv_have_include_next = buggy; then
Packit 8f70b4
       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include_next'
Packit 8f70b4
       gl_next_as_first_directive='<'gl_HEADER_NAME'>'
Packit 8f70b4
     else
Packit 8f70b4
       # INCLUDE_NEXT_AS_FIRST_DIRECTIVE='include'
Packit 8f70b4
       gl_next_as_first_directive=AS_VAR_GET(gl_next_header)
Packit 8f70b4
     fi
Packit 8f70b4
     AC_SUBST(
Packit 8f70b4
       AS_TR_CPP([NEXT_AS_FIRST_DIRECTIVE_]m4_defn([gl_HEADER_NAME])),
Packit 8f70b4
       [$gl_next_as_first_directive])
Packit 8f70b4
     AS_VAR_POPDEF([gl_next_header])])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# Autoconf 2.68 added warnings for our use of AC_COMPILE_IFELSE;
Packit 8f70b4
# this fallback is safe for all earlier autoconf versions.
Packit 8f70b4
m4_define_default([AC_LANG_DEFINES_PROVIDED])