- AC_LINK_IFELSE([AC_LANG_PROGRAM()],
- [gl_ldd_output0=`(ldd conftest$ac_exeext) 2>/dev/null` ||
- gl_ldd_output0=])
- if test "$gl_ldd_output0"; then
- gl_saved_ldflags=$LDFLAGS
- gl_saved_libs=$LIBS
- LIBS="$LIBS -lm"
+ gl_saved_ldflags=$LDFLAGS
+ gl_saved_libs=$LIBS
+ # Link with -lm to detect binutils 2.16 bug with --as-needed; see
+ # <http://lists.gnu.org/archive/html/bug-gnulib/2006-06/msg00131.html>.
+ LIBS="$LIBS -lm"
+ # Use long option sequences like '-z ignore' to test for the feature,
+ # to forestall problems with linkers that have -z, -i, -g, -n, etc. flags.
+ # GCC + binutils likes '-Wl,--as-needed'.
+ # GCC + Solaris ld likes '-Wl,-z,ignore'.
+ # Sun C likes '-z ignore'.
+ # Don't try bare '--as-needed'; nothing likes it and the HP-UX 11.11
+ # native cc issues annoying warnings and then ignores it,
+ # which would cause us to incorrectly conclude that it worked.
+ for gl_flags in \
+ '-Wl,--as-needed' \
+ '-Wl,-z,ignore' \
+ '-z ignore'
+ do
+ LDFLAGS="$gl_flags $LDFLAGS"