Blame m4/include_next.m4

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