* lib-ignore.m4 (gl_IGNORE_UNUSED_LIBRARIES): Use -Wl,-z,ignore
[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 '-Wl,-z,ignore' '-z ignore'; do
19        LDFLAGS="$gl_flags $LDFLAGS"
20        AC_LINK_IFELSE([AC_LANG_PROGRAM()],
21          [gl_cv_ignore_unused_libraries=$gl_flags])
22        LDFLAGS=$gl_saved_ldflags
23        test "$gl_cv_ignore_unused_libraries" != none && break
24      done])
25
26   test "$gl_cv_ignore_unused_libraries" != none &&
27     LDFLAGS="$LDFLAGS $gl_cv_ignore_unused_libraries"
28 ])