]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
build: Refactor GNU .init_array support check into a new m4 function
authorGuillem Jover <guillem@hadrons.org>
Fri, 26 May 2023 21:55:40 +0000 (23:55 +0200)
committerGuillem Jover <guillem@hadrons.org>
Tue, 5 Sep 2023 01:02:12 +0000 (03:02 +0200)
configure.ac
m4/libbsd-compiler.m4

index 40d25b97f978c809c77551e6b57aa6d84fadf105..8ff2bef0c944281656fc40f0c30d572df6b61847 100644 (file)
@@ -184,49 +184,7 @@ AC_CHECK_DECLS([environ], [], [], [[
 #include <unistd.h>
 ]])
 
-AC_CACHE_CHECK([for GNU .init_array section support],
-  [libbsd_cv_gnu_init_array_support], [
-  AC_RUN_IFELSE([
-    AC_LANG_SOURCE([[
-static int rc = 1;
-static void init(int argc) { if (argc == 1) rc = 0; }
-void (*init_func)(int argc) __attribute__((__section__(".init_array"), __used__)) = init;
-int main() { return rc; }
-    ]])
-  ], [
-    libbsd_cv_gnu_init_array_support=yes
-  ], [
-    libbsd_cv_gnu_init_array_support=no
-  ], [
-    AC_PREPROC_IFELSE([
-      AC_LANG_SOURCE([[
-/* Look for a known libc that supports .init_array with the GNU extension
- * to pass main() arguments to the init functions. */
-#include <stdlib.h>
-#if defined __GLIBC_PREREQ
-#  if __GLIBC_PREREQ(2, 4)
-/* glibc supports GNU .init_array since 2.4. */
-#  else
-#    error glibc does not support GNU .init_array
-#  endif
-#else
-/*
- * Basic SysV ABI .init_array support, init functions do not get arguments:
- * - Bionic since its inception.
- * - uClibc since 0.9.29.
- */
-#  error unknown whether libc supports GNU .init_array
-#endif
-      ]])
-    ], [
-      libbsd_cv_gnu_init_array_support=yes
-    ], [
-      libbsd_cv_gnu_init_array_support=no
-    ])
-  ])
-])
-AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
-  [test "$libbsd_cv_gnu_init_array_support" = yes])
+LIBBSD_HAS_GNU_INIT_ARRAY
 
 # Checks for library functions.
 AC_MSG_CHECKING([for program_invocation_short_name])
index b655b83b7ab0edfdf1011112bc15d7db1b6485ad..dd8fbeb73e1b40cac41fc03a649fc1b1a8dca371 100644 (file)
@@ -22,3 +22,51 @@ AC_DEFUN([LIBBSD_CHECK_COMPILER_FLAG], [
   ])
   AS_VAR_POPDEF([libbsd_varname_cache])
 ])
+
+# LIBBSD_HAS_GNU_INIT_ARRAY
+# -------------------------
+AC_DEFUN([LIBBSD_HAS_GNU_INIT_ARRAY], [
+  AC_CACHE_CHECK([for GNU .init_array section support],
+    [libbsd_cv_gnu_init_array_support], [
+    AC_RUN_IFELSE([
+      AC_LANG_SOURCE([[
+static int rc = 1;
+static void init(int argc) { if (argc == 1) rc = 0; }
+void (*init_func)(int argc) __attribute__((__section__(".init_array"), __used__)) = init;
+int main() { return rc; }
+      ]])
+    ], [
+      libbsd_cv_gnu_init_array_support=yes
+    ], [
+      libbsd_cv_gnu_init_array_support=no
+    ], [
+      AC_PREPROC_IFELSE([
+        AC_LANG_SOURCE([[
+/* Look for a known libc that supports .init_array with the GNU extension
+ * to pass main() arguments to the init functions. */
+#include <stdlib.h>
+#if defined __GLIBC_PREREQ
+#  if __GLIBC_PREREQ(2, 4)
+/* glibc supports GNU .init_array since 2.4. */
+#  else
+#    error glibc does not support GNU .init_array
+#  endif
+#else
+/*
+ * Basic SysV ABI .init_array support, init functions do not get arguments:
+ * - Bionic since its inception.
+ * - uClibc since 0.9.29.
+ */
+#  error unknown whether libc supports GNU .init_array
+#endif
+        ]])
+      ], [
+        libbsd_cv_gnu_init_array_support=yes
+      ], [
+        libbsd_cv_gnu_init_array_support=no
+      ])
+    ])
+  ])
+  AM_CONDITIONAL([BUILD_LIBBSD_CTOR],
+    [test "$libbsd_cv_gnu_init_array_support" = yes])
+])