Blame m4/absolute-header.m4

Packit 8f70b4
# absolute-header.m4 serial 16
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 Derek Price.
Packit 8f70b4
Packit 8f70b4
# gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...)
Packit 8f70b4
# ---------------------------------------
Packit 8f70b4
# Find the absolute name of a header file, testing first if the header exists.
Packit 8f70b4
# If the header were sys/inttypes.h, this macro would define
Packit 8f70b4
# ABSOLUTE_SYS_INTTYPES_H to the '""' quoted absolute name of sys/inttypes.h
Packit 8f70b4
# in config.h
Packit 8f70b4
# (e.g. '#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"').
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
AC_DEFUN([gl_ABSOLUTE_HEADER],
Packit 8f70b4
[AC_REQUIRE([AC_CANONICAL_HOST])
Packit 8f70b4
AC_LANG_PREPROC_REQUIRE()dnl
Packit 8f70b4
dnl FIXME: gl_absolute_header and ac_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_absolute_header],
Packit 8f70b4
                  [gl_cv_absolute_]m4_defn([gl_HEADER_NAME]))dnl
Packit 8f70b4
  AC_CACHE_CHECK([absolute name of <]m4_defn([gl_HEADER_NAME])[>],
Packit 8f70b4
    m4_defn([gl_absolute_header]),
Packit 8f70b4
    [AS_VAR_PUSHDEF([ac_header_exists],
Packit 8f70b4
                    [ac_cv_header_]m4_defn([gl_HEADER_NAME]))dnl
Packit 8f70b4
    AC_CHECK_HEADERS_ONCE(m4_defn([gl_HEADER_NAME]))dnl
Packit 8f70b4
    if test AS_VAR_GET(ac_header_exists) = yes; then
Packit 8f70b4
      gl_ABSOLUTE_HEADER_ONE(m4_defn([gl_HEADER_NAME]))
Packit 8f70b4
    fi
Packit 8f70b4
    AS_VAR_POPDEF([ac_header_exists])dnl
Packit 8f70b4
    ])dnl
Packit 8f70b4
  AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_defn([gl_HEADER_NAME])),
Packit 8f70b4
                     ["AS_VAR_GET(gl_absolute_header)"],
Packit 8f70b4
                     [Define this to an absolute name of <]m4_defn([gl_HEADER_NAME])[>.])
Packit 8f70b4
  AS_VAR_POPDEF([gl_absolute_header])dnl
Packit 8f70b4
])dnl
Packit 8f70b4
])# gl_ABSOLUTE_HEADER
Packit 8f70b4
Packit 8f70b4
# gl_ABSOLUTE_HEADER_ONE(HEADER)
Packit 8f70b4
# ------------------------------
Packit 8f70b4
# Like gl_ABSOLUTE_HEADER, except that:
Packit 8f70b4
#   - it assumes that the header exists,
Packit 8f70b4
#   - it uses the current CPPFLAGS,
Packit 8f70b4
#   - it does not cache the result,
Packit 8f70b4
#   - it is silent.
Packit 8f70b4
AC_DEFUN([gl_ABSOLUTE_HEADER_ONE],
Packit 8f70b4
[
Packit 8f70b4
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit 8f70b4
  AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote([$1])[[>]])])
Packit 8f70b4
  dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
Packit 8f70b4
  dnl that contain only a #include of other header files and no
Packit 8f70b4
  dnl non-comment tokens of their own. This leads to a failure to
Packit 8f70b4
  dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
Packit 8f70b4
  dnl and others. The workaround is to force preservation of comments
Packit 8f70b4
  dnl through option -C. This ensures all necessary #line directives
Packit 8f70b4
  dnl are present. GCC supports option -C as well.
Packit 8f70b4
  case "$host_os" in
Packit 8f70b4
    aix*) gl_absname_cpp="$ac_cpp -C" ;;
Packit 8f70b4
    *)    gl_absname_cpp="$ac_cpp" ;;
Packit 8f70b4
  esac
Packit 8f70b4
changequote(,)
Packit 8f70b4
  case "$host_os" in
Packit 8f70b4
    mingw*)
Packit 8f70b4
      dnl For the sake of native Windows compilers (excluding gcc),
Packit 8f70b4
      dnl treat backslash as a directory separator, like /.
Packit 8f70b4
      dnl Actually, these compilers use a double-backslash as
Packit 8f70b4
      dnl directory separator, inside the
Packit 8f70b4
      dnl   # line "filename"
Packit 8f70b4
      dnl directives.
Packit 8f70b4
      gl_dirsep_regex='[/\\]'
Packit 8f70b4
      ;;
Packit 8f70b4
    *)
Packit 8f70b4
      gl_dirsep_regex='\/'
Packit 8f70b4
      ;;
Packit 8f70b4
  esac
Packit 8f70b4
  dnl A sed expression that turns a string into a basic regular
Packit 8f70b4
  dnl expression, for use within "/.../".
Packit 8f70b4
  gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
Packit 8f70b4
  gl_header_literal_regex=`echo '$1' \
Packit 8f70b4
                           | sed -e "$gl_make_literal_regex_sed"`
Packit 8f70b4
  gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
Packit 8f70b4
      s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
Packit 8f70b4
      s|^/[^/]|//&|
Packit 8f70b4
      p
Packit 8f70b4
      q
Packit 8f70b4
    }'
Packit 8f70b4
changequote([,])
Packit 8f70b4
  dnl eval is necessary to expand gl_absname_cpp.
Packit 8f70b4
  dnl Ultrix and Pyramid sh refuse to redirect output of eval,
Packit 8f70b4
  dnl so use subshell.
Packit 8f70b4
  AS_VAR_SET([gl_cv_absolute_]AS_TR_SH([[$1]]),
Packit 8f70b4
[`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
Packit 8f70b4
  sed -n "$gl_absolute_header_sed"`])
Packit 8f70b4
])