build: Detect support for --version-script in ld
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/configure.ac b/configure.ac
index 6e9496d..e8d4c5f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,25 @@ AC_SYS_LARGEFILE
LT_INIT
+AC_CACHE_CHECK([if ld supports --version-script flag],
+ [libbsd_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([], [])
+ ], [
+ libbsd_cv_version_script=yes
+ ], [
+ libbsd_cv_version_script=no
+ ])
+ LDFLAGS="$save_LDFLAGS"
+ rm -f conftest.map
+ ]
+)
+AM_CONDITIONAL([HAVE_LINKER_VERSION_SCRIPT],
+ [test "x$libbsd_cv_version_script" = "xyes"])
+
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
diff --git a/src/Makefile.am b/src/Makefile.am
index 8384b92..c4229cf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -65,8 +65,11 @@ libbsd_la_LIBADD = \
$(ARC4RANDOM_ATFORK_LIBS) \
$(nil)
libbsd_la_LDFLAGS = \
- -Wl,--version-script=$(srcdir)/libbsd.map \
-version-number $(LIBBSD_ABI)
+if HAVE_LINKER_VERSION_SCRIPT
+libbsd_la_LDFLAGS += \
+ -Wl,--version-script=$(srcdir)/libbsd.map
+endif
libbsd_la_SOURCES = \
arc4random.c \
arc4random.h \