Commit b6be272ec1baa16adb3502895f361f443054ccd9

Guillem Jover 2017-05-31T06:45:25

build: Detect version script linker support at configure time This is not a widely supported feature, so only use if in case the linker does support it. Proposed-by: Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>

diff --git a/.gitignore b/.gitignore
index 3dd8333..affc47b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,5 +20,4 @@ Makefile.in
 /config.*
 /configure
 /libtool
-/m4/
 /stamp-h1
diff --git a/Makefile.am b/Makefile.am
index b839ae1..afb2fdc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,6 +7,7 @@ ACLOCAL_AMFLAGS = -I m4
 EXTRA_DIST = \
 	autogen \
 	get-version \
+	m4/libmd-linker.m4 \
 	$(nil)
 
 dist-hook:
diff --git a/autogen b/autogen
index 7cf1815..2e71cf6 100755
--- a/autogen
+++ b/autogen
@@ -1,5 +1,4 @@
 #!/bin/sh
 
-mkdir -p m4
 autoreconf -f -i
 rm -rf autom4te.cache
diff --git a/configure.ac b/configure.ac
index 633605f..9baffad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,6 +24,7 @@ AC_SYS_LARGEFILE
 
 AM_PROG_AR
 LT_INIT
+LIBMD_LINKER_VERSION_SCRIPT
 
 # Checks for programs.
 AC_PROG_CC
diff --git a/m4/.gitignore b/m4/.gitignore
new file mode 100644
index 0000000..9d6d77a
--- /dev/null
+++ b/m4/.gitignore
@@ -0,0 +1,2 @@
+*.m4
+!libmd*.m4
diff --git a/m4/libmd-linker.m4 b/m4/libmd-linker.m4
new file mode 100644
index 0000000..7d1236a
--- /dev/null
+++ b/m4/libmd-linker.m4
@@ -0,0 +1,22 @@
+# Copyright © 2014 Guillem Jover <guillem@hadrons.org>
+
+# LIBMD_LINKER_VERSION_SCRIPT
+# --------------------------
+AC_DEFUN([LIBMD_LINKER_VERSION_SCRIPT], [
+  AC_CACHE_CHECK([for --version-script linker flag], [libmd_cv_version_script], [
+    echo "{ global: symbol; local: *; };" >conftest.map
+    save_LDFLAGS=$LDFLAGS
+    LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
+    AC_LINK_IFELSE([
+      AC_LANG_PROGRAM([], [])
+    ], [
+      libmd_cv_version_script=yes
+    ], [
+      libmd_cv_version_script=no
+    ])
+    LDFLAGS="$save_LDFLAGS"
+    rm -f conftest.map
+  ])
+  AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
+    [test "x$libmd_cv_version_script" = "xyes"])
+])
diff --git a/src/Makefile.am b/src/Makefile.am
index 77f677f..62cba25 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,8 +25,11 @@ libmd_la_helper_sources = \
 
 libmd_la_LDFLAGS = \
 	-no-undefined \
-	-Wl,--version-script=$(srcdir)/libmd.map \
 	-version-number $(LIBMD_ABI)
+if HAVE_LINKER_VERSION_SCRIPT
+libmd_la_LDFLAGS += \
+	-Wl,--version-script=$(srcdir)/libmd.map
+endif
 libmd_la_DEPENDENCIES = \
 	libmd.map \
 	helper.c \