Blame m4/libunistring-base.m4

Packit 33f14e
# libunistring-base.m4 serial 5
Packit 33f14e
dnl Copyright (C) 2010-2017 Free Software Foundation, Inc.
Packit 33f14e
dnl This file is free software; the Free Software Foundation
Packit 33f14e
dnl gives unlimited permission to copy and/or distribute it,
Packit 33f14e
dnl with or without modifications, as long as this notice is preserved.
Packit 33f14e
Packit 33f14e
dnl From Paolo Bonzini and Bruno Haible.
Packit 33f14e
Packit 33f14e
dnl gl_LIBUNISTRING_MODULE([VERSION], [Module])
Packit 33f14e
dnl Declares that the source files of Module should be compiled, unless we
Packit 33f14e
dnl are linking with libunistring and its version is >= the given VERSION.
Packit 33f14e
dnl Defines an automake conditional LIBUNISTRING_COMPILE_$MODULE that is
Packit 33f14e
dnl true if the source files of Module should be compiled.
Packit 33f14e
dnl This macro is to be used for public libunistring API, not for
Packit 33f14e
dnl undocumented API.
Packit 33f14e
dnl
Packit 33f14e
dnl You have to bump the VERSION argument to the next projected version
Packit 33f14e
dnl number each time you make a change that affects the behaviour of the
Packit 33f14e
dnl functions defined in Module (even if the sources of Module itself do not
Packit 33f14e
dnl change).
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_LIBUNISTRING_MODULE],
Packit 33f14e
[
Packit 33f14e
  AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
Packit 33f14e
  dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
Packit 33f14e
  dnl gl_LIBUNISTRING_CORE if that macro has been run.
Packit 33f14e
  AM_CONDITIONAL(AS_TR_CPP([LIBUNISTRING_COMPILE_$2]),
Packit 33f14e
    [gl_LIBUNISTRING_VERSION_CMP([$1])])
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
dnl gl_LIBUNISTRING_LIBHEADER([VERSION], [HeaderFile])
Packit 33f14e
dnl Declares that HeaderFile should be created, unless we are linking
Packit 33f14e
dnl with libunistring and its version is >= the given VERSION.
Packit 33f14e
dnl HeaderFile should be relative to the lib directory and end in '.h'.
Packit 33f14e
dnl Prepares for substituting LIBUNISTRING_HEADERFILE (to HeaderFile or empty).
Packit 33f14e
dnl
Packit 33f14e
dnl When we are linking with the already installed libunistring and its version
Packit 33f14e
dnl is < VERSION, we create HeaderFile here, because we may compile functions
Packit 33f14e
dnl (via gl_LIBUNISTRING_MODULE above) that are not contained in the installed
Packit 33f14e
dnl version.
Packit 33f14e
dnl When we are linking with the already installed libunistring and its version
Packit 33f14e
dnl is > VERSION, we don't create HeaderFile here: it could cause compilation
Packit 33f14e
dnl errors in other libunistring header files if some types are missing.
Packit 33f14e
dnl
Packit 33f14e
dnl You have to bump the VERSION argument to the next projected version
Packit 33f14e
dnl number each time you make a non-comment change to the HeaderFile.
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_LIBUNISTRING_LIBHEADER],
Packit 33f14e
[
Packit 33f14e
  AC_REQUIRE([gl_LIBUNISTRING_LIB_PREPARE])
Packit 33f14e
  dnl Use the variables HAVE_LIBUNISTRING, LIBUNISTRING_VERSION from
Packit 33f14e
  dnl gl_LIBUNISTRING_CORE if that macro has been run.
Packit 33f14e
  if gl_LIBUNISTRING_VERSION_CMP([$1]); then
Packit 33f14e
    LIBUNISTRING_[]AS_TR_CPP([$2])='$2'
Packit 33f14e
  else
Packit 33f14e
    LIBUNISTRING_[]AS_TR_CPP([$2])=
Packit 33f14e
  fi
Packit 33f14e
  AC_SUBST([LIBUNISTRING_]AS_TR_CPP([$2]))
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
dnl Miscellaneous preparations/initializations.
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_LIBUNISTRING_LIB_PREPARE],
Packit 33f14e
[
Packit 33f14e
  dnl Ensure that HAVE_LIBUNISTRING is fully determined at this point.
Packit 33f14e
  m4_ifdef([gl_LIBUNISTRING], [AC_REQUIRE([gl_LIBUNISTRING])])
Packit 33f14e
Packit 33f14e
  AC_REQUIRE([AC_PROG_AWK])
Packit 33f14e
Packit 33f14e
dnl Sed expressions to extract the parts of a version number.
Packit 33f14e
changequote(,)
Packit 33f14e
gl_libunistring_sed_extract_major='/^[0-9]/{s/^\([0-9]*\).*/\1/p;q;}
Packit 33f14e
i\
Packit 33f14e
0
Packit 33f14e
q
Packit 33f14e
'
Packit 33f14e
gl_libunistring_sed_extract_minor='/^[0-9][0-9]*[.][0-9]/{s/^[0-9]*[.]\([0-9]*\).*/\1/p;q;}
Packit 33f14e
i\
Packit 33f14e
0
Packit 33f14e
q
Packit 33f14e
'
Packit 33f14e
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;}
Packit 33f14e
i\
Packit 33f14e
0
Packit 33f14e
q
Packit 33f14e
'
Packit 33f14e
changequote([,])
Packit 33f14e
Packit 33f14e
  if test "$HAVE_LIBUNISTRING" = yes; then
Packit 33f14e
    LIBUNISTRING_VERSION_MAJOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_major"`
Packit 33f14e
    LIBUNISTRING_VERSION_MINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_minor"`
Packit 33f14e
    LIBUNISTRING_VERSION_SUBMINOR=`echo "$LIBUNISTRING_VERSION" | sed -n -e "$gl_libunistring_sed_extract_subminor"`
Packit 33f14e
  fi
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
dnl gl_LIBUNISTRING_VERSION_CMP([VERSION])
Packit 33f14e
dnl Expands to a shell statement that evaluates to true if LIBUNISTRING_VERSION
Packit 33f14e
dnl is less than the VERSION argument.
Packit 33f14e
AC_DEFUN([gl_LIBUNISTRING_VERSION_CMP],
Packit 33f14e
[ { test "$HAVE_LIBUNISTRING" != yes \
Packit 33f14e
    || {
Packit 33f14e
         dnl AS_LITERAL_IF exists and works fine since autoconf-2.59 at least.
Packit 33f14e
         AS_LITERAL_IF([$1],
Packit 33f14e
           [dnl This is the optimized variant, that assumes the argument is a literal:
Packit 33f14e
            m4_pushdef([requested_version_major],
Packit 33f14e
              [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^\([0-9]*\).*], [\1]), [])])
Packit 33f14e
            m4_pushdef([requested_version_minor],
Packit 33f14e
              [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
Packit 33f14e
            m4_pushdef([requested_version_subminor],
Packit 33f14e
              [gl_LIBUNISTRING_ARG_OR_ZERO(m4_bpatsubst([$1], [^[0-9]*[.][0-9]*[.]\([0-9]*\).*], [\1]), [$1])])
Packit 33f14e
            test $LIBUNISTRING_VERSION_MAJOR -lt requested_version_major \
Packit 33f14e
            || { test $LIBUNISTRING_VERSION_MAJOR -eq requested_version_major \
Packit 33f14e
                 && { test $LIBUNISTRING_VERSION_MINOR -lt requested_version_minor \
Packit 33f14e
                      || { test $LIBUNISTRING_VERSION_MINOR -eq requested_version_minor \
Packit 33f14e
                           && test $LIBUNISTRING_VERSION_SUBMINOR -lt requested_version_subminor
Packit 33f14e
                         }
Packit 33f14e
                    }
Packit 33f14e
               }
Packit 33f14e
            m4_popdef([requested_version_subminor])
Packit 33f14e
            m4_popdef([requested_version_minor])
Packit 33f14e
            m4_popdef([requested_version_major])
Packit 33f14e
           ],
Packit 33f14e
           [dnl This is the unoptimized variant:
Packit 33f14e
            requested_version_major=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_major"`
Packit 33f14e
            requested_version_minor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_minor"`
Packit 33f14e
            requested_version_subminor=`echo '$1' | sed -n -e "$gl_libunistring_sed_extract_subminor"`
Packit 33f14e
            test $LIBUNISTRING_VERSION_MAJOR -lt $requested_version_major \
Packit 33f14e
            || { test $LIBUNISTRING_VERSION_MAJOR -eq $requested_version_major \
Packit 33f14e
                 && { test $LIBUNISTRING_VERSION_MINOR -lt $requested_version_minor \
Packit 33f14e
                      || { test $LIBUNISTRING_VERSION_MINOR -eq $requested_version_minor \
Packit 33f14e
                           && test $LIBUNISTRING_VERSION_SUBMINOR -lt $requested_version_subminor
Packit 33f14e
                         }
Packit 33f14e
                    }
Packit 33f14e
               }
Packit 33f14e
           ])
Packit 33f14e
       }
Packit 33f14e
  }])
Packit 33f14e
Packit 33f14e
dnl gl_LIBUNISTRING_ARG_OR_ZERO([ARG], [ORIG]) expands to ARG if it is not the
Packit 33f14e
dnl same as ORIG, otherwise to 0.
Packit 33f14e
m4_define([gl_LIBUNISTRING_ARG_OR_ZERO], [m4_if([$1], [$2], [0], [$1])])