absolute-header.m4 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # absolute-header.m4 serial 17
  2. dnl Copyright (C) 2006-2023 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. dnl From Derek Price.
  7. # gl_ABSOLUTE_HEADER(HEADER1 HEADER2 ...)
  8. # ---------------------------------------
  9. # Find the absolute name of a header file, testing first if the header exists.
  10. # If the header were sys/inttypes.h, this macro would define
  11. # ABSOLUTE_SYS_INTTYPES_H to the '""' quoted absolute name of sys/inttypes.h
  12. # in config.h
  13. # (e.g. '#define ABSOLUTE_SYS_INTTYPES_H "///usr/include/sys/inttypes.h"').
  14. # The three "///" are to pacify Sun C 5.8, which otherwise would say
  15. # "warning: #include of /usr/include/... may be non-portable".
  16. # Use '""', not '<>', so that the /// cannot be confused with a C99 comment.
  17. # Note: This macro assumes that the header file is not empty after
  18. # preprocessing, i.e. it does not only define preprocessor macros but also
  19. # provides some type/enum definitions or function/variable declarations.
  20. AC_DEFUN([gl_ABSOLUTE_HEADER],
  21. [AC_REQUIRE([AC_CANONICAL_HOST])
  22. AC_LANG_PREPROC_REQUIRE()dnl
  23. m4_foreach_w([gl_HEADER_NAME], [$1],
  24. [AS_VAR_PUSHDEF([gl_absolute_header],
  25. [gl_cv_absolute_]m4_defn([gl_HEADER_NAME]))dnl
  26. AC_CACHE_CHECK([absolute name of <]m4_defn([gl_HEADER_NAME])[>],
  27. [gl_absolute_header],
  28. [AS_VAR_PUSHDEF([ac_header_exists],
  29. [ac_cv_header_]m4_defn([gl_HEADER_NAME]))dnl
  30. AC_CHECK_HEADERS_ONCE(m4_defn([gl_HEADER_NAME]))dnl
  31. if test AS_VAR_GET([ac_header_exists]) = yes; then
  32. gl_ABSOLUTE_HEADER_ONE(m4_defn([gl_HEADER_NAME]))
  33. fi
  34. AS_VAR_POPDEF([ac_header_exists])dnl
  35. ])dnl
  36. AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_defn([gl_HEADER_NAME])),
  37. ["AS_VAR_GET([gl_absolute_header])"],
  38. [Define this to an absolute name of <]m4_defn([gl_HEADER_NAME])[>.])
  39. AS_VAR_POPDEF([gl_absolute_header])dnl
  40. ])dnl
  41. ])# gl_ABSOLUTE_HEADER
  42. # gl_ABSOLUTE_HEADER_ONE(HEADER)
  43. # ------------------------------
  44. # Like gl_ABSOLUTE_HEADER, except that:
  45. # - it assumes that the header exists,
  46. # - it uses the current CPPFLAGS,
  47. # - it does not cache the result,
  48. # - it is silent.
  49. AC_DEFUN([gl_ABSOLUTE_HEADER_ONE],
  50. [
  51. AC_REQUIRE([AC_CANONICAL_HOST])
  52. AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote([$1])[[>]])])
  53. dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
  54. dnl that contain only a #include of other header files and no
  55. dnl non-comment tokens of their own. This leads to a failure to
  56. dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
  57. dnl and others. The workaround is to force preservation of comments
  58. dnl through option -C. This ensures all necessary #line directives
  59. dnl are present. GCC supports option -C as well.
  60. case "$host_os" in
  61. aix*) gl_absname_cpp="$ac_cpp -C" ;;
  62. *) gl_absname_cpp="$ac_cpp" ;;
  63. esac
  64. changequote(,)
  65. case "$host_os" in
  66. mingw*)
  67. dnl For the sake of native Windows compilers (excluding gcc),
  68. dnl treat backslash as a directory separator, like /.
  69. dnl Actually, these compilers use a double-backslash as
  70. dnl directory separator, inside the
  71. dnl # line "filename"
  72. dnl directives.
  73. gl_dirsep_regex='[/\\]'
  74. ;;
  75. *)
  76. gl_dirsep_regex='\/'
  77. ;;
  78. esac
  79. dnl A sed expression that turns a string into a basic regular
  80. dnl expression, for use within "/.../".
  81. gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
  82. gl_header_literal_regex=`echo '$1' \
  83. | sed -e "$gl_make_literal_regex_sed"`
  84. gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
  85. s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
  86. s|^/[^/]|//&|
  87. p
  88. q
  89. }'
  90. changequote([,])
  91. dnl eval is necessary to expand gl_absname_cpp.
  92. dnl Ultrix and Pyramid sh refuse to redirect output of eval,
  93. dnl so use subshell.
  94. AS_VAR_SET([gl_cv_absolute_]AS_TR_SH([[$1]]),
  95. [`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
  96. sed -n "$gl_absolute_header_sed"`])
  97. ])