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. 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. m4_define([TEST_DUMMY_PKGCONFIG], [[cat >pkg-config <, although they # are present in the alternate "cur_colr" implementation. # # Regardless, neither implementation seems to have working mouse support with # any X terminal emulator so for now no workarounds are provided and the checks # are expected to return "no". AT_DATA([hp/curses.h], [[int mouse_set(unsigned long); int request_mouse_pos(void); ]]) # Ncurses-like mouse functions. AT_DATA([ncurses/curses.h], [[unsigned long mousemask(unsigned long, unsigned long *); typedef int MEVENT; int getmouse_nc_(MEVENT *); #define getmouse getmouse_nc_ #define BUTTON1_RELEASED 1L #define BUTTON1_PRESSED 2L /* rename this to avoid false positives in the test */ #define mouse_set mouse_set_bogus_ ]]) # SysV-like mouse funcitons. AT_DATA([sysv/curses.h], [[int mouse_set(unsigned long); int request_mouse_pos(void); #define BUTTON_STATUS(x) 0 #define BUTTON_RELEASED 0 #define BUTTON_PRESSED 1 #define BUTTON1_RELEASED 1L #define BUTTON1_PRESSED 2L ]]) AT_DATA([test.in], [[@dx_cv_curses_have_mouse_set@ @dx_cv_curses_have_mousemask@ @dx_cv_curses_have_getmouse_ncurses@ @dx_cv_curses_have_request_mouse_pos@ ]]) TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h]) DX_CHECK_CURSES_MOUSE_SUPPORT AC_SUBST([dx_cv_curses_have_mouse_set]) AC_SUBST([dx_cv_curses_have_mousemask]) AC_SUBST([dx_cv_curses_have_request_mouse_pos]) AC_SUBST([dx_cv_curses_have_getmouse_ncurses]) AC_CONFIG_FILES([test]) ]]) TEST_AUTORECONF TEST_CONFIGURE([CURSES_CFLAGS=-Ihp CURSES_LIBS="$builddir/t/libdummy.a"]) AT_CHECK([cat test && grep CURSES_MOUSE_SUPPORT config.h], [0], [no no /* #undef HAVE_CURSES_MOUSE_SUPPORT */ ]) TEST_CONFIGURE([CURSES_CFLAGS=-Incurses CURSES_LIBS="$builddir/t/libdummy.a"]) AT_CHECK([cat test && grep CURSES_MOUSE_SUPPORT config.h], [0], [no yes yes #define HAVE_CURSES_MOUSE_SUPPORT 1 ]) TEST_CONFIGURE([CURSES_CFLAGS=-Isysv CURSES_LIBS="$builddir/t/libdummy.a"]) AT_CHECK([cat test && grep CURSES_MOUSE_SUPPORT config.h], [0], [yes no yes #define HAVE_CURSES_MOUSE_SUPPORT 1 ]) AT_CLEANUP AT_SETUP([GLib GNU inline workaround]) TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a]) # This test will only work if we have a version of GCC that implements # C99 inline semantics by default. AT_DATA([a.c], [[#if __GNUC__ extern inline void my_dup_fn(void) { } #endif int main(void) { return 0; } ]]) AT_DATA([b.c], [[#if __GNUC__ extern inline void my_dup_fn(void) { } #endif ]]) AT_DATA([test.sh.in], [[#!/bin/sh @CC@ @CPPFLAGS@ @CFLAGS@ -c a.c || exit 77 @CC@ @CPPFLAGS@ @CFLAGS@ -c b.c || exit 77 @CC@ @CFLAGS@ @LDFLAGS@ a.o b.o || exit 0 exit 77 ]]) AT_DATA([glib.h], [[#define GLIB_CHECK_VERSION(x, y, z) 1 const char *g_get_prgname(void); ]]) TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h]) DX_LIB_GLIB2 AC_CONFIG_FILES([test.sh], [chmod +x test.sh]) ]]) TEST_AUTORECONF TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config]) AT_CHECK([./test.sh], [0], [ignore], [ignore]) AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0], [/* #undef G_INLINE_FUNC */ ]) AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0], [/* #undef G_IMPLEMENT_INLINES */ ]) cp glib.h glib-orig.h cat glib-orig.h - >glib.h <<'EOF' #ifndef G_INLINE_FUNC # define G_INLINE_FUNC extern inline #endif G_INLINE_FUNC void break_things(void) { } EOF TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config]) AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0], [#define G_INLINE_FUNC static inline ]) AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0], [/* #undef G_IMPLEMENT_INLINES */ ]) cat glib-orig.h - >glib.h <<'EOF' #define G_INLINE_FUNC extern inline #ifdef G_IMPLEMENT_INLINES extern void break_things(void); #else G_INLINE_FUNC void break_things(void) { } #endif EOF TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config]) AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0], [/* #undef G_INLINE_FUNC */ ]) AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0], [#define G_IMPLEMENT_INLINES 1 ]) 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