Blame glm4/include_next.m4

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