Document a pitfall.
[gnulib.git] / m4 / absolute-header.m4
1 # absolute-header.m4 serial 8
2 dnl Copyright (C) 2006-2008 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, assuming 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_LANG_PREPROC_REQUIRE()dnl
24 AC_FOREACH([gl_HEADER_NAME], [$1],
25   [AS_VAR_PUSHDEF([gl_absolute_header],
26                   [gl_cv_absolute_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl
27   AC_CACHE_CHECK([absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>],
28     m4_quote(m4_defn([gl_absolute_header])),
29     [AS_VAR_PUSHDEF([ac_header_exists],
30                     [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))dnl
31     AC_CHECK_HEADERS_ONCE(m4_quote(m4_defn([gl_HEADER_NAME])))dnl
32     if test AS_VAR_GET(ac_header_exists) = yes; then
33       AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]])])
34 dnl eval is necessary to expand ac_cpp.
35 dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
36       AS_VAR_SET(gl_absolute_header,
37 [`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
38 sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
39         s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
40         s#^/[^/]#//&#
41         p
42         q
43 }'`])
44     fi
45     AS_VAR_POPDEF([ac_header_exists])dnl
46     ])dnl
47   AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_quote(m4_defn([gl_HEADER_NAME]))),
48                      ["AS_VAR_GET(gl_absolute_header)"],
49                      [Define this to an absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>.])
50   AS_VAR_POPDEF([gl_absolute_header])dnl
51 ])dnl
52 ])# gl_ABSOLUTE_HEADER