Blame m4/libunistring-base.m4

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