Debian Codegraph @

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