build: Refactor linker script detection into a new m4 function
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
diff --git a/configure.ac b/configure.ac
index aabe28e..40d25b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,28 +32,7 @@ AC_SYS_LARGEFILE
AM_PROG_AR
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([[
-extern int symbol(void);
-int symbol(void) { return 0; }
-]], [[
-]])
- ], [
- 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"])
+LIBBSD_LINKER_VERSION_SCRIPT
is_windows=no
AS_CASE([$host_os],
diff --git a/m4/libbsd-linker.m4 b/m4/libbsd-linker.m4
new file mode 100644
index 0000000..394bac5
--- /dev/null
+++ b/m4/libbsd-linker.m4
@@ -0,0 +1,27 @@
+# Copyright © 2019, 2022 Guillem Jover <guillem@hadrons.org>
+
+# LIBBSD_LINKER_VERSION_SCRIPT
+# ----------------------------
+AC_DEFUN([LIBBSD_LINKER_VERSION_SCRIPT], [
+ 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([[
+extern int symbol(void);
+int symbol(void) { return 0; }
+]], [[
+]])
+ ], [
+ 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"])
+])