]> git.draconx.ca Git - dxcommon.git/commitdiff
Add a configure test for syslog support.
authorNick Bowler <nbowler@draconx.ca>
Sat, 29 Jul 2023 00:07:28 +0000 (20:07 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sat, 29 Jul 2023 02:11:34 +0000 (22:11 -0400)
m4/syslog.m4 [new file with mode: 0644]
t/libdummy.c
tests/libs.at

diff --git a/m4/syslog.m4 b/m4/syslog.m4
new file mode 100644 (file)
index 0000000..8262170
--- /dev/null
@@ -0,0 +1,26 @@
+dnl Copyright © 2021, 2023 Nick Bowler
+dnl
+dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+dnl This is free software: you are free to do what the fuck you want to.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+dnl DX_CHECK_SYSLOG
+dnl
+dnl Expands AC_CHECK_HEADERS([syslog.h])
+dnl
+dnl Then, if syslog.h is available, checks that a program can be linked
+dnl against the syslog family of functions.
+dnl
+dnl If successful, the cache variable dx_cv_have_syslog is set to "yes".
+dnl Otherwise, dx_cv_have_syslog is set to "no".
+AC_DEFUN([DX_CHECK_SYSLOG],
+[AC_CHECK_HEADERS([syslog.h], [], [], [@&t@])
+AS_IF([test x"$ac_cv_header_syslog_h" = x"yes"],
+  [AC_CACHE_CHECK([for syslog], [dx_cv_have_syslog],
+    [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <syslog.h>],
+[openlog("conftest", LOG_PID, LOG_USER);
+syslog(LOG_ERR, "%s", "hello");
+closelog();])], [dx_cv_have_syslog=yes], [dx_cv_have_syslog=no])])])
+AS_IF([test x"$dx_cv_have_syslog" = x"yes"],
+  [AC_DEFINE([HAVE_SYSLOG], [1],
+    [Define to 1 if syslog et al. are available.])])])
index 3e40d130941eef1390dca6b66304db67d77aa852..1bfa48afe7896d1d0b79ff8b5f9c210bb9d34efd 100644 (file)
@@ -14,3 +14,5 @@ unsigned long mousemask(unsigned long a, unsigned long *b) { return 0; }
 struct MEVENT;
 int getmouse_nc_(struct MEVENT *mev) { return 0; }
 int getmouse_bogus_(void *p) { return 0; }
+
+void dx_closelog(void) { }
index 1d327cc1afcc335b27d852120f9326c471b31de9..f7cf534739fb5abcdcf29111df8c1c4b7d23d11d 100644 (file)
@@ -1,4 +1,4 @@
-dnl Copyright © 2019-2020, 2022 Nick Bowler
+dnl Copyright © 2019-2020, 2022-2023 Nick Bowler
 dnl
 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 dnl This is free software: you are free to do what the fuck you want to.
@@ -355,3 +355,43 @@ AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
 ])
 
 AT_CLEANUP
+
+AT_SETUP([DX_CHECK_SYSLOG])
+
+AT_DATA([syslog.h],
+[[/* since syslog is normally in the standard C library, to make negative
+link tests possible we use a dummy external name */
+extern void dx_closelog(void);
+
+static void openlog(const char *, int, int) { dx_closelog(); }
+static void syslog(int, const char *, ...) { dx_closelog(); }
+static void closelog(void) { dx_closelog(); }
+
+#define LOG_PID  1
+#define LOG_USER 2
+#define LOG_ERR  0
+]])
+
+AT_DATA([test.in],
+[[@ac_cv_header_syslog_h@
+@dx_cv_have_syslog@
+]])
+
+TEST_CONFIGURE_AC([[DX_CHECK_SYSLOG
+AC_SUBST([ac_cv_header_syslog_h])
+AC_SUBST([dx_cv_have_syslog])
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+TEST_CONFIGURE([CFLAGS=-I.])
+AT_CHECK([cat test], [0], [yes
+no
+])
+
+TEST_CONFIGURE([CFLAGS=-I. LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([cat test], [0], [yes
+yes
+])
+
+AT_CLEANUP