Blame gnulib/m4/absolute-header.m4

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