Update Gnulib to v0.0-3955-g8ab5996.
[bpt/guile.git] / m4 / libunistring-base.m4
CommitLineData
a927b6c1
LC
1# libunistring-base.m4 serial 2
2dnl Copyright (C) 2010 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Paolo Bonzini and Bruno Haible.
8
9dnl gl_LIBUNISTRING_LIBSOURCE([VERSION], [SourceFile])
10dnl Declares that SourceFile should be compiled, unless we are linking
11dnl with libunistring and its version is >= the given VERSION.
12dnl SourceFile should be relative to the lib directory and end in '.c'.
13dnl This macro is to be used for public libunistring API, not for
14dnl undocumented API.
15dnl
16dnl You have to bump the VERSION argument to the next projected version
17dnl number each time you make a change that affects the behaviour of the
18dnl functions defined in SourceFile (even if SourceFile itself does not
19dnl change).
20
21AC_DEFUN([gl_LIBUNISTRING_LIBSOURCE],
22[
23 AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
24 dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
25 dnl gl_LIBUNISTRING_CORE if that macro has been run.
26 if gl_LIBUNISTRING_VERSION_CMP([$1])
27 then
28 m4_foreach_w([gl_source_file], [$2],
29 [AC_LIBOBJ(m4_bpatsubst(m4_defn([gl_source_file]), [\.c$], []))
30 ])
31 fi
32])
33
34dnl gl_LIBUNISTRING_LIBHEADER([VERSION], [HeaderFile])
35dnl Declares that HeaderFile should be created, unless we are linking
36dnl with libunistring and its version is >= the given VERSION.
37dnl HeaderFile should be relative to the lib directory and end in '.h'.
38dnl Prepares for substituting LIBUNISTRING_HEADERFILE (to HeaderFile or empty).
39dnl
40dnl When we are linking with the already installed libunistring and its version
41dnl is < VERSION, we create HeaderFile here, because we may compile functions
42dnl (via gl_LIBUNISTRING_LIBSOURCE above) that are not contained in the
43dnl installed version.
44dnl When we are linking with the already installed libunistring and its version
45dnl is > VERSION, we don't create HeaderFile here: it could cause compilation
46dnl errors in other libunistring header files if some types are missing.
47dnl
48dnl You have to bump the VERSION argument to the next projected version
49dnl number each time you make a non-comment change to the HeaderFile.
50
51AC_DEFUN([gl_LIBUNISTRING_LIBHEADER],
52[
53 AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
54 dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
55 dnl gl_LIBUNISTRING_CORE if that macro has been run.
56 if gl_LIBUNISTRING_VERSION_CMP([$1])
57 then
58 LIBUNISTRING_[]AS_TR_CPP([$2])='$2'
59 else
60 LIBUNISTRING_[]AS_TR_CPP([$2])=
61 fi
62 AC_SUBST([LIBUNISTRING_]AS_TR_CPP([$2]))
63])
64
65dnl Miscellaneous preparations/initializations.
66
67AC_DEFUN([gl_LIBUNISTRING_LIB_PREPARE],
68[
69 AC_REQUIRE([AC_PROG_AWK])
70
71dnl Sed expressions to extract the parts of a version number.
72changequote(,)
73gl_libunistring_sed_extract_major='/^[0-9]/{s/^\([0-9]*\).*/\1/p;q;}
74i\
750
76q
77'
78gl_libunistring_sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p;q;}
79i\
800
81q
82'
83gl_libunistring_sed_extract_subminor='/^[0-9][0-9]*[.][0-9][0-9]*[.][0-9]/{s/^[0-9]*[.][0-9]*[.]\([0-9]*\).*/\1/p;q;}
84i\
850
86q
87'
88changequote([,])
89
90 if test "$HAVE_LIBUNISTRING" = yes; then
91 LIBUNISTRING_VERSION_MAJOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_major"`
92 LIBUNISTRING_VERSION_MINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_minor"`
93 LIBUNISTRING_VERSION_SUBMINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_subminor"`
94 fi
95])
96
97dnl gl_LIBUNISTRING_VERSION_CMP([VERSION])
98dnl Expands to a shell statement that evaluates to true if LIBUNISTRING_VERSION
99dnl is less than the VERSION argument.
100AC_DEFUN([gl_LIBUNISTRING_VERSION_CMP],
101[ { test "$HAVE_LIBUNISTRING" != yes \
102 || {
103 dnl AS_LITERAL_IF exists and works fine since autoconf-2.59 at least.
104 AS_LITERAL_IF([$1],
105 [dnl This is the optimized variant, that assumes the argument is a literal:
106 m4_pushdef([requested_version_major],
107 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^\([0-9]*\).*], [\1]), [])])
108 m4_pushdef([requested_version_minor],
109 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
110 m4_pushdef([requested_version_subminor],
111 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.][0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
112 test $LIBUNISTRING_VERSION_MAJOR -lt requested_version_major \
113 || { test $LIBUNISTRING_VERSION_MAJOR -eq requested_version_major \
114 && { test $LIBUNISTRING_VERSION_MINOR -lt requested_version_minor \
115 || { test $LIBUNISTRING_VERSION_MINOR -eq requested_version_minor \
116 && test $LIBUNISTRING_VERSION_SUBMINOR -lt requested_version_subminor
117 }
118 }
119 }
120 m4_popdef([requested_version_subminor])
121 m4_popdef([requested_version_minor])
122 m4_popdef([requested_version_major])
123 ],
124 [dnl This is the unoptimized variant:
125 requested_version_major=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_major"`
126 requested_version_minor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_minor"`
127 requested_version_subminor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_subminor"`
128 test $LIBUNISTRING_VERSION_MAJOR -lt $requested_version_major \
129 || { test $LIBUNISTRING_VERSION_MAJOR -eq $requested_version_major \
130 && { test $LIBUNISTRING_VERSION_MINOR -lt $requested_version_minor \
131 || { test $LIBUNISTRING_VERSION_MINOR -eq $requested_version_minor \
132 && test $LIBUNISTRING_VERSION_SUBMINOR -lt $requested_version_subminor
133 }
134 }
135 }
136 ])
137 }
138 }
139])
140
141dnl gl_LIBUNISTRING_ARG_OR_ZERO([ARG], [ORIG]) expands to ARG if it is not the
142dnl same as ORIG, otherwise to 0.
143m4_define([gl_LIBUNISTRING_ARG_OR_ZERO], [m4_if([$1], [$2], [0], [$1])])