absolute-header.m4 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # absolute-header.m4 serial 16
  2. dnl Copyright (C) 2006-2014 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. dnl FIXME: gl_absolute_header and ac_header_exists must be used unquoted
  24. dnl until we can assume autoconf 2.64 or newer.
  25. m4_foreach_w([gl_HEADER_NAME], [$1],
  26. [AS_VAR_PUSHDEF([gl_absolute_header],
  27. [gl_cv_absolute_]m4_defn([gl_HEADER_NAME]))dnl
  28. AC_CACHE_CHECK([absolute name of <]m4_defn([gl_HEADER_NAME])[>],
  29. m4_defn([gl_absolute_header]),
  30. [AS_VAR_PUSHDEF([ac_header_exists],
  31. [ac_cv_header_]m4_defn([gl_HEADER_NAME]))dnl
  32. AC_CHECK_HEADERS_ONCE(m4_defn([gl_HEADER_NAME]))dnl
  33. if test AS_VAR_GET(ac_header_exists) = yes; then
  34. gl_ABSOLUTE_HEADER_ONE(m4_defn([gl_HEADER_NAME]))
  35. fi
  36. AS_VAR_POPDEF([ac_header_exists])dnl
  37. ])dnl
  38. AC_DEFINE_UNQUOTED(AS_TR_CPP([ABSOLUTE_]m4_defn([gl_HEADER_NAME])),
  39. ["AS_VAR_GET(gl_absolute_header)"],
  40. [Define this to an absolute name of <]m4_defn([gl_HEADER_NAME])[>.])
  41. AS_VAR_POPDEF([gl_absolute_header])dnl
  42. ])dnl
  43. ])# gl_ABSOLUTE_HEADER
  44. # gl_ABSOLUTE_HEADER_ONE(HEADER)
  45. # ------------------------------
  46. # Like gl_ABSOLUTE_HEADER, except that:
  47. # - it assumes that the header exists,
  48. # - it uses the current CPPFLAGS,
  49. # - it does not cache the result,
  50. # - it is silent.
  51. AC_DEFUN([gl_ABSOLUTE_HEADER_ONE],
  52. [
  53. AC_REQUIRE([AC_CANONICAL_HOST])
  54. AC_LANG_CONFTEST([AC_LANG_SOURCE([[#include <]]m4_dquote([$1])[[>]])])
  55. dnl AIX "xlc -E" and "cc -E" omit #line directives for header files
  56. dnl that contain only a #include of other header files and no
  57. dnl non-comment tokens of their own. This leads to a failure to
  58. dnl detect the absolute name of <dirent.h>, <signal.h>, <poll.h>
  59. dnl and others. The workaround is to force preservation of comments
  60. dnl through option -C. This ensures all necessary #line directives
  61. dnl are present. GCC supports option -C as well.
  62. case "$host_os" in
  63. aix*) gl_absname_cpp="$ac_cpp -C" ;;
  64. *) gl_absname_cpp="$ac_cpp" ;;
  65. esac
  66. changequote(,)
  67. case "$host_os" in
  68. mingw*)
  69. dnl For the sake of native Windows compilers (excluding gcc),
  70. dnl treat backslash as a directory separator, like /.
  71. dnl Actually, these compilers use a double-backslash as
  72. dnl directory separator, inside the
  73. dnl # line "filename"
  74. dnl directives.
  75. gl_dirsep_regex='[/\\]'
  76. ;;
  77. *)
  78. gl_dirsep_regex='\/'
  79. ;;
  80. esac
  81. dnl A sed expression that turns a string into a basic regular
  82. dnl expression, for use within "/.../".
  83. gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
  84. gl_header_literal_regex=`echo '$1' \
  85. | sed -e "$gl_make_literal_regex_sed"`
  86. gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
  87. s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
  88. s|^/[^/]|//&|
  89. p
  90. q
  91. }'
  92. changequote([,])
  93. dnl eval is necessary to expand gl_absname_cpp.
  94. dnl Ultrix and Pyramid sh refuse to redirect output of eval,
  95. dnl so use subshell.
  96. AS_VAR_SET([gl_cv_absolute_]AS_TR_SH([[$1]]),
  97. [`(eval "$gl_absname_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
  98. sed -n "$gl_absolute_header_sed"`])
  99. ])