Sync from coreutils.
[pspp] / m4 / lib-ignore.m4
1 # If possible, ignore libraries that are not depended on.
2
3 dnl Copyright (C) 2006 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 dnl Written by Paul Eggert.
9
10 AC_DEFUN([gl_IGNORE_UNUSED_LIBRARIES],
11 [
12   AC_CACHE_CHECK([for flag to ignore unused libraries],
13     [gl_cv_ignore_unused_libraries],
14     [gl_cv_ignore_unused_libraries=none
15      AC_LINK_IFELSE([AC_LANG_PROGRAM()],
16        [gl_ldd_output0=`(ldd conftest$ac_exeext) 2>/dev/null` ||
17           gl_ldd_output0=])
18      if test "$gl_ldd_output0"; then
19        gl_saved_ldflags=$LDFLAGS
20        gl_saved_libs=$LIBS
21        LIBS="$LIBS -lm"
22        AC_LINK_IFELSE([AC_LANG_PROGRAM()],
23          [gl_ldd_output1=`(ldd conftest$ac_exeext) 2>/dev/null` ||
24             gl_ldd_output1=])
25        if test "$gl_ldd_output1" && test "$gl_ldd_output0" != "$gl_ldd_output1"
26        then
27          for gl_flags in '-Xlinker -zignore' '-zignore'; do
28            LDFLAGS="$gl_flags $LDFLAGS"
29            AC_LINK_IFELSE([AC_LANG_PROGRAM()],
30              [if gl_ldd_output2=`(ldd conftest$ac_exeext) 2>/dev/null` &&
31                  test "$gl_ldd_output0" = "$gl_ldd_output2"; then
32                 gl_cv_ignore_unused_libraries=$gl_flags
33               fi])
34            LDFLAGS=$gl_saved_ldflags
35            test "gl_cv_ignore_unused_libraries" != none && break
36          done
37        fi
38        LIBS=$gl_saved_LIBS
39      fi])
40
41   test "$gl_cv_ignore_unused_libraries" != none &&
42     LDFLAGS="$LDFLAGS $gl_cv_ignore_unused_libraries"
43 ])