From ddd692ba50e40feb5bcf77da7ce3fc32fc5cd0ff Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 12 Aug 2017 09:09:09 -0400 Subject: [PATCH] add libicu support; configure --with-icu --- config.make.in | 6 +-- configure.ac | 2 + include/tig/tig.h | 7 ++++ tools/ax_with_icu.m4 | 97 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 tools/ax_with_icu.m4 diff --git a/config.make.in b/config.make.in index 74850371b..f5954eb2c 100644 --- a/config.make.in +++ b/config.make.in @@ -9,10 +9,10 @@ datarootdir = @datarootdir@ sysconfdir = @sysconfdir@ CC = @CC@ -CFLAGS = @CFLAGS@ @COVERAGE_CFLAGS@ +CFLAGS = @CFLAGS@ @ICU_CFLAGS@ @COVERAGE_CFLAGS@ CPPFLAGS = @CPPFLAGS@ -DHAVE_CONFIG_H -LDFLAGS = @LDFLAGS@ -LDLIBS = @LIBS@ @CURSES_LIBS@ +LDFLAGS = @LDFLAGS@ @ICU_LDFLAGS@ +LDLIBS = @LIBS@ @ICU_LIBS@ @CURSES_LIBS@ ASCIIDOC = @ASCIIDOC@ XMLTO = @XMLTO@ diff --git a/configure.ac b/configure.ac index 4b914e821..aaba44f09 100644 --- a/configure.ac +++ b/configure.ac @@ -34,6 +34,8 @@ AC_SUBST(CURSES_LIBS) AX_LIB_READLINE(6.2) +AX_WITH_ICU([48.0], [icu-uc]) + AM_ICONV AC_CHECK_PROGS(SED, [gsed], [sed]) diff --git a/include/tig/tig.h b/include/tig/tig.h index d4299b400..07cfe57ad 100644 --- a/include/tig/tig.h +++ b/include/tig/tig.h @@ -87,6 +87,13 @@ # include #endif +#ifdef HAVE_ICU +#define U_CHARSET_IS_UTF8 1 +#include +#include +#include +#endif + #ifdef TRUE #undef TRUE #endif diff --git a/tools/ax_with_icu.m4 b/tools/ax_with_icu.m4 new file mode 100644 index 000000000..c2a9f25ee --- /dev/null +++ b/tools/ax_with_icu.m4 @@ -0,0 +1,97 @@ +dnl Copyright (c) 2006-2017 Jonas Fonseca +dnl +dnl This program is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU General Public License as +dnl published by the Free Software Foundation; either version 2 of +dnl the License, or (at your option) any later version. +dnl +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU General Public License for more details. +dnl +dnl SYNOPSIS +dnl +dnl AX_WITH_ICU([version, [components]]) +dnl +dnl version default value is 0 +dnl +dnl components default value is icu-uc +dnl +dnl DESCRIPTION +dnl +dnl Defines +dnl +dnl ICU_CFLAGS +dnl ICU_LDFLAGS +dnl ICU_LIBS +dnl +dnl If pkg-config fails, falls back to the deprecated icu-config +dnl utility. icu-config is not capable of selecting a subset of +dnl components to link, and will ignore the "components" argument +dnl to the macro. +dnl +dnl Components recognized by pkg-config are: +dnl +dnl icu-uc Common (uc) and Data (dt/data) libraries +dnl icu-i18n Internationalization (in/i18n) library +dnl icu-lx Paragraph Layout library +dnl icu-io Ustdio/iostream library (icuio) +dnl +dnl The user may override the location of pkg-config or icu-config +dnl via environment variables $PKG_CONFIG and $ICU_CONFIG. +dnl +dnl EXAMPLE +dnl +dnl AX_WITH_ICU([50.0], [icu-uc icu-i18n]) +dnl + +AC_DEFUN([AX_WITH_ICU], [ + AC_ARG_WITH([icu], AS_HELP_STRING([--with-icu], [Build with libicu support])) + + _libicu_min_version="$1" + _libicu_components="$2" + test x = x"$_libicu_min_version" && _libicu_min_version=0 + test x = x"$_libicu_components" && _libicu_components=icu-uc + + _libicu_pkg_config="${PKG_CONFIG:-pkg-config}" + _libicu_icu_config="${ICU_CONFIG:-icu-config}" + + AC_SUBST(ICU_CFLAGS) + AC_SUBST(ICU_LDFLAGS) + AC_SUBST(ICU_LIBS) + + AS_IF([test "x$with_icu" = "xyes"], [ + + AC_MSG_CHECKING([whether pkg-config can query libicu]) + AS_IF([test x != x"$("$_libicu_pkg_config" --modversion icu-uc 2>/dev/null)"], [ + AC_MSG_RESULT([yes]) + ], [ dnl else + AC_MSG_RESULT([no]) + AC_MSG_CHECKING([whether icu-config can query libicu]) + AS_IF([test x != x"$("$_libicu_icu_config" --version 2>/dev/null)"], [ + AC_MSG_RESULT([yes]) + ], [ dnl else + AC_MSG_RESULT([no]) + AC_MSG_ERROR([neither pkg-config nor icu-config is able to query local libicu configuration]) + ]) + ]) + + AC_MSG_CHECKING([for libicu version >= $_libicu_min_version]) + ICU_VERSION="$(("$_libicu_pkg_config" --modversion "$_libicu_components" 2>/dev/null || "$_libicu_icu_config" --version || printf "%s\n" "-1") | head -1)" + AS_IF([test x"$(expr "$ICU_VERSION" ">=" "$_libicu_min_version")" = x1], [ + + # libicu success + AC_MSG_RESULT([$ICU_VERSION]) + AC_DEFINE(HAVE_ICU, [1], [Define to 1 if libicu is present]) + ICU_CFLAGS="$( "$_libicu_pkg_config" --cflags "$_libicu_components" 2>/dev/null || "$_libicu_icu_config" --cflags)" + ICU_LDFLAGS="$("$_libicu_pkg_config" --libs-only-L "$_libicu_components" 2>/dev/null || "$_libicu_icu_config" --ldflags-searchpath)" + ICU_LIBS="$( "$_libicu_pkg_config" --libs-only-l "$_libicu_components" 2>/dev/null || "$_libicu_icu_config" --ldflags-libsonly)" + + ], [ dnl else + AC_MSG_RESULT([$ICU_VERSION]) + AC_MSG_ERROR([required libicu version not found]) + ]) + + ]) +])