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