usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / m4 / absolute-header.m4
blob0abd6d9002c5972cb2e4477991ef9593de8634b9
1 # absolute-header.m4
2 # serial 18
3 dnl Copyright (C) 2006-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl From Derek Price.
10 # gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...)
11 # ---------------------------------------
12 # Find the absolute name of a header file, testing first if the header exists.
13 # If the header were sys/inttypes.h, this macro would define
14 # ABSOLUTE_SYS_INTTYPES_H to the '""' quoted absolute name of sys/inttypes.h
15 # in config.h
16 # (e.g. '#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"').
17 # The three "///" are to pacify Sun C 5.8, which otherwise would say
18 # "warning: #include of /usr/include/... may be non-portable".
19 # Use '""', not '<>', so that the /// cannot be confused with a C99 comment.
20 # Note: This macro assumes that the header file is not empty after
21 # preprocessing, i.e. it does not only define preprocessor macros but also
22 # provides some type/enum definitions or function/variable declarations.
23 AC_DEFUN([gl_ABSOLUTE_HEADER],
24 [AC_REQUIRE([AC_CANONICAL_HOST])
25 AC_LANG_PREPROC_REQUIRE()dnl
26 m4_foreach_w([gl_HEADER_NAME], [$1],
27   [AS_VAR_PUSHDEF([gl_absolute_header],
28                   [gl_cv_absolute_]m4_defn([gl_HEADER_NAME]))dnl
29   AC_CACHE_CHECK([absolute name of <]m4_defn([gl_HEADER_NAME])[>],
30     [gl_absolute_header],
31     [AS_VAR_PUSHDEF([ac_header_exists],
32                     [ac_cv_header_]m4_defn([gl_HEADER_NAME]))dnl
33     AC_CHECK_HEADERS_ONCE(m4_defn([gl_HEADER_NAME]))dnl
34     if test AS_VAR_GET([ac_header_exists]) = yes; then
35       gl_ABSOLUTE_HEADER_ONE(m4_defn([gl_HEADER_NAME]))
36     fi
37     AS_VAR_POPDEF([ac_header_exists])dnl
38     ])dnl
39   AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_defn([gl_HEADER_NAME])),
40                      ["AS_VAR_GET([gl_absolute_header])"],
41                      [Define this to an absolute name of <]m4_defn([gl_HEADER_NAME])[>.])
42   AS_VAR_POPDEF([gl_absolute_header])dnl
43 ])dnl
44 ])# gl_ABSOLUTE_HEADER
46 # gl_ABSOLUTE_HEADER_ONE(HEADER)
47 # ------------------------------
48 # Like gl_ABSOLUTE_HEADER, except that:
49 #   - it assumes that the header exists,
50 #   - it uses the current CPPFLAGS,
51 #   - it does not cache the result,
52 #   - it is silent.
53 AC_DEFUN([gl_ABSOLUTE_HEADER_ONE],
55   AC_REQUIRE([AC_CANONICAL_HOST])
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 changequote(,)
69   case "$host_os" in
70     mingw* | windows*)
71       dnl For the sake of native Windows compilers (excluding gcc),
72       dnl treat backslash as a directory separator, like /.
73       dnl Actually, these compilers use a double-backslash as
74       dnl directory separator, inside the
75       dnl   # line "filename"
76       dnl directives.
77       gl_dirsep_regex='[/\\]'
78       ;;
79     *)
80       gl_dirsep_regex='\/'
81       ;;
82   esac
83   dnl A sed expression that turns a string into a basic regular
84   dnl expression, for use within "/.../".
85   gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
86   gl_header_literal_regex=`echo '$1' \
87                            | sed -e "$gl_make_literal_regex_sed"`
88   gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
89       s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
90       s|^/[^/]|//&|
91       p
92       q
93     }'
94 changequote([,])
95   dnl eval is necessary to expand gl_absname_cpp.
96   dnl Ultrix and Pyramid sh refuse to redirect output of eval,
97   dnl so use subshell.
98   AS_VAR_SET([gl_cv_absolute_]AS_TR_SH([[$1]]),
99 [`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
100   sed -n "$gl_absolute_header_sed"`])