libunistring.m4 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # libunistring.m4 serial 12
  2. dnl Copyright (C) 2009-2021 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. AC_PREREQ([2.64])
  7. dnl gl_LIBUNISTRING
  8. dnl Searches for an installed libunistring.
  9. dnl If found, it sets and AC_SUBSTs HAVE_LIBUNISTRING=yes and the LIBUNISTRING
  10. dnl and LTLIBUNISTRING variables, sets the LIBUNISTRING_VERSION variable, and
  11. dnl augments the CPPFLAGS variable, and #defines HAVE_LIBUNISTRING to 1.
  12. dnl Otherwise, it sets and AC_SUBSTs HAVE_LIBUNISTRING=no and LIBUNISTRING and
  13. dnl LTLIBUNISTRING to empty.
  14. dnl Define gl_LIBUNISTRING using AC_DEFUN_ONCE, in order dnl to avoid warnings
  15. dnl like
  16. dnl "warning: AC_REQUIRE: `gl_LIBUNISTRING' was expanded before it was required".
  17. dnl This is tricky because of the way 'aclocal' is implemented:
  18. dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
  19. dnl Otherwise aclocal's initial scan pass would miss the macro definition.
  20. dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
  21. dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
  22. dnl warnings.
  23. AC_DEFUN_ONCE([gl_LIBUNISTRING],
  24. [
  25. AC_BEFORE([$0], [gl_LIBUNISTRING_MODULE])
  26. AC_BEFORE([$0], [gl_LIBUNISTRING_LIBHEADER])
  27. AC_BEFORE([$0], [gl_LIBUNISTRING_LIB_PREPARE])
  28. m4_ifdef([gl_LIBUNISTRING_OPTIONAL],
  29. [
  30. AC_MSG_CHECKING([whether included libunistring is requested])
  31. AC_ARG_WITH([included-libunistring],
  32. [ --with-included-libunistring use the libunistring parts included here],
  33. [gl_libunistring_force_included=$withval],
  34. [gl_libunistring_force_included=no])
  35. AC_MSG_RESULT([$gl_libunistring_force_included])
  36. gl_libunistring_use_included="$gl_libunistring_force_included"
  37. if test "$gl_libunistring_use_included" = yes; then
  38. dnl Assume that libunistring is not installed until some other macro
  39. dnl explicitly invokes gl_LIBUNISTRING_CORE.
  40. if test -z "$HAVE_LIBUNISTRING"; then
  41. HAVE_LIBUNISTRING=no
  42. fi
  43. LIBUNISTRING=
  44. LTLIBUNISTRING=
  45. else
  46. gl_LIBUNISTRING_CORE
  47. if test $HAVE_LIBUNISTRING = no; then
  48. gl_libunistring_use_included=yes
  49. LIBUNISTRING=
  50. LTLIBUNISTRING=
  51. fi
  52. fi
  53. ],
  54. [gl_LIBUNISTRING_CORE])
  55. ])
  56. AC_DEFUN([gl_LIBUNISTRING_CORE],
  57. [
  58. AC_REQUIRE([AM_ICONV])
  59. if test -n "$LIBICONV"; then
  60. dnl First, try to link without -liconv. libunistring often depends on
  61. dnl libiconv, but we don't know (and often don't need to know) where
  62. dnl libiconv is installed.
  63. AC_LIB_HAVE_LINKFLAGS([unistring], [],
  64. [#include <uniconv.h>], [u8_strconv_from_locale((char*)0);],
  65. [no, trying again together with libiconv])
  66. if test "$ac_cv_libunistring" != yes; then
  67. dnl Second try, with -liconv.
  68. dnl We have to erase the cached result of the first AC_LIB_HAVE_LINKFLAGS
  69. dnl invocation, otherwise the second one will not be run.
  70. unset ac_cv_libunistring
  71. glus_save_LIBS="$LIBS"
  72. LIBS="$LIBS $LIBICONV"
  73. AC_LIB_HAVE_LINKFLAGS([unistring], [],
  74. [#include <uniconv.h>], [u8_strconv_from_locale((char*)0);],
  75. [no, consider installing GNU libunistring])
  76. if test -n "$LIBUNISTRING"; then
  77. LIBUNISTRING="$LIBUNISTRING $LIBICONV"
  78. LTLIBUNISTRING="$LTLIBUNISTRING $LTLIBICONV"
  79. fi
  80. LIBS="$glus_save_LIBS"
  81. fi
  82. else
  83. AC_LIB_HAVE_LINKFLAGS([unistring], [],
  84. [#include <uniconv.h>], [u8_strconv_from_locale((char*)0);],
  85. [no, consider installing GNU libunistring])
  86. fi
  87. if test $HAVE_LIBUNISTRING = yes; then
  88. dnl Determine the installed version.
  89. AC_CACHE_CHECK([for libunistring version], [gl_cv_libunistring_version],
  90. [AC_COMPUTE_INT([gl_libunistring_hexversion],
  91. [_LIBUNISTRING_VERSION],
  92. [#include <unistring/version.h>])
  93. dnl Versions <= 0.9.3 had a hexversion of 0x0009.
  94. dnl Use other tests to distinguish them.
  95. if test $gl_libunistring_hexversion = 9; then
  96. dnl Version 0.9.2 introduced the header <unistring/cdefs.h>.
  97. AC_COMPILE_IFELSE(
  98. [AC_LANG_PROGRAM([[#include <unistring/cdefs.h>]], [[]])],
  99. [gl_cv_libunistring_version092=true],
  100. [gl_cv_libunistring_version092=false])
  101. if $gl_cv_libunistring_version092; then
  102. dnl Version 0.9.3 changed a comment in <unistr.h>.
  103. gl_ABSOLUTE_HEADER_ONE([unistr.h])
  104. if test -n "$gl_cv_absolute_unistr_h" \
  105. && grep 'Copy no more than N units of SRC to DEST. Return a pointer' $gl_cv_absolute_unistr_h > /dev/null; then
  106. dnl Detected version 0.9.3.
  107. gl_libunistring_hexversion=2307
  108. else
  109. dnl Detected version 0.9.2.
  110. gl_libunistring_hexversion=2306
  111. fi
  112. else
  113. dnl Version 0.9.1 introduced the type casing_suffix_context_t.
  114. AC_COMPILE_IFELSE(
  115. [AC_LANG_PROGRAM(
  116. [[#include <unicase.h>
  117. casing_suffix_context_t ct;]],
  118. [[]])],
  119. [gl_cv_libunistring_version091=true],
  120. [gl_cv_libunistring_version091=false])
  121. if $gl_cv_libunistring_version091; then
  122. dnl Detected version 0.9.1.
  123. gl_libunistring_hexversion=2305
  124. else
  125. dnl Detected version 0.9.
  126. gl_libunistring_hexversion=2304
  127. fi
  128. fi
  129. fi
  130. dnl Transform into the usual major.minor.subminor notation.
  131. gl_libunistring_major=`expr $gl_libunistring_hexversion / 65536`
  132. gl_libunistring_minor=`expr $gl_libunistring_hexversion / 256 % 256`
  133. gl_libunistring_subminor=`expr $gl_libunistring_hexversion % 256`
  134. gl_cv_libunistring_version="$gl_libunistring_major.$gl_libunistring_minor.$gl_libunistring_subminor"
  135. ])
  136. LIBUNISTRING_VERSION="$gl_cv_libunistring_version"
  137. fi
  138. ])