libunistring-base.m4 6.2 KB

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