Debian Codegraph @

m4/libunistring-base.m4

raw
1 # libunistring-base.m4
2 # serial 10
3 dnl Copyright (C) 2010-2026 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 - if the automake conditional LIBUNISTRING_COMPILE_$MODULE evaluates
45 dnl to true: the value of
46 dnl ${module_indicator_prefix}_GNULIB_LIBUNISTRING_DLL_VARIABLE_NAME
47 dnl (which usually is empty, unless explicitly set in configure.ac).
48 dnl (This is necessary because when the conditional evaluates to false,
49 dnl the application code expects to use the declared variable from the
50 dnl installed libunistring; it's in this case that the
51 dnl LIBUNISTRING_DLL_VARIABLE macro from the installed
52 dnl <unistring/woe32dll.h> must be used.)
53 dnl
54 dnl This macro invocation must not occur in macros that are AC_REQUIREd.
55
56 AC_DEFUN([gl_LIBUNISTRING_MODULE_WITH_VARIABLE],
57 [
58 gl_LIBUNISTRING_MODULE([$1], [$2])
59 m4_ifndef([gl_IN_LIBUNISTRING],
60 [if test -z "${AS_TR_CPP([LIBUNISTRING_COMPILE_$2])_TRUE}"; then
61 GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]AS_TR_CPP([$2_DLL_VARIABLE])=$GL_MODULE_INDICATOR_PREFIX[]_GNULIB_LIBUNISTRING_DLL_VARIABLE_NAME
62 fi
63 ])
64 ])
65
66 dnl gl_LIBUNISTRING_LIBHEADER([VERSION], [HeaderFile])
67 dnl Declares that HeaderFile should be created, unless we are linking
68 dnl with libunistring and its version is >= the given VERSION.
69 dnl HeaderFile should be relative to the lib directory and end in '.h'.
70 dnl Prepares for substituting LIBUNISTRING_HEADERFILE (to HeaderFile or empty).
71 dnl
72 dnl When we are linking with the already installed libunistring and its version
73 dnl is < VERSION, we create HeaderFile here, because we may compile functions
74 dnl (via gl_LIBUNISTRING_MODULE above) that are not contained in the installed
75 dnl version.
76 dnl When we are linking with the already installed libunistring and its version
77 dnl is > VERSION, we don't create HeaderFile here: it could cause compilation
78 dnl errors in other libunistring header files if some types are missing.
79 dnl
80 dnl You have to bump the VERSION argument to the next projected version
81 dnl number each time you make a non-comment change to the HeaderFile.
82
83 AC_DEFUN([gl_LIBUNISTRING_LIBHEADER],
84 [
85 AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
86 dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
87 dnl gl_LIBUNISTRING_CORE if that macro has been run.
88 if gl_LIBUNISTRING_VERSION_CMP([$1]); then
89 dnl It is OK to use a .h file in lib/ from within tests/, but not vice
90 dnl versa.
91 if test -z "$LIBUNISTRING_[]AS_TR_CPP([$2])"; then
92 LIBUNISTRING_[]AS_TR_CPP([$2])="${gl_source_base_prefix}$2"
93 fi
94 else
95 LIBUNISTRING_[]AS_TR_CPP([$2])=
96 fi
97 AC_SUBST([LIBUNISTRING_]AS_TR_CPP([$2]))
98 ])
99
100 dnl Miscellaneous preparations/initializations.
101
102 AC_DEFUN([gl_LIBUNISTRING_LIB_PREPARE],
103 [
104 dnl Ensure that HAVE_LIBUNISTRING is fully determined at this point.
105 m4_ifdef([gl_LIBUNISTRING], [AC_REQUIRE([gl_LIBUNISTRING])])
106
107 AC_REQUIRE([AC_PROG_AWK])
108
109 dnl Sed expressions to extract the parts of a version number.
110 changequote(,)
111 gl_libunistring_sed_extract_major='/^[0-9]/{s/^\([0-9]*\).*/\1/p;q;}
112 i\
113 0
114 q
115 '
116 gl_libunistring_sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p;q;}
117 i\
118 0
119 q
120 '
121 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;}
122 i\
123 0
124 q
125 '
126 changequote([,])
127
128 if test "$HAVE_LIBUNISTRING" = yes; then
129 LIBUNISTRING_VERSION_MAJOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_major"`
130 LIBUNISTRING_VERSION_MINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_minor"`
131 LIBUNISTRING_VERSION_SUBMINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_subminor"`
132 fi
133
134 dnl Determine whether <unistring/woe32dll.h> from an installed libunistring
135 dnl is available.
136 m4_ifdef([gl_IN_LIBUNISTRING],
137 [dnl In libunistring, all .h files that declare variables need to
138 dnl #include <unistring/woe32dll.h>. This references the file
139 dnl unistring/woe32dll.h in libunistring.
140 HAVE_UNISTRING_WOE32DLL_H=1
141 ],
142 [dnl In gnulib or in applications, we need a #include <unistring/woe32dll.h>
143 dnl if and only if an installed libunistring is available.
144 if test "$HAVE_LIBUNISTRING" = yes; then
145 AC_CHECK_HEADERS([unistring/woe32dll.h],
146 [HAVE_UNISTRING_WOE32DLL_H=1],
147 [HAVE_UNISTRING_WOE32DLL_H=0])
148 else
149 HAVE_UNISTRING_WOE32DLL_H=0
150 fi
151 ])
152 AC_SUBST([HAVE_UNISTRING_WOE32DLL_H])
153 ])
154
155 dnl gl_LIBUNISTRING_VERSION_CMP([VERSION])
156 dnl Expands to a shell statement that evaluates to true if LIBUNISTRING_VERSION
157 dnl is less than the VERSION argument.
158 AC_DEFUN([gl_LIBUNISTRING_VERSION_CMP],
159 [dnl VERSION = 999.9 means to evaluates to true always, i.e. to ignore
160 dnl the installed libunistring regardless of its version.
161 m4_if([$1], [999.9],
162 [true],
163 [ { test "$HAVE_LIBUNISTRING" != yes \
164 || {
165 dnl AS_LITERAL_IF exists and works fine since autoconf-2.59 at least.
166 AS_LITERAL_IF([$1],
167 [dnl This is the optimized variant, that assumes the argument is a literal:
168 m4_pushdef([requested_version_major],
169 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^\([0-9]*\).*], [\1]), [])])
170 m4_pushdef([requested_version_minor],
171 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
172 m4_pushdef([requested_version_subminor],
173 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.][0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
174 test $LIBUNISTRING_VERSION_MAJOR -lt requested_version_major \
175 || { test $LIBUNISTRING_VERSION_MAJOR -eq requested_version_major \
176 && { test $LIBUNISTRING_VERSION_MINOR -lt requested_version_minor \
177 || { test $LIBUNISTRING_VERSION_MINOR -eq requested_version_minor \
178 && test $LIBUNISTRING_VERSION_SUBMINOR -lt requested_version_subminor
179 }
180 }
181 }
182 m4_popdef([requested_version_subminor])
183 m4_popdef([requested_version_minor])
184 m4_popdef([requested_version_major])
185 ],
186 [dnl This is the unoptimized variant:
187 requested_version_major=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_major"`
188 requested_version_minor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_minor"`
189 requested_version_subminor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_subminor"`
190 test $LIBUNISTRING_VERSION_MAJOR -lt $requested_version_major \
191 || { test $LIBUNISTRING_VERSION_MAJOR -eq $requested_version_major \
192 && { test $LIBUNISTRING_VERSION_MINOR -lt $requested_version_minor \
193 || { test $LIBUNISTRING_VERSION_MINOR -eq $requested_version_minor \
194 && test $LIBUNISTRING_VERSION_SUBMINOR -lt $requested_version_subminor
195 }
196 }
197 }
198 ])
199 }
200 }])])
201
202 dnl gl_LIBUNISTRING_ARG_OR_ZERO([ARG], [ORIG]) expands to ARG if it is not the
203 dnl same as ORIG, otherwise to 0.
204 m4_define([gl_LIBUNISTRING_ARG_OR_ZERO], [m4_if([$1], [$2], [0], [$1])])