Blame m4/absolute-header.m4

Packit 709fb3
# absolute-header.m4 serial 16
Packit 709fb3
dnl Copyright (C) 2006-2017 Free Software Foundation, Inc.
Packit 709fb3
dnl This file is free software; the Free Software Foundation
Packit 709fb3
dnl gives unlimited permission to copy and/or distribute it,
Packit 709fb3
dnl with or without modifications, as long as this notice is preserved.
Packit 709fb3
Packit 709fb3
dnl From Derek Price.
Packit 709fb3
Packit 709fb3
# gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...)
Packit 709fb3
# ---------------------------------------
Packit 709fb3
# Find the absolute name of a header file, testing first if the header exists.
Packit 709fb3
# If the header were sys/inttypes.h, this macro would define
Packit 709fb3
# ABSOLUTE_SYS_INTTYPES_H to the '""' quoted absolute name of sys/inttypes.h
Packit 709fb3
# in config.h
Packit 709fb3
# (e.g. '#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"').
Packit 709fb3
# The three "///" are to pacify Sun C 5.8, which otherwise would say
Packit 709fb3
# "warning: #include of /usr/include/... may be non-portable".
Packit 709fb3
# Use '""', not '<>', so that the /// cannot be confused with a C99 comment.
Packit 709fb3
# Note: This macro assumes that the header file is not empty after
Packit 709fb3
# preprocessing, i.e. it does not only define preprocessor macros but also
Packit 709fb3
# provides some type/enum definitions or function/variable declarations.
Packit 709fb3
AC_DEFUN([gl_ABSOLUTE_HEADER],
Packit 709fb3
[AC_REQUIRE([AC_CANONICAL_HOST])
Packit 709fb3
AC_LANG_PREPROC_REQUIRE()dnl
Packit 709fb3
dnl FIXME: gl_absolute_header and ac_header_exists must be used unquoted
Packit 709fb3
dnl until we can assume autoconf 2.64 or newer.
Packit 709fb3
m4_foreach_w([gl_HEADER_NAME], [$1],
Packit 709fb3
  [AS_VAR_PUSHDEF([gl_absolute_header],
Packit 709fb3
                  [gl_cv_absolute_]m4_defn([gl_HEADER_NAME]))dnl
Packit 709fb3
  AC_CACHE_CHECK([absolute name of <]m4_defn([gl_HEADER_NAME])[>],
Packit 709fb3
    m4_defn([gl_absolute_header]),
Packit 709fb3
    [AS_VAR_PUSHDEF([ac_header_exists],
Packit 709fb3
                    [ac_cv_header_]m4_defn([gl_HEADER_NAME]))dnl
Packit 709fb3
    AC_CHECK_HEADERS_ONCE(m4_defn([gl_HEADER_NAME]))dnl
Packit 709fb3
    if test AS_VAR_GET(ac_header_exists) = yes; then
Packit 709fb3
      gl_ABSOLUTE_HEADER_ONE(m4_defn([gl_HEADER_NAME]))
Packit 709fb3
    fi
Packit 709fb3
    AS_VAR_POPDEF([ac_header_exists])dnl
Packit 709fb3
    ])dnl
Packit 709fb3
  AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_defn([gl_HEADER_NAME])),
Packit 709fb3
                     ["AS_VAR_GET(gl_absolute_header)"],
Packit 709fb3
                     [Define this to an absolute name of <]m4_defn([gl_HEADER_NAME])[>.])
Packit 709fb3
  AS_VAR_POPDEF([gl_absolute_header])dnl
Packit 709fb3
])dnl
Packit 709fb3
])# gl_ABSOLUTE_HEADER
Packit 709fb3
Packit 709fb3
# gl_ABSOLUTE_HEADER_ONE(HEADER)
Packit 709fb3
# ------------------------------
Packit 709fb3
# Like gl_ABSOLUTE_HEADER, except that:
Packit 709fb3
#   - it assumes that the header exists,
Packit 709fb3
#   - it uses the current CPPFLAGS,
Packit 709fb3
#   - it does not cache the result,
Packit 709fb3
#   - it is silent.
Packit 709fb3
AC_DEFUN([gl_ABSOLUTE_HEADER_ONE],
Packit 709fb3
[
Packit 709fb3
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit 709fb3
  AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote([$1])[[>]])])
Packit 709fb3
  dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
Packit 709fb3
  dnl that contain only a #include of other header files and no
Packit 709fb3
  dnl non-comment tokens of their own. This leads to a failure to
Packit 709fb3
  dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
Packit 709fb3
  dnl and others. The workaround is to force preservation of comments
Packit 709fb3
  dnl through option -C. This ensures all necessary #line directives
Packit 709fb3
  dnl are present. GCC supports option -C as well.
Packit 709fb3
  case "$host_os" in
Packit 709fb3
    aix*) gl_absname_cpp="$ac_cpp -C" ;;
Packit 709fb3
    *)    gl_absname_cpp="$ac_cpp" ;;
Packit 709fb3
  esac
Packit 709fb3
changequote(,)
Packit 709fb3
  case "$host_os" in
Packit 709fb3
    mingw*)
Packit 709fb3
      dnl For the sake of native Windows compilers (excluding gcc),
Packit 709fb3
      dnl treat backslash as a directory separator, like /.
Packit 709fb3
      dnl Actually, these compilers use a double-backslash as
Packit 709fb3
      dnl directory separator, inside the
Packit 709fb3
      dnl   # line "filename"
Packit 709fb3
      dnl directives.
Packit 709fb3
      gl_dirsep_regex='[/\\]'
Packit 709fb3
      ;;
Packit 709fb3
    *)
Packit 709fb3
      gl_dirsep_regex='\/'
Packit 709fb3
      ;;
Packit 709fb3
  esac
Packit 709fb3
  dnl A sed expression that turns a string into a basic regular
Packit 709fb3
  dnl expression, for use within "/.../".
Packit 709fb3
  gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
Packit 709fb3
  gl_header_literal_regex=`echo '$1' \
Packit 709fb3
                           | sed -e "$gl_make_literal_regex_sed"`
Packit 709fb3
  gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
Packit 709fb3
      s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
Packit 709fb3
      s|^/[^/]|//&|
Packit 709fb3
      p
Packit 709fb3
      q
Packit 709fb3
    }'
Packit 709fb3
changequote([,])
Packit 709fb3
  dnl eval is necessary to expand gl_absname_cpp.
Packit 709fb3
  dnl Ultrix and Pyramid sh refuse to redirect output of eval,
Packit 709fb3
  dnl so use subshell.
Packit 709fb3
  AS_VAR_SET([gl_cv_absolute_]AS_TR_SH([[$1]]),
Packit 709fb3
[`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
Packit 709fb3
  sed -n "$gl_absolute_header_sed"`])
Packit 709fb3
])