configure: use minimal LIBS during gettext check In some configurations, vim fails to link correctly with messages such as: edit.c:(.text+0x1614): undefined reference to `libintl_gettext' In particular, this has been seen by the buildroot autobuilds (see [1]) but has also been reported at [2] and [3]. In the bad case, the configure script says: checking for NLS... gettext() works In the good case, it says: checking for NLS... gettext() works with -lintl In the bad case, the system has libelf, vim detects that and takes it along in $LIBS. Libelf needs libintl on this system, and so linking the test program with -lelf will automatically take -lintl too. This causes configure to think gettext() does not need libintl, while in reality it does. In the good case, libelf is not present and thus not used. The first configure test for gettext fails, and then configure retries with -lintl (which succeeds). Until now, there isn't really a problem. In both cases, you could link correctly. In the 'bad' case, libintl is implicitly taken through libelf, in the second case it is explicitly taken. The real problem occurs because configure also tests whether the linker supports --as-needed and uses it when possible, instead of the link.sh script. However, --as-needed seems to cause libintl NOT to be taken in the bad case, causing the undefined references to libintl_gettext. This patch changes the configure script so that the gettext check does not use additional libraries such as libelf. The test program is linked either with nothing, or with libintl alone. This will cause libintl to be added explicitly to LIBS, when needed. [1] http://autobuild.buildroot.net/results/21b5a910e6a27fa1cb12d0002ffed7e6ed9d6c83/ [2] http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2012-November/243930.html [3] http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2012-May/234184.html Signed-off-by: Thomas De Schampheleire Upstream-status: accepted (http://article.gmane.org/gmane.editors.vim.devel/43528) --- src/auto/configure | 11 ++++++----- src/configure.in | 13 +++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/auto/configure b/src/auto/configure --- a/src/auto/configure +++ b/src/auto/configure @@ -12271,6 +12271,8 @@ fi if test -f po/Makefile; then have_gettext="no" if test -n "$MSGFMT"; then + olibs=$LIBS + LIBS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include @@ -12284,10 +12286,9 @@ gettext("Test"); _ACEOF if ac_fn_c_try_link "$LINENO"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: gettext() works" >&5 -$as_echo "gettext() works" >&6; }; have_gettext="yes" -else - olibs=$LIBS - LIBS="$LIBS -lintl" +$as_echo "gettext() works" >&6; }; have_gettext="yes"; LIBS=$olibs; +else + LIBS="-lintl" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include @@ -12301,7 +12302,7 @@ gettext("Test"); _ACEOF if ac_fn_c_try_link "$LINENO"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: gettext() works with -lintl" >&5 -$as_echo "gettext() works with -lintl" >&6; }; have_gettext="yes" +$as_echo "gettext() works with -lintl" >&6; }; have_gettext="yes"; LIBS="$olibs -lintl"; else { $as_echo "$as_me:${as_lineno-$LINENO}: result: gettext() doesn't work" >&5 $as_echo "gettext() doesn't work" >&6; }; diff --git a/src/configure.in b/src/configure.in --- a/src/configure.in +++ b/src/configure.in @@ -3484,6 +3484,9 @@ if test "$MANDEF" = "man -s"; then fi dnl Check if gettext() is working and if it needs -lintl +dnl We take care to base this on an empty LIBS: on some systems libelf would be +dnl in LIBS and implicitly take along libintl. The final LIBS would then not +dnl contain libintl, and the link step would fail due to -Wl,--as-needed. AC_MSG_CHECKING(--disable-nls argument) AC_ARG_ENABLE(nls, [ --disable-nls Don't support NLS (gettext()).], , @@ -3502,16 +3505,18 @@ if test "$enable_nls" = "yes"; then if test -f po/Makefile; then have_gettext="no" if test -n "$MSGFMT"; then + olibs=$LIBS + LIBS="" AC_TRY_LINK( [#include ], [gettext("Test");], - AC_MSG_RESULT([gettext() works]); have_gettext="yes", - olibs=$LIBS - LIBS="$LIBS -lintl" + AC_MSG_RESULT([gettext() works]); have_gettext="yes"; LIBS=$olibs, + LIBS="-lintl" AC_TRY_LINK( [#include ], [gettext("Test");], - AC_MSG_RESULT([gettext() works with -lintl]); have_gettext="yes", + AC_MSG_RESULT([gettext() works with -lintl]); have_gettext="yes"; + LIBS="$olibs -lintl", AC_MSG_RESULT([gettext() doesn't work]); LIBS=$olibs)) else