Debian Codegraph @

m4/libunistring-base.m4

raw
1 # libunistring-base.m4 serial 7
2 dnl Copyright (C) 2010-2022 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
22 AC_DEFUN([gl_LIBUNISTRING_MODULE],
23 [
24 AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
25 dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
26 dnl gl_LIBUNISTRING_CORE if that macro has been run.
27 gl_CONDITIONAL(AS_TR_CPP([LIBUNISTRING_COMPILE_$2]),
28 [gl_LIBUNISTRING_VERSION_CMP([$1])])
29 ])
30
31 dnl gl_LIBUNISTRING_LIBHEADER([VERSION], [HeaderFile])
32 dnl Declares that HeaderFile should be created, unless we are linking
33 dnl with libunistring and its version is >= the given VERSION.
34 dnl HeaderFile should be relative to the lib directory and end in '.h'.
35 dnl Prepares for substituting LIBUNISTRING_HEADERFILE (to HeaderFile or empty).
36 dnl
37 dnl When we are linking with the already installed libunistring and its version
38 dnl is < VERSION, we create HeaderFile here, because we may compile functions
39 dnl (via gl_LIBUNISTRING_MODULE above) that are not contained in the installed
40 dnl version.
41 dnl When we are linking with the already installed libunistring and its version
42 dnl is > VERSION, we don't create HeaderFile here: it could cause compilation
43 dnl errors in other libunistring header files if some types are missing.
44 dnl
45 dnl You have to bump the VERSION argument to the next projected version
46 dnl number each time you make a non-comment change to the HeaderFile.
47
48 AC_DEFUN([gl_LIBUNISTRING_LIBHEADER],
49 [
50 AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
51 dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
52 dnl gl_LIBUNISTRING_CORE if that macro has been run.
53 if gl_LIBUNISTRING_VERSION_CMP([$1]); then
54 dnl It is OK to use a .h file in lib/ from within tests/, but not vice
55 dnl versa.
56 if test -z "$LIBUNISTRING_[]AS_TR_CPP([$2])"; then
57 LIBUNISTRING_[]AS_TR_CPP([$2])="${gl_source_base_prefix}$2"
58 fi
59 else
60 LIBUNISTRING_[]AS_TR_CPP([$2])=
61 fi
62 AC_SUBST([LIBUNISTRING_]AS_TR_CPP([$2]))
63 ])
64
65 dnl Miscellaneous preparations/initializations.
66
67 AC_DEFUN([gl_LIBUNISTRING_LIB_PREPARE],
68 [
69 dnl Ensure that HAVE_LIBUNISTRING is fully determined at this point.
70 m4_ifdef([gl_LIBUNISTRING], [AC_REQUIRE([gl_LIBUNISTRING])])
71
72 AC_REQUIRE([AC_PROG_AWK])
73
74 dnl Sed expressions to extract the parts of a version number.
75 changequote(,)
76 gl_libunistring_sed_extract_major='/^[0-9]/{s/^\([0-9]*\).*/\1/p;q;}
77 i\
78 0
79 q
80 '
81 gl_libunistring_sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p;q;}
82 i\
83 0
84 q
85 '
86 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;}
87 i\
88 0
89 q
90 '
91 changequote([,])
92
93 if test "$HAVE_LIBUNISTRING" = yes; then
94 LIBUNISTRING_VERSION_MAJOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_major"`
95 LIBUNISTRING_VERSION_MINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_minor"`
96 LIBUNISTRING_VERSION_SUBMINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_subminor"`
97 fi
98 ])
99
100 dnl gl_LIBUNISTRING_VERSION_CMP([VERSION])
101 dnl Expands to a shell statement that evaluates to true if LIBUNISTRING_VERSION
102 dnl is less than the VERSION argument.
103 AC_DEFUN([gl_LIBUNISTRING_VERSION_CMP],
104 [ { test "$HAVE_LIBUNISTRING" != yes \
105 || {
106 dnl AS_LITERAL_IF exists and works fine since autoconf-2.59 at least.
107 AS_LITERAL_IF([$1],
108 [dnl This is the optimized variant, that assumes the argument is a literal:
109 m4_pushdef([requested_version_major],
110 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^\([0-9]*\).*], [\1]), [])])
111 m4_pushdef([requested_version_minor],
112 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
113 m4_pushdef([requested_version_subminor],
114 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.][0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
115 test $LIBUNISTRING_VERSION_MAJOR -lt requested_version_major \
116 || { test $LIBUNISTRING_VERSION_MAJOR -eq requested_version_major \
117 && { test $LIBUNISTRING_VERSION_MINOR -lt requested_version_minor \
118 || { test $LIBUNISTRING_VERSION_MINOR -eq requested_version_minor \
119 && test $LIBUNISTRING_VERSION_SUBMINOR -lt requested_version_subminor
120 }
121 }
122 }
123 m4_popdef([requested_version_subminor])
124 m4_popdef([requested_version_minor])
125 m4_popdef([requested_version_major])
126 ],
127 [dnl This is the unoptimized variant:
128 requested_version_major=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_major"`
129 requested_version_minor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_minor"`
130 requested_version_subminor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_subminor"`
131 test $LIBUNISTRING_VERSION_MAJOR -lt $requested_version_major \
132 || { test $LIBUNISTRING_VERSION_MAJOR -eq $requested_version_major \
133 && { test $LIBUNISTRING_VERSION_MINOR -lt $requested_version_minor \
134 || { test $LIBUNISTRING_VERSION_MINOR -eq $requested_version_minor \
135 && test $LIBUNISTRING_VERSION_SUBMINOR -lt $requested_version_subminor
136 }
137 }
138 }
139 ])
140 }
141 }])
142
143 dnl gl_LIBUNISTRING_ARG_OR_ZERO([ARG], [ORIG]) expands to ARG if it is not the
144 dnl same as ORIG, otherwise to 0.
145 m4_define([gl_LIBUNISTRING_ARG_OR_ZERO], [m4_if([$1], [$2], [0], [$1])])