Debian Codegraph @

m4/libunistring-base.m4

raw
1 # libunistring-base.m4
2 # serial 9
3 dnl Copyright (C) 2010-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl From Paolo Bonzini and Bruno Haible.
10
11 dnl gl_LIBUNISTRING_MODULE([VERSION], [Module])
12 dnl Declares that the source files of Module should be compiled, unless we
13 dnl are linking with libunistring and its version is >= the given VERSION.
14 dnl Defines an automake conditional LIBUNISTRING_COMPILE_$MODULE that is
15 dnl true if the source files of Module should be compiled.
16 dnl This macro is to be used for public libunistring API, not for
17 dnl undocumented API.
18 dnl
19 dnl You have to bump the VERSION argument to the next projected version
20 dnl number each time you make a change that affects the behaviour of the
21 dnl functions defined in Module (even if the sources of Module itself do not
22 dnl change).
23 dnl
24 dnl This macro invocation must not occur in macros that are AC_REQUIREd.
25
26 AC_DEFUN([gl_LIBUNISTRING_MODULE],
27 [
28 AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
29 dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
30 dnl gl_LIBUNISTRING_CORE if that macro has been run.
31 gl_CONDITIONAL(AS_TR_CPP([LIBUNISTRING_COMPILE_$2]),
32 [gl_LIBUNISTRING_VERSION_CMP([$1])])
33 ])
34
35 dnl gl_LIBUNISTRING_MODULE_WITH_VARIABLE([VERSION], [Module])
36 dnl is like gl_LIBUNISTRING_MODULE([VERSION], [Module]), except that it also
37 dnl defines an AC_SUBSTed autoconf variable GNULIB_$MODULE_DLL_VARIABLE.
38 dnl What's the expansion of this autoconf variable?
39 dnl - When building libunistring, it expands to LIBUNISTRING_DLL_VARIABLE.
40 dnl (This is necessary because this token must be present in the .h files
41 dnl when the .h files get installed.)
42 dnl - When building gnulib or application code it expands to
43 dnl - LIBUNISTRING_DLL_VARIABLE by default,
44 dnl - empty if the automake conditional LIBUNISTRING_COMPILE_$MODULE
45 dnl evaluates to true.
46 dnl (This is necessary because when the conditional evaluates to false,
47 dnl the application code expects to use the declared variable from the
48 dnl installed libunistring; it's in this case that the
49 dnl LIBUNISTRING_DLL_VARIABLE macro from the installed
50 dnl <unistring/woe32dll.h> must be used.)
51 dnl
52 dnl This macro invocation must not occur in macros that are AC_REQUIREd.
53
54 AC_DEFUN([gl_LIBUNISTRING_MODULE_WITH_VARIABLE],
55 [
56 gl_LIBUNISTRING_MODULE([$1], [$2])
57 m4_ifndef([gl_IN_LIBUNISTRING],
58 [if test -z "${AS_TR_CPP([LIBUNISTRING_COMPILE_$2])_TRUE}"; then
59 GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]AS_TR_CPP([$2_DLL_VARIABLE])=
60 fi
61 ])
62 ])
63
64 dnl gl_LIBUNISTRING_LIBHEADER([VERSION], [HeaderFile])
65 dnl Declares that HeaderFile should be created, unless we are linking
66 dnl with libunistring and its version is >= the given VERSION.
67 dnl HeaderFile should be relative to the lib directory and end in '.h'.
68 dnl Prepares for substituting LIBUNISTRING_HEADERFILE (to HeaderFile or empty).
69 dnl
70 dnl When we are linking with the already installed libunistring and its version
71 dnl is < VERSION, we create HeaderFile here, because we may compile functions
72 dnl (via gl_LIBUNISTRING_MODULE above) that are not contained in the installed
73 dnl version.
74 dnl When we are linking with the already installed libunistring and its version
75 dnl is > VERSION, we don't create HeaderFile here: it could cause compilation
76 dnl errors in other libunistring header files if some types are missing.
77 dnl
78 dnl You have to bump the VERSION argument to the next projected version
79 dnl number each time you make a non-comment change to the HeaderFile.
80
81 AC_DEFUN([gl_LIBUNISTRING_LIBHEADER],
82 [
83 AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
84 dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
85 dnl gl_LIBUNISTRING_CORE if that macro has been run.
86 if gl_LIBUNISTRING_VERSION_CMP([$1]); then
87 dnl It is OK to use a .h file in lib/ from within tests/, but not vice
88 dnl versa.
89 if test -z "$LIBUNISTRING_[]AS_TR_CPP([$2])"; then
90 LIBUNISTRING_[]AS_TR_CPP([$2])="${gl_source_base_prefix}$2"
91 fi
92 else
93 LIBUNISTRING_[]AS_TR_CPP([$2])=
94 fi
95 AC_SUBST([LIBUNISTRING_]AS_TR_CPP([$2]))
96 ])
97
98 dnl Miscellaneous preparations/initializations.
99
100 AC_DEFUN([gl_LIBUNISTRING_LIB_PREPARE],
101 [
102 dnl Ensure that HAVE_LIBUNISTRING is fully determined at this point.
103 m4_ifdef([gl_LIBUNISTRING], [AC_REQUIRE([gl_LIBUNISTRING])])
104
105 AC_REQUIRE([AC_PROG_AWK])
106
107 dnl Sed expressions to extract the parts of a version number.
108 changequote(,)
109 gl_libunistring_sed_extract_major='/^[0-9]/{s/^\([0-9]*\).*/\1/p;q;}
110 i\
111 0
112 q
113 '
114 gl_libunistring_sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p;q;}
115 i\
116 0
117 q
118 '
119 gl_libunistring_sed_extract_subminor='/^[0-9][0-9]*[.][0-9][0-9]*[.][0-9]/{s/^[0-9]*[.][0-9]*[.]\([0-9]*\).*/\1/p;q;}
120 i\
121 0
122 q
123 '
124 changequote([,])
125
126 if test "$HAVE_LIBUNISTRING" = yes; then
127 LIBUNISTRING_VERSION_MAJOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_major"`
128 LIBUNISTRING_VERSION_MINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_minor"`
129 LIBUNISTRING_VERSION_SUBMINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_subminor"`
130 fi
131
132 dnl Determine whether <unistring/woe32dll.h> from an installed libunistring
133 dnl is available.
134 m4_ifdef([gl_IN_LIBUNISTRING],
135 [dnl In libunistring, all .h files that declare variables need to
136 dnl #include <unistring/woe32dll.h>. This references the file
137 dnl unistring/woe32dll.h in libunistring.
138 HAVE_UNISTRING_WOE32DLL_H=1
139 ],
140 [dnl In gnulib or in applications, we need a #include <unistring/woe32dll.h>
141 dnl if and only if an installed libunistring is available.
142 if test "$HAVE_LIBUNISTRING" = yes; then
143 AC_CHECK_HEADERS([unistring/woe32dll.h],
144 [HAVE_UNISTRING_WOE32DLL_H=1],
145 [HAVE_UNISTRING_WOE32DLL_H=0])
146 else
147 HAVE_UNISTRING_WOE32DLL_H=0
148 fi
149 ])
150 AC_SUBST([HAVE_UNISTRING_WOE32DLL_H])
151 ])
152
153 dnl gl_LIBUNISTRING_VERSION_CMP([VERSION])
154 dnl Expands to a shell statement that evaluates to true if LIBUNISTRING_VERSION
155 dnl is less than the VERSION argument.
156 AC_DEFUN([gl_LIBUNISTRING_VERSION_CMP],
157 [dnl VERSION = 999.9 means to evaluates to true always, i.e. to ignore
158 dnl the installed libunistring regardless of its version.
159 m4_if([$1], [999.9],
160 [true],
161 [ { test "$HAVE_LIBUNISTRING" != yes \
162 || {
163 dnl AS_LITERAL_IF exists and works fine since autoconf-2.59 at least.
164 AS_LITERAL_IF([$1],
165 [dnl This is the optimized variant, that assumes the argument is a literal:
166 m4_pushdef([requested_version_major],
167 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^\([0-9]*\).*], [\1]), [])])
168 m4_pushdef([requested_version_minor],
169 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
170 m4_pushdef([requested_version_subminor],
171 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.][0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
172 test $LIBUNISTRING_VERSION_MAJOR -lt requested_version_major \
173 || { test $LIBUNISTRING_VERSION_MAJOR -eq requested_version_major \
174 && { test $LIBUNISTRING_VERSION_MINOR -lt requested_version_minor \
175 || { test $LIBUNISTRING_VERSION_MINOR -eq requested_version_minor \
176 && test $LIBUNISTRING_VERSION_SUBMINOR -lt requested_version_subminor
177 }
178 }
179 }
180 m4_popdef([requested_version_subminor])
181 m4_popdef([requested_version_minor])
182 m4_popdef([requested_version_major])
183 ],
184 [dnl This is the unoptimized variant:
185 requested_version_major=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_major"`
186 requested_version_minor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_minor"`
187 requested_version_subminor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_subminor"`
188 test $LIBUNISTRING_VERSION_MAJOR -lt $requested_version_major \
189 || { test $LIBUNISTRING_VERSION_MAJOR -eq $requested_version_major \
190 && { test $LIBUNISTRING_VERSION_MINOR -lt $requested_version_minor \
191 || { test $LIBUNISTRING_VERSION_MINOR -eq $requested_version_minor \
192 && test $LIBUNISTRING_VERSION_SUBMINOR -lt $requested_version_subminor
193 }
194 }
195 }
196 ])
197 }
198 }])])
199
200 dnl gl_LIBUNISTRING_ARG_OR_ZERO([ARG], [ORIG]) expands to ARG if it is not the
201 dnl same as ORIG, otherwise to 0.
202 m4_define([gl_LIBUNISTRING_ARG_OR_ZERO], [m4_if([$1], [$2], [0], [$1])])