* lib-ignore.m4 (gl_IGNORE_UNUSED_LIBRARIES): Don't use ldd, as
[gnulib.git] / 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      gl_saved_ldflags=$LDFLAGS
16      # Use long option sequences like '-z ignore' to test for the feature,
17      # to forestall problems with linkers that have -z, -i, -g, -n, etc. flags.
18      for gl_flags in '-Xlinker -z -Xlinker ignore' '-z ignore'; do
19        LDFLAGS="$gl_flags $LDFLAGS"
20        AC_LINK_IFELSE([AC_LANG_PROGRAM()],
21          [case $gl_flags in
22             '-Xlinker -z -Xlinker ignore')
23               # Shorten this ugly thing, for prettier 'make' output.
24               gl_cv_ignore_unused_libraries='-Xlinker -zignore';;
25             *)
26               gl_cv_ignore_unused_libraries=$gl_flags;;
27           esac])
28        LDFLAGS=$gl_saved_ldflags
29        test "$gl_cv_ignore_unused_libraries" != none && break
30      done])
31
32   test "$gl_cv_ignore_unused_libraries" != none &&
33     LDFLAGS="$LDFLAGS $gl_cv_ignore_unused_libraries"
34 ])