onceonly.m4 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # onceonly.m4 serial 7
  2. dnl Copyright (C) 2002-2003, 2005-2006, 2008-2011 Free Software Foundation,
  3. dnl Inc.
  4. dnl This file is free software, distributed under the terms of the GNU
  5. dnl General Public License. As a special exception to the GNU General
  6. dnl Public License, this file may be distributed as part of a program
  7. dnl that contains a configuration script generated by Autoconf, under
  8. dnl the same distribution terms as the rest of that program.
  9. dnl This file defines some "once only" variants of standard autoconf macros.
  10. dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS
  11. dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS
  12. dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS
  13. dnl AC_REQUIRE([AC_FUNC_STRCOLL]) like AC_FUNC_STRCOLL
  14. dnl The advantage is that the check for each of the headers/functions/decls
  15. dnl will be put only once into the 'configure' file. It keeps the size of
  16. dnl the 'configure' file down, and avoids redundant output when 'configure'
  17. dnl is run.
  18. dnl The drawback is that the checks cannot be conditionalized. If you write
  19. dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi
  20. dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to
  21. dnl empty, and the check will be inserted before the body of the AC_DEFUNed
  22. dnl function.
  23. dnl The original code implemented AC_CHECK_HEADERS_ONCE and AC_CHECK_FUNCS_ONCE
  24. dnl in terms of AC_DEFUN and AC_REQUIRE. This implementation uses diversions to
  25. dnl named sections DEFAULTS and INIT_PREPARE in order to check all requested
  26. dnl headers at once, thus reducing the size of 'configure'. It is known to work
  27. dnl with autoconf 2.57..2.62 at least . The size reduction is ca. 9%.
  28. dnl Autoconf version 2.59 plus gnulib is required; this file is not needed
  29. dnl with Autoconf 2.60 or greater. But note that autoconf's implementation of
  30. dnl AC_CHECK_DECLS_ONCE expects a comma-separated list of symbols as first
  31. dnl argument!
  32. AC_PREREQ([2.59])
  33. # AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of
  34. # AC_CHECK_HEADERS(HEADER1 HEADER2 ...).
  35. AC_DEFUN([AC_CHECK_HEADERS_ONCE], [
  36. :
  37. m4_foreach_w([gl_HEADER_NAME], [$1], [
  38. AC_DEFUN([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME,
  39. [./-], [___])), [
  40. m4_divert_text([INIT_PREPARE],
  41. [gl_header_list="$gl_header_list gl_HEADER_NAME"])
  42. gl_HEADERS_EXPANSION
  43. AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])),
  44. [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.])
  45. ])
  46. AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(m4_translit(gl_HEADER_NAME,
  47. [./-], [___])))
  48. ])
  49. ])
  50. m4_define([gl_HEADERS_EXPANSION], [
  51. m4_divert_text([DEFAULTS], [gl_header_list=])
  52. AC_CHECK_HEADERS([$gl_header_list])
  53. m4_define([gl_HEADERS_EXPANSION], [])
  54. ])
  55. # AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of
  56. # AC_CHECK_FUNCS(FUNC1 FUNC2 ...).
  57. AC_DEFUN([AC_CHECK_FUNCS_ONCE], [
  58. :
  59. m4_foreach_w([gl_FUNC_NAME], [$1], [
  60. AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [
  61. m4_divert_text([INIT_PREPARE],
  62. [gl_func_list="$gl_func_list gl_FUNC_NAME"])
  63. gl_FUNCS_EXPANSION
  64. AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_FUNC_NAME])),
  65. [Define to 1 if you have the `]m4_defn([gl_FUNC_NAME])[' function.])
  66. ])
  67. AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]))
  68. ])
  69. ])
  70. m4_define([gl_FUNCS_EXPANSION], [
  71. m4_divert_text([DEFAULTS], [gl_func_list=])
  72. AC_CHECK_FUNCS([$gl_func_list])
  73. m4_define([gl_FUNCS_EXPANSION], [])
  74. ])
  75. # AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of
  76. # AC_CHECK_DECLS(DECL1, DECL2, ...).
  77. AC_DEFUN([AC_CHECK_DECLS_ONCE], [
  78. :
  79. m4_foreach_w([gl_DECL_NAME], [$1], [
  80. AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [
  81. AC_CHECK_DECLS(m4_defn([gl_DECL_NAME]))
  82. ])
  83. AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]))
  84. ])
  85. ])