diff options
author | Thomas White <taw@bitwiz.org.uk> | 2011-01-16 18:23:31 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:11 +0100 |
commit | 63dc461a73ba698ccbab42ae3d4427810b1af14e (patch) | |
tree | 7dfdab8d4d0b30269e718ec95f18141af54f3e82 /m4 | |
parent | 63039a76484b181e18a76144f7c38b1467dd861b (diff) |
Use gl_IGNORE_UNUSED_LIBRARIES
Diffstat (limited to 'm4')
-rw-r--r-- | m4/gnulib-cache.m4 | 3 | ||||
-rw-r--r-- | m4/gnulib-comp.m4 | 4 | ||||
-rw-r--r-- | m4/lib-ignore.m4 | 115 |
3 files changed, 121 insertions, 1 deletions
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index 564eb307..e09ed2cb 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -15,11 +15,12 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-libtool --macro-prefix=gl strndup +# gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-libtool --macro-prefix=gl lib-ignore strndup # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([]) gl_MODULES([ + lib-ignore strndup ]) gl_AVOID([]) diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 032577bd..4b97830a 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -31,6 +31,7 @@ AC_DEFUN([gl_EARLY], # Code from module extensions: AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) # Code from module include_next: + # Code from module lib-ignore: # Code from module memchr: # Code from module stddef: # Code from module string: @@ -59,6 +60,8 @@ AC_DEFUN([gl_INIT], # Code from module c++defs: # Code from module extensions: # Code from module include_next: + # Code from module lib-ignore: + gl_IGNORE_UNUSED_LIBRARIES # Code from module memchr: gl_FUNC_MEMCHR gl_STRING_MODULE_INDICATOR([memchr]) @@ -228,6 +231,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/extensions.m4 m4/gnulib-common.m4 m4/include_next.m4 + m4/lib-ignore.m4 m4/memchr.m4 m4/mmap-anon.m4 m4/onceonly.m4 diff --git a/m4/lib-ignore.m4 b/m4/lib-ignore.m4 new file mode 100644 index 00000000..a67b002c --- /dev/null +++ b/m4/lib-ignore.m4 @@ -0,0 +1,115 @@ +# If possible, ignore libraries that are not depended on. + +dnl Copyright (C) 2006, 2009-2010 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Paul Eggert. + +# gl_IGNORE_UNUSED_LIBRARIES +# -------------------------- +# Determines the option to be passed to the C/C++/Fortran compiler, so that it +# omits unused libraries. +# Example (on Solaris): +# $ cc foo.c -lnsl; ldd ./a.out +# libnsl.so.1 => /lib/libnsl.so.1 +# libc.so.1 => /lib/libc.so.1 +# libmp.so.2 => /lib/libmp.so.2 +# libmd.so.1 => /lib/libmd.so.1 +# libscf.so.1 => /lib/libscf.so.1 +# libdoor.so.1 => /lib/libdoor.so.1 +# libuutil.so.1 => /lib/libuutil.so.1 +# libgen.so.1 => /lib/libgen.so.1 +# libm.so.2 => /lib/libm.so.2 +# $ cc foo.c -lnsl -Wl,-z,ignore; ldd ./a.out +# libc.so.1 => /lib/libc.so.1 +# libm.so.2 => /lib/libm.so.2 +# +# Note that the option works only for the C compiler, not for the C++ +# compiler: +# - Sun C likes '-Wl,-z,ignore'. +# '-Qoption ld -z,ignore' is not accepted. +# '-z ignore' is accepted but has no effect. +# - Sun C++ and Sun Fortran like '-Qoption ld -z,ignore'. +# '-Wl,-z,ignore' is not accepted. +# '-z ignore' is accepted but has no effect. +# +# Sets and substitutes a variable that depends on the current language: +# - IGNORE_UNUSED_LIBRARIES_CFLAGS for C +# - IGNORE_UNUSED_LIBRARIES_CXXFLAGS for C++ +# - IGNORE_UNUSED_LIBRARIES_FFLAGS for Fortran +# +# Note that the option works only for direct invocation of the compiler, not +# through libtool: When libtool is used to create a shared library, it will +# honor and translate '-Wl,-z,ignore' to '-Qoption ld -z -Qoption ld ignore' +# if needed, but it will drop a '-Qoption ld -z,ignore' on the command line. +# +AC_DEFUN([gl_IGNORE_UNUSED_LIBRARIES], +[ + AC_CACHE_CHECK([for []_AC_LANG[] compiler flag to ignore unused libraries], + [gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries], + [gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries=none + 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 '-Wl,-z,ignore'. '-z ignore' is accepted but has no effect. + # 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 _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS + do + LDFLAGS="$gl_flags $LDFLAGS" + AC_LINK_IFELSE([AC_LANG_PROGRAM()], + [gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries=$gl_flags]) + LDFLAGS=$gl_saved_ldflags + test "$gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries" != none && + break + done + LIBS=$gl_saved_libs + ]) + IGNORE_UNUSED_LIBRARIES_[]_AC_LANG_PREFIX[]FLAGS= + if test "$gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries" != none; then + IGNORE_UNUSED_LIBRARIES_[]_AC_LANG_PREFIX[]FLAGS="$gl_cv_prog_[]_AC_LANG_ABBREV[]_ignore_unused_libraries" + fi + AC_SUBST([IGNORE_UNUSED_LIBRARIES_]_AC_LANG_PREFIX[FLAGS]) +]) + +# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS +# ----------------------------------- +# Expands to the language dependent options to be tried. +AC_DEFUN([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS], +[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) + +# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C) +# -------------------------------------- +m4_define([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C)], +[ '-Wl,--as-needed' \ + '-Wl,-z,ignore' \ + '-z ignore' +]) + +# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C++) +# ---------------------------------------- +m4_define([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C++)], +[ '-Wl,--as-needed' \ + '-Qoption ld -z,ignore' \ + '-Wl,-z,ignore' \ + '-z ignore' +]) + +# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran 77) +# ----------------------------------------------- +m4_copy([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(C++)], + [_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran 77)]) + +# _gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran) +# -------------------------------------------- +m4_copy([_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran 77)], + [_gl_IGNORE_UNUSED_LIBRARIES_OPTIONS(Fortran)]) |