From dd77c8383c1a759e909ac3185160cfed6e765b9c Mon Sep 17 00:00:00 2001 From: "Diego E. 'Flameeyes' Pettenò" Date: Wed, 19 Nov 2008 03:25:40 +0100 Subject: Check if the linker has an option to refuse undefined references. This ensures that hte library will be built in a way that will not fail when --as-needed is used. --- configure.ac | 2 ++ libasyncns/Makefile.am | 2 +- m4/attributes.m4 | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d6a505e..d08f1b9 100644 --- a/configure.ac +++ b/configure.ac @@ -83,6 +83,8 @@ ACF_SEARCH_FUNCTION([res_query], [-lresolv, -lbind], ACX_PTHREAD +CC_NOUNDEFINED + ZP_LYNX_DOC AC_CONFIG_FILES([Makefile libasyncns/Makefile doc/Makefile doc/README.html doxygen/Makefile doxygen/doxygen.conf libasyncns.pc]) diff --git a/libasyncns/Makefile.am b/libasyncns/Makefile.am index 40e989f..0b38163 100644 --- a/libasyncns/Makefile.am +++ b/libasyncns/Makefile.am @@ -21,7 +21,7 @@ AM_CFLAGS=-D__EXTENSIONS__ $(PTHREAD_CFLAGS) lib_LTLIBRARIES=libasyncns.la libasyncns_la_CC=$(PTHREAD_CC) libasyncns_la_SOURCES=asyncns.c asyncns.h -libasyncns_la_LDFLAGS=-version-info $(LIBASYNCNS_VERSION_INFO) +libasyncns_la_LDFLAGS=-version-info $(LIBASYNCNS_VERSION_INFO) $(LDFLAGS_NOUNDEFINED) libasyncns_la_LIBADD=$(PTHREAD_LIBS) check_PROGRAMS=asyncns-test diff --git a/m4/attributes.m4 b/m4/attributes.m4 index 45ea789..e86456a 100644 --- a/m4/attributes.m4 +++ b/m4/attributes.m4 @@ -99,6 +99,31 @@ AC_DEFUN([CC_CHECK_LDFLAGS], [ [$2], [$3]) ]) +dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for +dnl the current linker to avoid undefined references in a shared object. +AC_DEFUN([CC_NOUNDEFINED], [ + dnl We check $host for which systems to enable this for. + AC_REQUIRE([AC_CANONICAL_HOST]) + + case $host in + dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads + dnl are requested, as different implementations are present; to avoid problems + dnl use -Wl,-z,defs only for those platform not behaving this way. + *-freebsd*) ;; + *) + dnl First of all check for the --no-undefined variant of GNU ld. This allows + dnl for a much more readable commandline, so that people can understand what + dnl it does without going to look for what the heck -z defs does. + for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do + CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"]) + break + done + ;; + esac + + AC_SUBST([LDFLAGS_NOUNDEFINED]) +]) + dnl Check for a -Werror flag or equivalent. -Werror is the GCC dnl and ICC flag that tells the compiler to treat all the warnings dnl as fatal. We usually need this option to make sure that some -- cgit