Blame m4/absolute-header.m4

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