]> git.lyx.org Git - lyx.git/commitdiff
Configure included iconv with autotools
authorGeorg Baum <baum@lyx.org>
Thu, 5 May 2016 17:43:24 +0000 (19:43 +0200)
committerRichard Heck <rgheck@lyx.org>
Sun, 29 May 2016 21:55:43 +0000 (17:55 -0400)
The included iconv should not be used on Linux or OS X, but (depending on
local configuration) it might be needed for crosscompiling a mingw target
from Linux. Now the user can choose whether to use the included iconv or not.
cmake does already support that.

eilseq.m4 was taken from the original libiconv 1.14 package.

12 files changed:
3rdparty/Makefile.am
3rdparty/libiconv/Makefile.am
config/lyxinclude.m4
configure.ac
m4/Makefile.am
m4/eilseq.m4 [new file with mode: 0644]
src/Makefile.am
src/client/Makefile.am
src/frontends/Makefile.am
src/frontends/qt4/Makefile.am
src/support/Makefile.am
src/tex2lyx/Makefile.am

index 54ab6c4e63eb9031f124a42a8dfeefa22e710aaf..f936a4c7532f8a1191185f547aa58bd18c3ab105 100644 (file)
@@ -6,8 +6,12 @@ if USE_INCLUDED_BOOST
 BOOST = boost
 endif
 
+if USE_INCLUDED_ICONV
+ICONV = libiconv
+endif
+
 if USE_INCLUDED_ZLIB
 ZLIB = zlib
 endif
 
-SUBDIRS = $(BOOST) $(ZLIB)
+SUBDIRS = $(BOOST) $(ICONV) $(ZLIB)
index d965f380f1335dfcc67ea382406efd38f3e773b9..d03032d13192d4a952840eec119fefc936a45ade 100644 (file)
@@ -1,10 +1,7 @@
 include $(top_srcdir)/config/common.am
 
-# This is prepared for compilation, but currently only used for packaging,
-# because configure support for compilation is still missing.
-
 # We do not build right now
-#noinst_LIBRARIES = liblyxiconv.a
+noinst_LIBRARIES = liblyxiconv.a
 
 EXTRA_DIST = \
        CMakeLists.txt \
@@ -33,11 +30,15 @@ EXTRA_DIST = \
        1.14/libcharset/lib/ref-add.sin \
        1.14/libcharset/lib/ref-del.sin
 
-# If/when we decide to build, this will do in liblyxiconv_a_SOURCES
-# But for now it confuses automake < 1.14, where we do not use subdir-objects.
-# The issue here is that there are two relocatable.c files, and they would
-# create the same .o file.
-EXTRA_DIST += \
+AM_CPPFLAGS += -I$(srcdir)/1.14/srclib -DLIBDIR=""
+
+# The two relocatable.c files confuse automake < 1.14, where we do not use
+# subdir-objects. Therefore we cannot put both in liblyxiconv_a_SOURCES
+# (they would both create the same .o file). Fortunately their contents is
+# identical, so it is enough to build only one.
+EXTRA_DIST += 1.14/libcharset/lib/relocatable.c
+
+liblyxiconv_a_SOURCES = \
        1.14/include/export.h \
        1.14/lib/aliases2.h \
        1.14/lib/aliases_aix.h \
@@ -263,7 +264,6 @@ EXTRA_DIST += \
        1.14/lib/viscii.h \
        1.14/libcharset/include/export.h \
        1.14/libcharset/lib/localcharset.c \
-       1.14/libcharset/lib/relocatable.c \
        1.14/libcharset/lib/relocatable.h \
        1.14/srclib/localcharset.h \
        1.14/srclib/unitypes.in.h \
index df17da884370f81cda43f058e36b3cb9c688e7d1..84f66880a27ccdce601a79ac8a8df8ebda4bb8bc 100644 (file)
@@ -454,6 +454,70 @@ AC_DEFUN([LYX_USE_INCLUDED_BOOST],[
 ])
 
 
+dnl Usage: LYX_USE_INCLUDED_ICONV : select if the included iconv should
+dnl        be used.
+AC_DEFUN([LYX_USE_INCLUDED_ICONV],[
+  AC_MSG_CHECKING([whether to use included iconv library])
+  AC_ARG_WITH(included-iconv,
+    [AC_HELP_STRING([--without-included-iconv], [do not use the iconv lib supplied with LyX, try to find one in the system directories - compilation will abort if nothing suitable is found])],
+    [lyx_cv_with_included_iconv=$withval],
+    [lyx_cv_with_included_iconv=no])
+  AM_CONDITIONAL(USE_INCLUDED_ICONV, test x$lyx_cv_with_included_iconv = xyes)
+  AC_MSG_RESULT([$lyx_cv_with_included_iconv])
+  if test x$lyx_cv_with_included_iconv = xyes ; then
+dnl Some bits from libiconv configure.ac to avoid a nested configure call:
+    AC_EILSEQ
+    AC_TYPE_MBSTATE_T
+    AC_CHECK_FUNCS([getc_unlocked mbrtowc wcrtomb mbsinit setlocale])
+dnl Ymbstate_t is used if HAVE_WCRTOMB || HAVE_MBRTOWC, see 3rdparty/libiconv/1.14/lib/loop_wchar.h.
+    if test $ac_cv_func_wcrtomb = yes || test $ac_cv_func_mbrtowc = yes; then
+      USE_MBSTATE_T=1
+    else
+      USE_MBSTATE_T=0
+    fi
+    AC_SUBST([USE_MBSTATE_T])
+    AC_CACHE_CHECK([whether <wchar.h> is standalone],
+      [gl_cv_header_wchar_h_standalone],
+      [AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM(
+          [[#include <wchar.h>
+            wchar_t w;]],
+          [[]])],
+        [gl_cv_header_wchar_h_standalone=yes],
+        [gl_cv_header_wchar_h_standalone=no])])
+    if test $gl_cv_header_wchar_h_standalone = yes; then
+      BROKEN_WCHAR_H=0
+    else
+      BROKEN_WCHAR_H=1
+    fi
+    AC_SUBST([BROKEN_WCHAR_H])
+dnl we want const correctness
+    AC_DEFINE_UNQUOTED([ICONV_CONST], [const],
+      [Define as const if the declaration of iconv() needs const.])
+    ICONV_CONST=const
+    AC_SUBST([ICONV_CONST])
+dnl we build a static lib
+    DLL_VARIABLE=
+    AC_SUBST([DLL_VARIABLE])
+    ICONV_INCLUDES='-I$(top_srcdir)/3rdparty/libiconv/1.14 -I$(top_builddir)/3rdparty/libiconv'
+    ICONV_LIBS='\$(top_builddir)/3rdparty/libiconv/liblyxiconv.a'
+    ICONV_ICONV_H_IN=3rdparty/libiconv/iconv.h:3rdparty/libiconv/1.14/include/iconv.h.in
+  else
+    ICONV_INCLUDES=
+    AM_ICONV
+    if test "$am_cv_func_iconv" = no; then
+      AC_MSG_ERROR([cannot find required library iconv.])
+    else
+      ICONV_LIBS="$LIBICONV"
+    fi
+    ICONV_ICONV_H_IN=
+  fi
+  AC_SUBST(ICONV_INCLUDES)
+  AC_SUBST(ICONV_LIBS)
+  AC_SUBST(ICONV_ICONV_H_IN)
+])
+
+
 dnl Usage: LYX_USE_INCLUDED_ZLIB : select if the included zlib should
 dnl        be used.
 AC_DEFUN([LYX_USE_INCLUDED_ZLIB],[
index 6de63c9fd70e65cdc40388ec645395ef25148838..3b1a900ddb82522bc6dc9839c5a4ac98593764ab 100644 (file)
@@ -130,6 +130,19 @@ LYX_CHECK_CALLSTACK_PRINTING
 # Needed for our char_type
 AC_CHECK_SIZEOF(wchar_t)
 
+# Taken from gettext, needed for libiconv
+AC_CACHE_CHECK([for wchar_t], [gt_cv_c_wchar_t],
+   [AC_TRY_COMPILE([#include <stddef.h>
+      wchar_t foo = (wchar_t)'\0';], ,
+      [gt_cv_c_wchar_t=yes], [gt_cv_c_wchar_t=no])])
+if test $gt_cv_c_wchar_t = yes; then
+  AC_DEFINE([HAVE_WCHAR_T], [1], [Define if you have the 'wchar_t' type.])
+  HAVE_WCHAR_T=1
+else
+  HAVE_WCHAR_T=0
+fi
+AC_SUBST([HAVE_WCHAR_T])
+
 # Needed for Mingw-w64
 AC_TYPE_LONG_LONG_INT
 if test "$ac_cv_type_long_long_int" = yes; then
@@ -138,12 +151,7 @@ if test "$ac_cv_type_long_long_int" = yes; then
 fi
 
 ### We need iconv for unicode support (Qt4 frontend requires it too)
-AM_ICONV
-if test "$am_cv_func_iconv" = no; then
-  AC_MSG_ERROR([cannot find required library iconv.])
-else
-  LIBS="$LIBS $LIBICONV"
-fi
+LYX_USE_INCLUDED_ICONV
 
 ### check for compression support
 LYX_USE_INCLUDED_ZLIB
@@ -197,14 +205,6 @@ AC_TYPE_OFF_T
 AC_TYPE_PID_T
 AC_TYPE_SIZE_T
 AC_TYPE_UID_T
-# Taken from gettext
-AC_CACHE_CHECK([for wchar_t], [gt_cv_c_wchar_t],
-   [AC_TRY_COMPILE([#include <stddef.h>
-      wchar_t foo = (wchar_t)'\0';], ,
-      [gt_cv_c_wchar_t=yes], [gt_cv_c_wchar_t=no])])
-if test $gt_cv_c_wchar_t = yes; then
-  AC_DEFINE([HAVE_WCHAR_T], [1], [Define if you have the 'wchar_t' type.])
-fi
 
 LYX_CHECK_DEF(PATH_MAX, limits.h, [int n = PATH_MAX;])
 
@@ -368,6 +368,7 @@ AC_CONFIG_FILES([Makefile \
       3rdparty/boost/Makefile \
       3rdparty/hunspell/Makefile \
       3rdparty/libiconv/Makefile \
+      $ICONV_ICONV_H_IN \
       3rdparty/zlib/Makefile \
       autotests/Makefile \
       config/Makefile \
index 2fd4fbb176663d486e70865ad40a96e106a09e6d..6f02330e4c465620445712c67f50021b385fe1e4 100644 (file)
@@ -1 +1,2 @@
-EXTRA_DIST = iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 po.m4 progtest.m4
+EXTRA_DIST = eilseq.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 nls.m4 \
+       po.m4 progtest.m4
diff --git a/m4/eilseq.m4 b/m4/eilseq.m4
new file mode 100644 (file)
index 0000000..792d514
--- /dev/null
@@ -0,0 +1,67 @@
+#serial 1
+
+AC_PREREQ(2.50)
+
+# The EILSEQ errno value ought to be defined in <errno.h>, according to
+# ISO C 99 and POSIX.  But some systems (like SunOS 4) don't define it,
+# and some systems (like BSD/OS) define it in <wchar.h> not <errno.h>.
+
+# Define EILSEQ as a C macro and as a substituted macro in such a way that
+# 1. on all systems, after inclusion of <errno.h>, EILSEQ is usable,
+# 2. on systems where EILSEQ is defined elsewhere, we use the same numeric
+#    value.
+
+AC_DEFUN([AC_EILSEQ],
+[
+  AC_REQUIRE([AC_PROG_CC])dnl
+
+  dnl Check for any extra headers that could define EILSEQ.
+  AC_CHECK_HEADERS(wchar.h)
+
+  AC_CACHE_CHECK([for EILSEQ], ac_cv_decl_EILSEQ, [
+    AC_EGREP_CPP(yes,[
+#include <errno.h>
+#ifdef EILSEQ
+yes
+#endif
+      ], have_eilseq=1)
+    if test -n "$have_eilseq"; then
+      dnl EILSEQ exists in <errno.h>. Don't need to define EILSEQ ourselves.
+      ac_cv_decl_EILSEQ=yes
+    else
+      AC_EGREP_CPP(yes,[
+#include <errno.h>
+#if HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+#ifdef EILSEQ
+yes
+#endif
+        ], have_eilseq=1)
+      if test -n "$have_eilseq"; then
+        dnl EILSEQ exists in some other system header.
+        dnl Define it to the same value.
+        _AC_COMPUTE_INT([EILSEQ], ac_cv_decl_EILSEQ, [
+#include <errno.h>
+#if HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+/* The following two lines are a workaround against an autoconf-2.52 bug.  */
+#include <stdio.h>
+#include <stdlib.h>
+])
+      else
+        dnl EILSEQ isn't defined by the system. Define EILSEQ ourselves, but
+        dnl don't define it as EINVAL, because iconv() callers want to
+        dnl distinguish EINVAL and EILSEQ.
+        ac_cv_decl_EILSEQ=ENOENT
+      fi
+    fi
+  ])
+  if test "$ac_cv_decl_EILSEQ" != yes; then
+    AC_DEFINE_UNQUOTED([EILSEQ], [$ac_cv_decl_EILSEQ],
+                       [Define as good substitute value for EILSEQ.])
+    EILSEQ="$ac_cv_decl_EILSEQ"
+    AC_SUBST(EILSEQ)
+  fi
+])
index c0e4d5844e30e15321147c90460be8a285a266ef..8166b11ff43afee288cd151316190eac43ead291 100644 (file)
@@ -2,7 +2,8 @@ include $(top_srcdir)/config/common.am
 
 ############################### Core  ##############################
 
-AM_CPPFLAGS += -I$(top_srcdir)/src $(BOOST_INCLUDES) $(ZLIB_INCLUDES)
+AM_CPPFLAGS += -I$(top_srcdir)/src
+AM_CPPFLAGS += $(BOOST_INCLUDES) $(ICONV_INCLUDES) $(ZLIB_INCLUDES)
 AM_CPPFLAGS += $(ENCHANT_CFLAGS) $(HUNSPELL_CFLAGS)
 AM_CPPFLAGS += $(QT_CPPFLAGS) $(QT_CORE_INCLUDES)
 
@@ -20,7 +21,8 @@ EXTRA_DIST = lyx_commit_hash.h.in \
        tests/CMakeLists.txt
 
 OTHERLIBS = $(BOOST_LIBS) $(MYTHES_LIBS) $(ENCHANT_LIBS) $(HUNSPELL_LIBS) \
-            @LIBS@ $(ZLIB_LIBS) $(SOCKET_LIBS) $(LIBSHLWAPI) $(LIBPSAPI)
+            @LIBS@ $(ICONV_LIBS) $(ZLIB_LIBS) $(SOCKET_LIBS) \
+           $(LIBSHLWAPI) $(LIBPSAPI)
 
 noinst_LIBRARIES = liblyxcore.a
 bin_PROGRAMS = lyx
@@ -734,7 +736,8 @@ ADD_FRAMEWORKS = -framework QtGui -framework QtCore -framework AppKit -framework
 endif
 
 check_layout_CPPFLAGS = $(AM_CPPFLAGS)
-check_layout_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ $(ZLIB_LIBS) $(QT_LIB) $(LIBSHLWAPI)
+check_layout_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ \
+       $(ICONV_LIBS) $(ZLIB_LIBS) $(QT_LIB) $(LIBSHLWAPI)
 check_layout_LDFLAGS = $(QT_LDFLAGS) $(ADD_FRAMEWORKS)
 check_layout_SOURCES = \
        insets/InsetLayout.cpp \
@@ -754,7 +757,8 @@ check_layout_SOURCES = \
        tests/dummy_functions.cpp
 
 check_ExternalTransforms_CPPFLAGS = $(AM_CPPFLAGS)
-check_ExternalTransforms_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ $(ZLIB_LIBS) $(QT_LIB) $(LIBSHLWAPI)
+check_ExternalTransforms_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ \
+       $(ICONV_LIBS) $(ZLIB_LIBS) $(QT_LIB) $(LIBSHLWAPI)
 check_ExternalTransforms_LDFLAGS = $(QT_LDFLAGS) $(ADD_FRAMEWORKS)
 check_ExternalTransforms_SOURCES = \
        graphics/GraphicsParams.cpp \
@@ -766,7 +770,8 @@ check_ExternalTransforms_SOURCES = \
        tests/dummy_functions.cpp
 
 check_Length_CPPFLAGS = $(AM_CPPFLAGS)
-check_Length_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ $(ZLIB_LIBS) $(QT_LIB) $(LIBSHLWAPI)
+check_Length_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ \
+       $(ICONV_LIBS) $(ZLIB_LIBS) $(QT_LIB) $(LIBSHLWAPI)
 check_Length_LDFLAGS = $(QT_LDFLAGS) $(ADD_FRAMEWORKS)
 check_Length_SOURCES = \
        Length.cpp \
@@ -776,7 +781,8 @@ check_Length_SOURCES = \
        tests/dummy_functions.cpp
 
 check_ListingsCaption_CPPFLAGS = $(AM_CPPFLAGS)
-check_ListingsCaption_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ $(ZLIB_LIBS) $(QT_LIB) $(LIBSHLWAPI)
+check_ListingsCaption_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ \
+       $(ICONV_LIBS) $(ZLIB_LIBS) $(QT_LIB) $(LIBSHLWAPI)
 check_ListingsCaption_LDFLAGS = $(QT_LDFLAGS) $(ADD_FRAMEWORKS)
 check_ListingsCaption_SOURCES = \
        tests/check_ListingsCaption.cpp \
index 131c56a6c38e9dc0d482e215b871913cca255518..3874376ab4fecdba9136672d6f5de0e95586a3fd 100644 (file)
@@ -8,11 +8,12 @@ bin_PROGRAMS = lyxclient
 
 EXTRA_DIST = lyxclient.1in CMakeLists.txt
 
-AM_CPPFLAGS += -I$(srcdir)/.. $(BOOST_INCLUDES) $(ZLIB_INCLUDES)
+AM_CPPFLAGS += -I$(srcdir)/.. \
+       $(BOOST_INCLUDES) $(ICONV_INCLUDES) $(ZLIB_INCLUDES)
 
 lyxclient_LDADD = \
        $(top_builddir)/src/support/liblyxsupport.a \
-       $(BOOST_LIBS) @LIBS@ $(ZLIB_LIBS) $(SOCKET_LIBS) \
+       $(BOOST_LIBS) @LIBS@ $(ICONV_LIBS) $(ZLIB_LIBS) $(SOCKET_LIBS) \
        $(QT_LIB) $(QT_LDFLAGS) $(LIBSHLWAPI) $(LIBPSAPI)
 
 if INSTALL_MACOSX
index 0a615e19036349c750ff9a1f8f70e6428f2e6a47..862613a67f51964dded997125b30f6fcd9cac155 100644 (file)
@@ -6,7 +6,8 @@ DIST_SUBDIRS = qt4 .
 
 noinst_LIBRARIES = liblyxfrontends.a
 
-AM_CPPFLAGS += -I$(srcdir)/..  $(BOOST_INCLUDES) $(ZLIB_INCLUDES)
+AM_CPPFLAGS += -I$(srcdir)/.. \
+       $(BOOST_INCLUDES) $(ICONV_INCLUDES) $(ZLIB_INCLUDES)
 
 liblyxfrontends_a_SOURCES = \
        alert.h \
@@ -39,7 +40,7 @@ TESTS = \
 check_PROGRAMS = \
        biblio
 
-biblio_LDADD = $(BOOST_LIBS) $(ZLIB_LIBS)
+biblio_LDADD = $(BOOST_LIBS) $(ICONV_LIBS) $(ZLIB_LIBS)
 biblio_SOURCES = \
        tests/biblio.cpp \
        tests/boost.cpp
index 3358186ccb607d71beac92672a5f7d705a34fa68..fb21eb692eb40eaa5ecde924ece7696991675b0d 100644 (file)
@@ -47,7 +47,8 @@ AM_CPPFLAGS += \
        -I$(top_srcdir)/src \
        -I$(top_srcdir)/src/frontends \
        -I$(top_srcdir)/images \
-       $(QT_INCLUDES) $(BOOST_INCLUDES) $(ZLIB_INCLUDES)
+       $(QT_INCLUDES) \
+       $(BOOST_INCLUDES) $(ICONV_INCLUDES) $(ZLIB_INCLUDES)
 
 SOURCEFILES = \
        ButtonPolicy.cpp \
index d1137290ee4646dcf0e6eeb4fb5020f269ee616e..29f003b85d4374084fd93f702bba203904bd0c9a 100644 (file)
@@ -26,7 +26,8 @@ liblyxsupport_a_DEPENDENCIES = $(MOCEDFILES)
 #
 ##################################################################
 
-AM_CPPFLAGS += -I$(srcdir)/.. $(BOOST_INCLUDES) $(ZLIB_INCLUDES) \
+AM_CPPFLAGS += -I$(srcdir)/.. \
+       $(BOOST_INCLUDES) $(ICONV_INCLUDES) $(ZLIB_INCLUDES) \
        $(QT_CPPFLAGS) $(QT_INCLUDES)
 
 liblyxsupport_a_SOURCES = \
index e29356754f0c6c87c6181bf913d5bf2dec236ff8..bf2d66d67f81e9f7773f07756d900e37654f9046 100644 (file)
@@ -19,7 +19,7 @@ DEFAULT_INCLUDES =
 
 AM_CPPFLAGS += -I$(top_srcdir)/src/tex2lyx \
        -I$(top_srcdir)/src -I$(top_builddir) -I$(top_builddir)/src \
-       $(BOOST_INCLUDES) $(ZLIB_INCLUDES)
+       $(BOOST_INCLUDES) $(ICONV_INCLUDES) $(ZLIB_INCLUDES)
 
 TEST_FILES = \
        test/runtests.cmake \
@@ -125,7 +125,7 @@ tex2lyx_LDADD = \
        $(top_builddir)/src/support/liblyxsupport.a \
        $(LIBICONV) $(BOOST_LIBS) \
        $(QT_LIB) $(QT_LDFLAGS) \
-       @LIBS@ $(ZLIB_LIBS) $(LIBSHLWAPI) $(LIBPSAPI)
+       @LIBS@ $(ICONV_LIBS) $(ZLIB_LIBS) $(LIBSHLWAPI) $(LIBPSAPI)
 
 if INSTALL_MACOSX
 tex2lyx_LDFLAGS = -framework AppKit \