From 08afc52c4cc5fe8740722d7715fd66baa3dd9ffa Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Thu, 5 May 2016 19:43:24 +0200 Subject: [PATCH] Configure included iconv with autotools 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. --- 3rdparty/Makefile.am | 6 +++- 3rdparty/libiconv/Makefile.am | 20 +++++------ config/lyxinclude.m4 | 64 +++++++++++++++++++++++++++++++++ configure.ac | 29 +++++++-------- m4/Makefile.am | 3 +- m4/eilseq.m4 | 67 +++++++++++++++++++++++++++++++++++ src/Makefile.am | 18 ++++++---- src/client/Makefile.am | 5 +-- src/frontends/Makefile.am | 5 +-- src/frontends/qt4/Makefile.am | 3 +- src/support/Makefile.am | 3 +- src/tex2lyx/Makefile.am | 4 +-- 12 files changed, 187 insertions(+), 40 deletions(-) create mode 100644 m4/eilseq.m4 diff --git a/3rdparty/Makefile.am b/3rdparty/Makefile.am index 54ab6c4e63..f936a4c753 100644 --- a/3rdparty/Makefile.am +++ b/3rdparty/Makefile.am @@ -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) diff --git a/3rdparty/libiconv/Makefile.am b/3rdparty/libiconv/Makefile.am index d965f380f1..d03032d131 100644 --- a/3rdparty/libiconv/Makefile.am +++ b/3rdparty/libiconv/Makefile.am @@ -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 \ diff --git a/config/lyxinclude.m4 b/config/lyxinclude.m4 index df17da8843..84f66880a2 100644 --- a/config/lyxinclude.m4 +++ b/config/lyxinclude.m4 @@ -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 is standalone], + [gl_cv_header_wchar_h_standalone], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + 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],[ diff --git a/configure.ac b/configure.ac index 6de63c9fd7..3b1a900ddb 100644 --- a/configure.ac +++ b/configure.ac @@ -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 + 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 - 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 \ diff --git a/m4/Makefile.am b/m4/Makefile.am index 2fd4fbb176..6f02330e4c 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -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 index 0000000000..792d514b59 --- /dev/null +++ b/m4/eilseq.m4 @@ -0,0 +1,67 @@ +#serial 1 + +AC_PREREQ(2.50) + +# The EILSEQ errno value ought to be defined in , 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 not . + +# Define EILSEQ as a C macro and as a substituted macro in such a way that +# 1. on all systems, after inclusion of , 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 +#ifdef EILSEQ +yes +#endif + ], have_eilseq=1) + if test -n "$have_eilseq"; then + dnl EILSEQ exists in . Don't need to define EILSEQ ourselves. + ac_cv_decl_EILSEQ=yes + else + AC_EGREP_CPP(yes,[ +#include +#if HAVE_WCHAR_H +#include +#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 +#if HAVE_WCHAR_H +#include +#endif +/* The following two lines are a workaround against an autoconf-2.52 bug. */ +#include +#include +]) + 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 +]) diff --git a/src/Makefile.am b/src/Makefile.am index c0e4d5844e..8166b11ff4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 131c56a6c3..3874376ab4 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -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 diff --git a/src/frontends/Makefile.am b/src/frontends/Makefile.am index 0a615e1903..862613a67f 100644 --- a/src/frontends/Makefile.am +++ b/src/frontends/Makefile.am @@ -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 diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 3358186ccb..fb21eb692e 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -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 \ diff --git a/src/support/Makefile.am b/src/support/Makefile.am index d1137290ee..29f003b85d 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -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 = \ diff --git a/src/tex2lyx/Makefile.am b/src/tex2lyx/Makefile.am index e29356754f..bf2d66d67f 100644 --- a/src/tex2lyx/Makefile.am +++ b/src/tex2lyx/Makefile.am @@ -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 \