Debian Codegraph @

m4/libunistring-base.m4

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