bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 00/15] Add libunistring-optional module


From: Bruno Haible
Subject: Re: [PATCH 00/15] Add libunistring-optional module
Date: Tue, 18 May 2010 20:12:47 +0200
User-agent: KMail/1.9.9

Hi Paolo,

Adding to the discussion from 2010-04-11: One point we did not think about
is versioning. New versions of libunistring are released with enhanced
functionality (more functions, or bug fixes). If the using package requires
that functionality, it imposes a constraint on the libunistring version
that it can use. This is also needed by the unit tests: If a package
includes the module u8_stpncpy as optional, it may also contain its unit
test (written for version 0.9.3). But that unit test is known to fail
with a function u8_stpncpy from version 0.9.2.1.

Here's what I'm committing, based on your original patches. This shows only
the non-repetitive part of the commit. For the entire commit, please look
in git.


2010-05-18  Paolo Bonzini  <address@hidden>
            Bruno Haible  <address@hidden>

        New module 'libunistring-optional'.
        * modules/libunistring-optional: New file.
        * m4/libunistring-base.m4: New file.
        * m4/libunistring-optional.m4: New file.
        * lib/unicase.in.h: Renamed from lib/unicase.h.
        * lib/uniconv.in.h: Renamed from lib/uniconv.h.
        * lib/unictype.in.h: Renamed from lib/unictype.h.
        * lib/unilbrk.in.h: Renamed from lib/unilbrk.h.
        * lib/uniname.in.h: Renamed from lib/uniname.h.
        * lib/uninorm.in.h: Renamed from lib/uninorm.h.
        * lib/unistdio.in.h: Renamed from lib/unistdio.h.
        * lib/unistr.in.h: Renamed from lib/unistr.h.
        * lib/unitypes.in.h: Renamed from lib/unitypes.h.
        * lib/uniwbrk.in.h: Renamed from lib/uniwbrk.h.
        * lib/uniwidth.in.h: Renamed from lib/uniwidth.h.
        * m4/libunistring.m4 (gl_LIBUNISTRING_CORE): Renamed from
        gl_LIBUNISTRING. If the library was found, determine the installed
        version and set LIBUNISTRING_VERSION.
        (gl_LIBUNISTRING): New macro, as a wrapper arount it. Document that it
        sets LIBUNISTRING_VERSION. If the module libunistring-optional is used,
        handle a configuration option --with-included-libunistring.
        * modules/libunistring (Files): Add m4/absolute-header.m4.

======================== modules/libunistring-optional ========================
Description:
Try to use system libunistring for Unicode string functions.

Files:
m4/libunistring-optional.m4
m4/libunistring.m4
m4/absolute-header.m4

Depends-on:
havelib
iconv

configure.ac:
gl_LIBUNISTRING_OPTIONAL

Makefile.am:

Include:

Link:
$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise

License:
LGPL

Maintainer:
Paolo Bonzini, Bruno Haible

=========================== m4/libunistring-base.m4 ===========================
# libunistring-base.m4 serial 1
dnl Copyright (C) 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl From Paolo Bonzini and Bruno Haible.

dnl gl_LIBUNISTRING_LIBSOURCE([VERSION], [SourceFile])
dnl Declares that SourceFile should be compiled, unless we are linking
dnl with libunistring and its version is >= the given VERSION.
dnl SourceFile should be relative to the lib directory and end in '.c'.
dnl This macro is to be used for public libunistring API, not for
dnl undocumented API.
dnl
dnl You have to bump the VERSION argument to the next projected version
dnl number each time you make a change that affects the behaviour of the
dnl functions defined in SourceFile (even if SourceFile itself does not
dnl change).

AC_DEFUN([gl_LIBUNISTRING_LIBSOURCE],
[
  AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
  dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
  dnl gl_LIBUNISTRING_CORE if that macro has been run.
  if gl_LIBUNISTRING_VERSION_CMP([$1])
  then
    m4_foreach_w([gl_source_file], [$2],
      [AC_LIBOBJ(m4_bpatsubst(m4_defn([gl_source_file]), [\.c$], []))
      ])
  fi
])

dnl gl_LIBUNISTRING_LIBHEADER([VERSION], [HeaderFile])
dnl Declares that HeaderFile should be created, unless we are linking
dnl with libunistring and its version is >= the given VERSION.
dnl HeaderFile should be relative to the lib directory and end in '.h'.
dnl Prepares for substituting LIBUNISTRING_HEADERFILE (to HeaderFile or empty).
dnl
dnl When we are linking with the already installed libunistring and its version
dnl is < VERSION, we create HeaderFile here, because we may compile functions
dnl (via gl_LIBUNISTRING_LIBSOURCE above) that are not contained in the
dnl installed version.
dnl When we are linking with the already installed libunistring and its version
dnl is > VERSION, we don't create HeaderFile here: it could cause compilation
dnl errors in other libunistring header files if some types are missing.
dnl
dnl You have to bump the VERSION argument to the next projected version
dnl number each time you make a non-comment change to the HeaderFile.

AC_DEFUN([gl_LIBUNISTRING_LIBHEADER],
[
  AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
  dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
  dnl gl_LIBUNISTRING_CORE if that macro has been run.
  if gl_LIBUNISTRING_VERSION_CMP([$1])
  then
    LIBUNISTRING_[]AS_TR_CPP([$2])='$2'
  else
    LIBUNISTRING_[]AS_TR_CPP([$2])=
  fi
  AC_SUBST([LIBUNISTRING_]AS_TR_CPP([$2]))
])

dnl Miscellaneous preparations/initializations.

AC_DEFUN([gl_LIBUNISTRING_LIB_PREPARE],
[
  AC_REQUIRE([AC_PROG_AWK])

dnl Sed expressions to extract the parts of a version number.
changequote(,)
gl_libunistring_sed_extract_major='/^[0-9]/{s/^\([0-9]*\).*/\1/p;q;}
i\
0
q
'
gl_libunistring_sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p;q;}
i\
0
q
'
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;}
i\
0
q
'
changequote([,])

  if test "$HAVE_LIBUNISTRING" = yes; then
    LIBUNISTRING_VERSION_MAJOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e 
"$gl_libunistring_sed_extract_major"`
    LIBUNISTRING_VERSION_MINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e 
"$gl_libunistring_sed_extract_minor"`
    LIBUNISTRING_VERSION_SUBMINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e 
"$gl_libunistring_sed_extract_subminor"`
  fi
])

dnl gl_LIBUNISTRING_VERSION_CMP([VERSION])
dnl Expands to a shell statement that evaluates to true if LIBUNISTRING_VERSION
dnl is less than the VERSION argument.
dnl This is the unoptimized variant:
AC_DEFUN([gl_LIBUNISTRING_VERSION_CMP_ORIG],
[ { test "$HAVE_LIBUNISTRING" != yes \
    || {
         requested_version_major=`echo '$1' | sed -n -e 
"$gl_libunistring_sed_extract_major"`
         requested_version_minor=`echo '$1' | sed -n -e 
"$gl_libunistring_sed_extract_minor"`
         requested_version_subminor=`echo '$1' | sed -n -e 
"$gl_libunistring_sed_extract_subminor"`
         test $LIBUNISTRING_VERSION_MAJOR -lt $requested_version_major \
         || { test $LIBUNISTRING_VERSION_MAJOR -eq $requested_version_major \
              && { test $LIBUNISTRING_VERSION_MINOR -lt 
$requested_version_minor \
                   || { test $LIBUNISTRING_VERSION_MINOR -eq 
$requested_version_minor \
                        && test $LIBUNISTRING_VERSION_SUBMINOR -lt 
$requested_version_subminor
                      }
                 }
            }
       }
  }
])
dnl This is the optimized variant, that assumes the argument is a literal:
AC_DEFUN([gl_LIBUNISTRING_VERSION_CMP],
[ { test "$HAVE_LIBUNISTRING" != yes \
    || {
         m4_pushdef([requested_version_major],
           [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^\([0-9]*\).*], 
[\1]), [])])
         m4_pushdef([requested_version_minor],
           [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], 
[^[0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
         m4_pushdef([requested_version_subminor],
           [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], 
[^[0-9]*[.][0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
         test $LIBUNISTRING_VERSION_MAJOR -lt requested_version_major \
         || { test $LIBUNISTRING_VERSION_MAJOR -eq requested_version_major \
              && { test $LIBUNISTRING_VERSION_MINOR -lt requested_version_minor 
\
                   || { test $LIBUNISTRING_VERSION_MINOR -eq 
requested_version_minor \
                        && test $LIBUNISTRING_VERSION_SUBMINOR -lt 
requested_version_subminor
                      }
                 }
            }
         m4_popdef([requested_version_subminor])
         m4_popdef([requested_version_minor])
         m4_popdef([requested_version_major])
       }
  }
])

dnl gl_LIBUNISTRING_ARG_OR_ZERO([ARG], [ORIG]) expands to ARG if it is not the
dnl same as ORIG, otherwise to 0.
m4_define([gl_LIBUNISTRING_ARG_OR_ZERO], [m4_if([$1], [$2], [0], [$1])])
========================= m4/libunistring-optional.m4 =========================
# libunistring-optional.m4 serial 1
dnl Copyright (C) 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl gl_LIBUNISTRING_OPTIONAL
dnl Searches for an installed libunistring or uses the included source code
dnl parts.
dnl If found, it sets and AC_SUBSTs HAVE_LIBUNISTRING=yes and the LIBUNISTRING
dnl and LTLIBUNISTRING variables and augments the CPPFLAGS variable, and
dnl #defines HAVE_LIBUNISTRING to 1. Otherwise, it sets and AC_SUBSTs
dnl HAVE_LIBUNISTRING=no and LIBUNISTRING and LTLIBUNISTRING to empty.

AC_DEFUN([gl_LIBUNISTRING_OPTIONAL],
[
  dnl gl_LIBUNISTRING does a couple of extra things if this macro is used.
  AC_REQUIRE([gl_LIBUNISTRING])

  AC_MSG_CHECKING([whether to use the included libunistring])
  AC_MSG_RESULT([$gl_libunistring_use_included])
])
===============================================================================
--- m4/libunistring.m4.orig     Tue May 18 20:09:19 2010
+++ m4/libunistring.m4  Tue May 18 19:16:07 2010
@@ -1,4 +1,4 @@
-# libunistring.m4 serial 5
+# libunistring.m4 serial 6
 dnl Copyright (C) 2009-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,12 +7,48 @@
 dnl gl_LIBUNISTRING
 dnl Searches for an installed libunistring.
 dnl If found, it sets and AC_SUBSTs HAVE_LIBUNISTRING=yes and the LIBUNISTRING
-dnl and LTLIBUNISTRING variables and augments the CPPFLAGS variable, and
-dnl #defines HAVE_LIBUNISTRING to 1. Otherwise, it sets and AC_SUBSTs
-dnl HAVE_LIBUNISTRING=no and LIBUNISTRING and LTLIBUNISTRING to empty.
+dnl and LTLIBUNISTRING variables, sets the LIBUNISTRING_VERSION variable, and
+dnl augments the CPPFLAGS variable, and #defines HAVE_LIBUNISTRING to 1.
+dnl Otherwise, it sets and AC_SUBSTs HAVE_LIBUNISTRING=no and LIBUNISTRING and
+dnl LTLIBUNISTRING to empty.
 
 AC_DEFUN([gl_LIBUNISTRING],
 [
+  AC_BEFORE([$0], [gl_LIBUNISTRING_LIBSOURCE])
+  AC_BEFORE([$0], [gl_LIBUNISTRING_LIBHEADER])
+  AC_BEFORE([$0], [gl_LIBUNISTRING_LIB_PREPARE])
+
+  m4_ifdef([gl_LIBUNISTRING_OPTIONAL],
+    [
+      AC_MSG_CHECKING([whether included libunistring is requested])
+      AC_ARG_WITH([included-libunistring],
+        [  --with-included-libunistring  use the libunistring parts included 
here],
+        [gl_libunistring_force_included=$withval],
+        [gl_libunistring_force_included=no])
+      AC_MSG_RESULT([$gl_libunistring_force_included])
+      gl_libunistring_use_included="$gl_libunistring_force_included"
+      if test "$gl_libunistring_use_included" = yes; then
+        dnl Assume that libunistring is not installed until some other macro
+        dnl explicitly invokes gl_LIBUNISTRING_CORE.
+        if test -z "$HAVE_LIBUNISTRING"; then
+          HAVE_LIBUNISTRING=no
+        fi
+        LIBUNISTRING=
+        LTLIBUNISTRING=
+      else
+        gl_LIBUNISTRING_CORE
+        if test $HAVE_LIBUNISTRING = no; then
+          gl_libunistring_use_included=yes
+          LIBUNISTRING=
+          LTLIBUNISTRING=
+        fi
+      fi
+    ],
+    [gl_LIBUNISTRING_CORE])
+])
+
+AC_DEFUN([gl_LIBUNISTRING_CORE],
+[
   AC_REQUIRE([AM_ICONV])
   if test -n "$LIBICONV"; then
     dnl First, try to link without -liconv. libunistring often depends on
@@ -42,4 +78,51 @@
       [#include <uniconv.h>], [u8_strconv_from_locale((char*)0);],
       [no, consider installing GNU libunistring])
   fi
+  if test $HAVE_LIBUNISTRING = yes; then
+    dnl Determine the installed version.
+    AC_CACHE_CHECK([for libunistring version], [gl_cv_libunistring_version],
+      [AC_COMPUTE_INT([gl_libunistring_hexversion],
+                      [_LIBUNISTRING_VERSION],
+                      [#include <unistring/version.h>])
+       dnl Versions <= 0.9.3 had a hexversion of 0x0009.
+       dnl Use other tests to distinguish them.
+       if test $gl_libunistring_hexversion = 9; then
+         dnl Version 0.9.2 introduced the header <unistring/cdefs.h>.
+         AC_TRY_COMPILE([#include <unistring/cdefs.h>], ,
+           [gl_cv_libunistring_version092=true],
+           [gl_cv_libunistring_version092=false]);
+         if $gl_cv_libunistring_version092; then
+           dnl Version 0.9.3 changed a comment in <unistr.h>.
+           gl_ABSOLUTE_HEADER_ONE([unistr.h])
+           if test -n "$gl_cv_absolute_unistr_h" \
+              && grep 'Copy no more than N units of SRC to DEST.  Return a 
pointer' $gl_cv_absolute_unistr_h > /dev/null; then
+             dnl Detected version 0.9.3.
+             gl_libunistring_hexversion=2307
+           else
+             dnl Detected version 0.9.2.
+             gl_libunistring_hexversion=2306
+           fi
+         else
+           dnl Version 0.9.1 introduced the type casing_suffix_context_t.
+           AC_TRY_COMPILE([#include <unicase.h>
+                           casing_suffix_context_t ct;], ,
+             [gl_cv_libunistring_version091=true],
+             [gl_cv_libunistring_version091=false])
+           if $gl_cv_libunistring_version091; then
+             dnl Detected version 0.9.1.
+             gl_libunistring_hexversion=2305
+           else
+             dnl Detected version 0.9.
+             gl_libunistring_hexversion=2304
+           fi
+         fi
+       fi
+       dnl Transform into the usual major.minor.subminor notation.
+       gl_libunistring_major=`expr $gl_libunistring_hexversion / 65536`
+       gl_libunistring_minor=`expr $gl_libunistring_hexversion / 256 % 256`
+       gl_libunistring_subminor=`expr $gl_libunistring_hexversion % 256`
+       
gl_cv_libunistring_version="$gl_libunistring_major.$gl_libunistring_minor.$gl_libunistring_subminor"
+      ])
+    LIBUNISTRING_VERSION="$gl_cv_libunistring_version"
+  fi
 ])
--- modules/libunistring.orig   Tue May 18 20:09:19 2010
+++ modules/libunistring        Tue May 18 19:16:07 2010
@@ -3,6 +3,7 @@
 
 Files:
 m4/libunistring.m4
+m4/absolute-header.m4
 
 Depends-on:
 havelib



reply via email to

[Prev in Thread] Current Thread [Next in Thread]