onceonly.m4 3.8 KB

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