build: Refactor function checks into a new libbsd-funcs.m4 file These are complex enough to clutter the main configure.ac. Move them into their own file.
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
diff --git a/configure.ac b/configure.ac
index 7878743..b9930e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -187,53 +187,8 @@ AC_CHECK_DECLS([environ], [], [], [[
LIBBSD_HAS_GNU_INIT_ARRAY
# Checks for library functions.
-AC_MSG_CHECKING([for program_invocation_short_name])
-AC_LINK_IFELSE([
- AC_LANG_PROGRAM([[
-#include <errno.h>
- ]], [[
-const char *p = program_invocation_short_name;
- ]])
-], [
- AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
- [Define to 1 if you have program_invocation_short_name])
- AC_MSG_RESULT([yes])
-], [
- AC_MSG_RESULT([no])
-])
-
-AC_MSG_CHECKING([for __progname])
-AC_LINK_IFELSE([
- AC_LANG_PROGRAM([[
-#include <stdio.h>
-extern char *__progname;
- ]], [[
-printf("%s", __progname);
- ]])
-], [
- AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
- AC_MSG_RESULT([yes])
-], [
- AC_MSG_RESULT([no])
-])
-
-AC_MSG_CHECKING([for __register_atfork])
-AC_LINK_IFELSE([
- AC_LANG_PROGRAM([[
-#include <stddef.h>
-extern void *__dso_handle;
-extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
- ]], [[
-__register_atfork(NULL, NULL, NULL, __dso_handle);
- ]])
-], [
- AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
- [Define to 1 if you have __register_atfork])
- AC_MSG_RESULT([yes])
-], [
- LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
- AC_MSG_RESULT([no])
-])
+LIBBSD_CHECK_PROGNAME
+LIBBSD_CHECK_REGISTER_ATFORK
AC_CHECK_FUNCS([\
clearenv \
diff --git a/m4/libbsd-funcs.m4 b/m4/libbsd-funcs.m4
new file mode 100644
index 0000000..379afc5
--- /dev/null
+++ b/m4/libbsd-funcs.m4
@@ -0,0 +1,57 @@
+# Copyright © 2011-2024 Guillem Jover <guillem@hadrons.org>
+
+# LIBBSD_CHECK_PROGNAME
+# ---------------------
+AC_DEFUN([LIBBSD_CHECK_PROGNAME], [
+ AC_MSG_CHECKING([for program_invocation_short_name])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([[
+#include <errno.h>
+ ]], [[
+const char *p = program_invocation_short_name;
+ ]])
+ ], [
+ AC_DEFINE([HAVE_PROGRAM_INVOCATION_SHORT_NAME], [1],
+ [Define to 1 if you have program_invocation_short_name])
+ AC_MSG_RESULT([yes])
+ ], [
+ AC_MSG_RESULT([no])
+ ])
+
+ AC_MSG_CHECKING([for __progname])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([[
+#include <stdio.h>
+extern char *__progname;
+ ]], [[
+printf("%s", __progname);
+ ]])
+ ], [
+ AC_DEFINE([HAVE___PROGNAME], [1], [Define to 1 if you have __progname])
+ AC_MSG_RESULT([yes])
+ ], [
+ AC_MSG_RESULT([no])
+ ])
+])
+
+# LIBBSD_CHECK_REGISTER_ATFORK
+# ----------------------------
+AC_DEFUN([LIBBSD_CHECK_REGISTER_ATFORK], [
+ AC_MSG_CHECKING([for __register_atfork])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([[
+#include <stddef.h>
+extern void *__dso_handle;
+extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
+ ]], [[
+__register_atfork(NULL, NULL, NULL, __dso_handle);
+ ]])
+ ], [
+ AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
+ [Define to 1 if you have __register_atfork])
+ AC_MSG_RESULT([yes])
+ ], [
+ LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
+ AC_MSG_RESULT([no])
+ ])
+])