1 # libunistring-base.m4 serial 4
2 dnl Copyright (C) 2010 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.
7 dnl From Paolo Bonzini and Bruno Haible.
9 dnl gl_LIBUNISTRING_LIBSOURCE([VERSION], [SourceFile])
10 dnl Declares that SourceFile should be compiled, unless we are linking
11 dnl with libunistring and its version is >= the given VERSION.
12 dnl SourceFile should be relative to the lib directory and end in '.c'.
13 dnl This macro is to be used for public libunistring API, not for
16 dnl You have to bump the VERSION argument to the next projected version
17 dnl number each time you make a change that affects the behaviour of the
18 dnl functions defined in SourceFile (even if SourceFile itself does not
21 AC_DEFUN([gl_LIBUNISTRING_LIBSOURCE],
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]); then
27 m4_foreach_w([gl_source_file], [$2],
28 [AC_LIBOBJ(m4_bpatsubst(m4_defn([gl_source_file]), [\.c$], []))
33 dnl gl_LIBUNISTRING_LIBHEADER([VERSION], [HeaderFile])
34 dnl Declares that HeaderFile should be created, unless we are linking
35 dnl with libunistring and its version is >= the given VERSION.
36 dnl HeaderFile should be relative to the lib directory and end in '.h'.
37 dnl Prepares for substituting LIBUNISTRING_HEADERFILE (to HeaderFile or empty).
39 dnl When we are linking with the already installed libunistring and its version
40 dnl is < VERSION, we create HeaderFile here, because we may compile functions
41 dnl (via gl_LIBUNISTRING_LIBSOURCE above) that are not contained in the
42 dnl installed version.
43 dnl When we are linking with the already installed libunistring and its version
44 dnl is > VERSION, we don't create HeaderFile here: it could cause compilation
45 dnl errors in other libunistring header files if some types are missing.
47 dnl You have to bump the VERSION argument to the next projected version
48 dnl number each time you make a non-comment change to the HeaderFile.
50 AC_DEFUN([gl_LIBUNISTRING_LIBHEADER],
52 AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
53 dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
54 dnl gl_LIBUNISTRING_CORE if that macro has been run.
55 if gl_LIBUNISTRING_VERSION_CMP([$1]); then
56 LIBUNISTRING_[]AS_TR_CPP([$2])='$2'
58 LIBUNISTRING_[]AS_TR_CPP([$2])=
60 AC_SUBST([LIBUNISTRING_]AS_TR_CPP([$2]))
63 dnl Miscellaneous preparations/initializations.
65 AC_DEFUN([gl_LIBUNISTRING_LIB_PREPARE],
67 dnl Ensure that HAVE_LIBUNISTRING is fully determined at this point.
68 m4_ifdef([gl_LIBUNISTRING], [AC_REQUIRE([gl_LIBUNISTRING])])
70 AC_REQUIRE([AC_PROG_AWK])
72 dnl Sed expressions to extract the parts of a version number.
74 gl_libunistring_sed_extract_major='/^[0-9]/{s/^\([0-9]*\).*/\1/p;q;}
79 gl_libunistring_sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p;q;}
84 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;}
91 if test "$HAVE_LIBUNISTRING" = yes; then
92 LIBUNISTRING_VERSION_MAJOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_major"`
93 LIBUNISTRING_VERSION_MINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_minor"`
94 LIBUNISTRING_VERSION_SUBMINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_subminor"`
98 dnl gl_LIBUNISTRING_VERSION_CMP([VERSION])
99 dnl Expands to a shell statement that evaluates to true if LIBUNISTRING_VERSION
100 dnl is less than the VERSION argument.
101 AC_DEFUN([gl_LIBUNISTRING_VERSION_CMP],
102 [ { test "$HAVE_LIBUNISTRING" != yes \
104 dnl AS_LITERAL_IF exists and works fine since autoconf-2.59 at least.
106 [dnl This is the optimized variant, that assumes the argument is a literal:
107 m4_pushdef([requested_version_major],
108 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^\([0-9]*\).*], [\1]), [])])
109 m4_pushdef([requested_version_minor],
110 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
111 m4_pushdef([requested_version_subminor],
112 [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.][0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
113 test $LIBUNISTRING_VERSION_MAJOR -lt requested_version_major \
114 || { test $LIBUNISTRING_VERSION_MAJOR -eq requested_version_major \
115 && { test $LIBUNISTRING_VERSION_MINOR -lt requested_version_minor \
116 || { test $LIBUNISTRING_VERSION_MINOR -eq requested_version_minor \
117 && test $LIBUNISTRING_VERSION_SUBMINOR -lt requested_version_subminor
121 m4_popdef([requested_version_subminor])
122 m4_popdef([requested_version_minor])
123 m4_popdef([requested_version_major])
125 [dnl This is the unoptimized variant:
126 requested_version_major=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_major"`
127 requested_version_minor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_minor"`
128 requested_version_subminor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_subminor"`
129 test $LIBUNISTRING_VERSION_MAJOR -lt $requested_version_major \
130 || { test $LIBUNISTRING_VERSION_MAJOR -eq $requested_version_major \
131 && { test $LIBUNISTRING_VERSION_MINOR -lt $requested_version_minor \
132 || { test $LIBUNISTRING_VERSION_MINOR -eq $requested_version_minor \
133 && test $LIBUNISTRING_VERSION_SUBMINOR -lt $requested_version_subminor
141 dnl gl_LIBUNISTRING_ARG_OR_ZERO([ARG], [ORIG]) expands to ARG if it is not the
142 dnl same as ORIG, otherwise to 0.
143 m4_define([gl_LIBUNISTRING_ARG_OR_ZERO], [m4_if([$1], [$2], [0], [$1])])