2
0

libunistring.m4 6.2 KB

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