From b6d6da4cd46ac2c20bd8febe935e1af3ae96c4a9 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 20 Feb 2024 04:40:32 +0100 Subject: [PATCH] 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. --- configure.ac | 49 ++------------------------------------- m4/libbsd-funcs.m4 | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 47 deletions(-) create mode 100644 m4/libbsd-funcs.m4 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 - ]], [[ -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 -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 -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 + +# LIBBSD_CHECK_PROGNAME +# --------------------- +AC_DEFUN([LIBBSD_CHECK_PROGNAME], [ + AC_MSG_CHECKING([for program_invocation_short_name]) + AC_LINK_IFELSE([ + AC_LANG_PROGRAM([[ +#include + ]], [[ +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 +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 +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]) + ]) +])