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