-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.
-dnl There is NO WARRANTY, to the extent permitted by law.
+# Copyright © 2019-2020, 2022-2024 Nick Bowler
+#
+# License GPLv3+: GNU General Public License version 3 or any later version.
+# This is free software: you are free to change and redistribute it.
+# There is NO WARRANTY, to the extent permitted by law.
AT_BANNER([Library tests])
-dnl TEST_DUMMY_PKGCONFIG([cflags], [libs])
-dnl
-dnl Create a hack pkg-config script in the current working directory which
-dnl responds to --cflags and --libs with the provided values. The macro
-dnl arguments should each be a single shell word, suitable for the right
-dnl hand side of a shell assignment.
+# TEST_DUMMY_PKGCONFIG([cflags], [libs])
+#
+# Create a hack pkg-config script in the current working directory which
+# responds to --cflags and --libs with the provided values. The macro
+# arguments should each be a single shell word, suitable for the right
+# hand side of a shell assignment.
m4_define([TEST_DUMMY_PKGCONFIG],
[[cat >pkg-config <<EOF
#!/bin/sh
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);
+extern void dx_link_stub(void);
-static void openlog(const char *, int, int) { dx_closelog(); }
-static void syslog(int, const char *, ...) { dx_closelog(); }
-static void closelog(void) { dx_closelog(); }
+static void openlog(const char *, int, int) { dx_link_stub(); }
+static void syslog(int, const char *, ...) { dx_link_stub(); }
+static void closelog(void) { dx_link_stub(); }
#define LOG_PID 1
#define LOG_USER 2
])
AT_CLEANUP
+
+AT_SETUP([DX_CHECK_GETLINE])
+
+AT_DATA([stdio.h],
+[[/* since getline is normally in the standard C library, to make negative link
+tests possible we use a dummy external name */
+extern void dx_link_stub(void);
+typedef unsigned long size_t;
+typedef long ssize_t;
+typedef int FILE;
+
+static FILE stdin[1];
+
+#if !NO_GETLINE_DECL
+static size_t getline(char **line, size_t *n, FILE *f) { dx_link_stub(); }
+#endif
+]])
+
+AT_DATA([test.in],
+[[@dx_cv_have_getline@
+@DEFS@
+]])
+
+TEST_CONFIGURE_AC([[AC_PROG_CC
+CPPFLAGS="-I$srcdir $CPPFLAGS"
+DX_CHECK_GETLINE
+AC_SUBST([dx_cv_have_getline])
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+TEST_CONFIGURE
+AT_CHECK([sed '[s/-DPACKAGE\([^\\ ]*\\.\)*[^ ]* *//g]' test], [0], [no
+
+])
+
+TEST_CONFIGURE([LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([sed '[s/-DPACKAGE\([^\\ ]*\\.\)*[^ ]* *//g]' test], [0], [yes
+-DHAVE_GETLINE=1
+])
+
+TEST_CONFIGURE([CPPFLAGS="-DNO_GETLINE_DECL" LIBS="$builddir/t/libdummy.a"])
+AT_CHECK([sed '[s/-DPACKAGE\([^\\ ]*\\.\)*[^ ]* *//g]' test], [0], [no
+
+])
+
+AT_CLEANUP