include_next.m4 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # include_next.m4 serial 4
  2. dnl Copyright (C) 2006, 2007 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 Paul Eggert and Derek Price.
  7. AC_DEFUN([gl_INCLUDE_NEXT],
  8. [
  9. AC_LANG_PREPROC_REQUIRE()
  10. AC_CACHE_CHECK([whether the preprocessor supports include_next],
  11. [gl_cv_have_include_next],
  12. [rm -rf conftestd1 conftestd2
  13. mkdir conftestd1 conftestd2
  14. cat <<EOF > conftestd1/conftest.h
  15. #define DEFINED_IN_CONFTESTD1
  16. #include_next <conftest.h>
  17. #ifdef DEFINED_IN_CONFTESTD2
  18. int foo;
  19. #else
  20. #error "include_next doesn't work"
  21. #endif
  22. EOF
  23. cat <<EOF > conftestd2/conftest.h
  24. #ifndef DEFINED_IN_CONFTESTD1
  25. #error "include_next test doesn't work"
  26. #endif
  27. #define DEFINED_IN_CONFTESTD2
  28. EOF
  29. save_CPPFLAGS="$CPPFLAGS"
  30. CPPFLAGS="$CPPFLAGS -Iconftestd1 -Iconftestd2"
  31. AC_COMPILE_IFELSE([#include <conftest.h>],
  32. [gl_cv_have_include_next=yes],
  33. [gl_cv_have_include_next=no])
  34. CPPFLAGS="$save_CPPFLAGS"
  35. rm -rf conftestd1 conftestd2
  36. ])
  37. if test $gl_cv_have_include_next = yes; then
  38. dnl FIXME: Remove HAVE_INCLUDE_NEXT and update everything that uses it
  39. dnl to use @INCLUDE_NEXT@ instead.
  40. AC_DEFINE([HAVE_INCLUDE_NEXT], 1,
  41. [Define if your compiler supports the #include_next directive.])
  42. INCLUDE_NEXT=include_next
  43. else
  44. INCLUDE_NEXT=include
  45. fi
  46. AC_SUBST([INCLUDE_NEXT])
  47. ])
  48. # gl_CHECK_NEXT_HEADERS(HEADER1 HEADER2 ...)
  49. # ------------------------------------------
  50. # For each arg foo.h, if #include_next works, define NEXT_FOO_H to be
  51. # '<foo.h>'; otherwise define it to be
  52. # '"///usr/include/foo.h"', or whatever other absolute file name is suitable.
  53. # That way, a header file with the following line:
  54. # #@INCLUDE_NEXT@ @NEXT_FOO_H@
  55. # behaves (after sed substitution) as if it contained
  56. # #include_next <foo.h>
  57. # even if the compiler does not support include_next.
  58. # The three "///" are to pacify Sun C 5.8, which otherwise would say
  59. # "warning: #include of /usr/include/... may be non-portable".
  60. # Use `""', not `<>', so that the /// cannot be confused with a C99 comment.
  61. AC_DEFUN([gl_CHECK_NEXT_HEADERS],
  62. [
  63. AC_REQUIRE([gl_INCLUDE_NEXT])
  64. AC_CHECK_HEADERS_ONCE([$1])
  65. AC_FOREACH([gl_HEADER_NAME], [$1],
  66. [AS_VAR_PUSHDEF([gl_next_header],
  67. [gl_cv_next_]m4_quote(m4_defn([gl_HEADER_NAME])))
  68. if test $gl_cv_have_include_next = yes; then
  69. AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
  70. else
  71. AC_CACHE_CHECK(
  72. [absolute name of <]m4_quote(m4_defn([gl_HEADER_NAME]))[>],
  73. m4_quote(m4_defn([gl_next_header])),
  74. [AS_VAR_PUSHDEF([gl_header_exists],
  75. [ac_cv_header_]m4_quote(m4_defn([gl_HEADER_NAME])))
  76. if test AS_VAR_GET(gl_header_exists) = yes; then
  77. AC_LANG_CONFTEST(
  78. [AC_LANG_SOURCE(
  79. [[#include <]]m4_dquote(m4_defn([gl_HEADER_NAME]))[[>]]
  80. )])
  81. dnl eval is necessary to expand ac_cpp.
  82. dnl Ultrix and Pyramid sh refuse to redirect output of eval,
  83. dnl so use subshell.
  84. AS_VAR_SET([gl_next_header],
  85. ['"'`(eval "$ac_cpp conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
  86. sed -n '\#/]m4_quote(m4_defn([gl_HEADER_NAME]))[#{
  87. s#.*"\(.*/]m4_quote(m4_defn([gl_HEADER_NAME]))[\)".*#\1#
  88. s#^/[^/]#//&#
  89. p
  90. q
  91. }'`'"'])
  92. else
  93. AS_VAR_SET([gl_next_header], ['<'gl_HEADER_NAME'>'])
  94. fi
  95. AS_VAR_POPDEF([gl_header_exists])])
  96. fi
  97. AC_SUBST(
  98. AS_TR_CPP([NEXT_]m4_quote(m4_defn([gl_HEADER_NAME]))),
  99. [AS_VAR_GET([gl_next_header])])
  100. AS_VAR_POPDEF([gl_next_header])])
  101. ])