* build-aux/bootstrap (slurp): Remove obsolescent gettext.m4 patch.
[gnulib.git] / m4 / absolute-header.m4
1 # absolute-header.m4 serial 13
2 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Derek Price.
8
9 # gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...)
10 # ---------------------------------------
11 # Find the absolute name of a header file, testing first if the header exists.
12 # If the header were sys/inttypes.h, this macro would define
13 # ABSOLUTE_SYS_INTTYPES_H to the `""' quoted absolute name of sys/inttypes.h
14 # in config.h
15 # (e.g. `#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"').
16 # The three "///" are to pacify Sun C 5.8, which otherwise would say
17 # "warning: #include of /usr/include/... may be non-portable".
18 # Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
19 # Note: This macro assumes that the header file is not empty after
20 # preprocessing, i.e. it does not only define preprocessor macros but also
21 # provides some type/enum definitions or function/variable declarations.
22 AC_DEFUN([gl_ABSOLUTE_HEADER],
23 [AC_REQUIRE([AC_CANONICAL_HOST])
24 AC_LANG_PREPROC_REQUIRE()dnl
25 dnl FIXME: gl_absolute_header and ac_header_exists must be used unquoted
26 dnl until we can assume autoconf 2.64 or newer.
27 m4_foreach_w([gl_HEADER_NAME], [$1],
28   [AS_VAR_PUSHDEF([gl_absolute_header],
29                   [gl_cv_absolute_]m4_defn([gl_HEADER_NAME]))dnl
30   AC_CACHE_CHECK([absolute name of <]m4_defn([gl_HEADER_NAME])[>],
31     m4_defn([gl_absolute_header]),
32     [AS_VAR_PUSHDEF([ac_header_exists],
33                     [ac_cv_header_]m4_defn([gl_HEADER_NAME]))dnl
34     AC_CHECK_HEADERS_ONCE(m4_defn([gl_HEADER_NAME]))dnl
35     if test AS_VAR_GET(ac_header_exists) = yes; then
36       gl_ABSOLUTE_HEADER_ONE(m4_defn([gl_HEADER_NAME]))
37     fi
38     AS_VAR_POPDEF([ac_header_exists])dnl
39     ])dnl
40   AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_defn([gl_HEADER_NAME])),
41                      ["AS_VAR_GET(gl_absolute_header)"],
42                      [Define this to an absolute name of <]m4_defn([gl_HEADER_NAME])[>.])
43   AS_VAR_POPDEF([gl_absolute_header])dnl
44 ])dnl
45 ])# gl_ABSOLUTE_HEADER
46
47 # gl_ABSOLUTE_HEADER_ONE(HEADER)
48 # ------------------------------
49 # Like gl_ABSOLUTE_HEADER, except that:
50 #   - it assumes that the header exists,
51 #   - it uses the current CPPFLAGS,
52 #   - it does not cache the result,
53 #   - it is silent.
54 AC_DEFUN([gl_ABSOLUTE_HEADER_ONE],
55 [
56   AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote([$1])[[>]])])
57   dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
58   dnl that contain only a #include of other header files and no
59   dnl non-comment tokens of their own. This leads to a failure to
60   dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
61   dnl and others. The workaround is to force preservation of comments
62   dnl through option -C. This ensures all necessary #line directives
63   dnl are present. GCC supports option -C as well.
64   case "$host_os" in
65     aix*) gl_absname_cpp="$ac_cpp -C" ;;
66     *)    gl_absname_cpp="$ac_cpp" ;;
67   esac
68   dnl eval is necessary to expand gl_absname_cpp.
69   dnl Ultrix and Pyramid sh refuse to redirect output of eval,
70   dnl so use subshell.
71   AS_VAR_SET([gl_cv_absolute_]AS_TR_SH([[$1]]),
72 [`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
73 sed -n '\#/$1#{
74         s#.*"\(.*/$1\)".*#\1#
75         s#^/[^/]#//&#
76         p
77         q
78 }'`])
79 ])