summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego E. 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-11-19 03:25:40 +0100
committerDiego E. 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-11-19 03:25:40 +0100
commitdd77c8383c1a759e909ac3185160cfed6e765b9c (patch)
treece13a44ec0e3d7e4b2c578e22a4488d66111551c
parent30b99053ed08eb6260b4f9fc6f39634e8953d6e5 (diff)
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.
-rw-r--r--configure.ac2
-rw-r--r--libasyncns/Makefile.am2
-rw-r--r--m4/attributes.m425
3 files changed, 28 insertions, 1 deletions
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