1 dnl Copyright © 2019-2020, 2022 Nick Bowler
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
7 AT_BANNER([Library tests])
9 dnl TEST_DUMMY_PKGCONFIG([cflags], [libs])
11 dnl Create a hack pkg-config script in the current working directory which
12 dnl responds to --cflags and --libs with the provided values. The macro
13 dnl arguments should each be a single shell word, suitable for the right
14 dnl hand side of a shell assignment.
15 m4_define([TEST_DUMMY_PKGCONFIG],
16 [[cat >pkg-config <<EOF
22 --cflags) cflags=]$1[;;
24 --atleast-pkgconfig-version) exit;;
27 printf '%s %s\n' "\$cflags" "\$libs"
32 AT_SETUP([libdiscid probes])
33 AT_KEYWORDS([lib libdiscid])
36 AT_DATA([discid/discid.h],
37 [[typedef void DiscId;
38 DiscId *discid_new(void);
39 void discid_free(DiscId *);
40 #ifndef DISCID_VERSION_MAJOR
41 # define DISCID_VERSION_MAJOR 2
51 TEST_CONFIGURE_AC([[DX_LIB_LIBDISCID([1.2.3], [HAVE_LIBDISCID=yes],
53 AC_SUBST([HAVE_LIBDISCID])
54 AC_CONFIG_FILES([test])
58 # Check the search via explicit flags
59 TEST_CONFIGURE([LIBDISCID_CFLAGS=-I. LIBDISCID_LIBS="$builddir/t/libdummy.a"])
60 AT_CHECK_UNQUOTED([cat test], [0], [yes
62 $builddir/t/libdummy.a
65 # Check the search via pkg-config
66 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
67 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
68 AT_CHECK_UNQUOTED([cat test], [0], [yes
70 $builddir/t/libdummy.a
73 # Check the default -ldiscid search
74 cp "$builddir/t/libdummy.a" libdiscid.a
75 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
76 AT_CHECK_UNQUOTED([cat test], [0], [yes
81 # Check the failure case
82 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS='-I. -DDISCID_VERSION_MAJOR=0'])
83 AT_CHECK_UNQUOTED([cat test], [0], [no
90 AT_SETUP([curses probes])
91 AT_KEYWORDS([lib curses ncurses])
94 [[void initscr(void) { }
105 TEST_CONFIGURE_AC([[DX_LIB_CURSES([HAVE_CURSES=yes], [HAVE_CURSES=no])
106 AC_SUBST([HAVE_CURSES])
107 AC_CONFIG_FILES([test])
111 # Check the search via explicit flags
112 TEST_CONFIGURE([CURSES_CFLAGS=-I. CURSES_LIBS="$builddir/t/libdummy.a"])
113 AT_CHECK_UNQUOTED([cat test], [0], [yes
115 $builddir/t/libdummy.a
118 # Check the search via pkg-config
119 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
120 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
121 AT_CHECK_UNQUOTED([cat test], [0], [yes
123 $builddir/t/libdummy.a
126 # Check the default -lcurses search
127 cp "$builddir/t/libdummy.a" libcurses.a
128 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
129 AT_CHECK_UNQUOTED([cat test], [0], [yes
134 # Check the failure case
135 cp "$builddir/t/libempty.a" libcurses.a
136 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
137 AT_CHECK_UNQUOTED([cat test], [0], [no
144 AT_SETUP([DX_CHECK_CURSES_GETMOUSE_NCURSES])
145 AT_KEYWORDS([lib curses ncurses])
147 mkdir ncurses sysv bogus
148 AT_DATA([ncurses/curses.h],
149 [[typedef struct MEVENT { int x; } MEVENT;
150 int getmouse_nc_(MEVENT *);
151 #define getmouse getmouse_nc_
154 AT_DATA([sysv/curses.h],
155 [[unsigned getmouse(void);
158 AT_DATA([bogus/curses.h],
159 [[typedef int MEVENT;
160 int getmouse_bogus_(void *);
161 #define getmouse getmouse_bogus_
165 [[@dx_cv_curses_have_getmouse_ncurses@
168 TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
169 DX_CHECK_CURSES_GETMOUSE_NCURSES
170 AC_SUBST([dx_cv_curses_have_getmouse_ncurses])
171 AC_CONFIG_FILES([test])
175 TEST_CONFIGURE([CURSES_CFLAGS=-Incurses CURSES_LIBS="$builddir/t/libdummy.a"])
176 AT_CHECK([cat test && grep HAVE_CURSES config.h], [0], [yes
177 #define HAVE_CURSES_GETMOUSE_NCURSES 1
180 TEST_CONFIGURE([CURSES_CFLAGS=-Isysv CURSES_LIBS="$builddir/t/libdummy.a"])
181 AT_CHECK([cat test && grep HAVE_CURSES config.h], [0], [no
182 /* #undef HAVE_CURSES_GETMOUSE_NCURSES */
185 TEST_CONFIGURE([CURSES_CFLAGS=-Ibogus CURSES_LIBS="$builddir/t/libdummy.a"])
186 AT_CHECK([cat test && grep HAVE_CURSES config.h], [0], [no
187 /* #undef HAVE_CURSES_GETMOUSE_NCURSES */
192 AT_SETUP([DX_CHECK_CURSES_MOUSE_SUPPORT])
193 AT_KEYWORDS([lib curses ncurses])
195 mkdir hp ncurses sysv
197 # HP-UX 11 curses contains definitions of mouse functions in the library but
198 # is missing declarations and associated macros in <curses.h>, although they
199 # are present in the alternate "cur_colr" implementation.
201 # Regardless, neither implementation seems to have working mouse support with
202 # any X terminal emulator so for now no workarounds are provided and the checks
203 # are expected to return "no".
204 AT_DATA([hp/curses.h],
205 [[int mouse_set(unsigned long);
206 int request_mouse_pos(void);
209 # Ncurses-like mouse functions.
210 AT_DATA([ncurses/curses.h],
211 [[unsigned long mousemask(unsigned long, unsigned long *);
213 int getmouse_nc_(MEVENT *);
214 #define getmouse getmouse_nc_
215 #define BUTTON1_RELEASED 1L
216 #define BUTTON1_PRESSED 2L
218 /* rename this to avoid false positives in the test */
219 #define mouse_set mouse_set_bogus_
222 # SysV-like mouse funcitons.
223 AT_DATA([sysv/curses.h],
224 [[int mouse_set(unsigned long);
225 int request_mouse_pos(void);
227 #define BUTTON_STATUS(x) 0
228 #define BUTTON_RELEASED 0
229 #define BUTTON_PRESSED 1
231 #define BUTTON1_RELEASED 1L
232 #define BUTTON1_PRESSED 2L
236 [[@dx_cv_curses_have_mouse_set@
237 @dx_cv_curses_have_mousemask@
238 @dx_cv_curses_have_getmouse_ncurses@
239 @dx_cv_curses_have_request_mouse_pos@
242 TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
243 DX_CHECK_CURSES_MOUSE_SUPPORT
244 AC_SUBST([dx_cv_curses_have_mouse_set])
245 AC_SUBST([dx_cv_curses_have_mousemask])
246 AC_SUBST([dx_cv_curses_have_request_mouse_pos])
247 AC_SUBST([dx_cv_curses_have_getmouse_ncurses])
248 AC_CONFIG_FILES([test])
252 TEST_CONFIGURE([CURSES_CFLAGS=-Ihp CURSES_LIBS="$builddir/t/libdummy.a"])
253 AT_CHECK([cat test && grep CURSES_MOUSE_SUPPORT config.h], [0], [no
257 /* #undef HAVE_CURSES_MOUSE_SUPPORT */
260 TEST_CONFIGURE([CURSES_CFLAGS=-Incurses CURSES_LIBS="$builddir/t/libdummy.a"])
261 AT_CHECK([cat test && grep CURSES_MOUSE_SUPPORT config.h], [0], [no
265 #define HAVE_CURSES_MOUSE_SUPPORT 1
268 TEST_CONFIGURE([CURSES_CFLAGS=-Isysv CURSES_LIBS="$builddir/t/libdummy.a"])
269 AT_CHECK([cat test && grep CURSES_MOUSE_SUPPORT config.h], [0], [yes
273 #define HAVE_CURSES_MOUSE_SUPPORT 1
278 AT_SETUP([GLib GNU inline workaround])
280 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
282 # This test will only work if we have a version of GCC that implements
283 # C99 inline semantics by default.
286 extern inline void my_dup_fn(void) { }
288 int main(void) { return 0; }
292 extern inline void my_dup_fn(void) { }
296 AT_DATA([test.sh.in],
298 @CC@ @CPPFLAGS@ @CFLAGS@ -c a.c || exit 77
299 @CC@ @CPPFLAGS@ @CFLAGS@ -c b.c || exit 77
300 @CC@ @CFLAGS@ @LDFLAGS@ a.o b.o || exit 0
305 [[#define GLIB_CHECK_VERSION(x, y, z) 1
306 const char *g_get_prgname(void);
309 TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
311 AC_CONFIG_FILES([test.sh], [chmod +x test.sh])
314 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
315 AT_CHECK([./test.sh], [0], [ignore], [ignore])
317 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
318 [/* #undef G_INLINE_FUNC */
320 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
321 [/* #undef G_IMPLEMENT_INLINES */
324 cp glib.h glib-orig.h
325 cat glib-orig.h - >glib.h <<'EOF'
326 #ifndef G_INLINE_FUNC
327 # define G_INLINE_FUNC extern inline
329 G_INLINE_FUNC void break_things(void) { }
332 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
333 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
334 [#define G_INLINE_FUNC static inline
336 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
337 [/* #undef G_IMPLEMENT_INLINES */
340 cat glib-orig.h - >glib.h <<'EOF'
341 #define G_INLINE_FUNC extern inline
342 #ifdef G_IMPLEMENT_INLINES
343 extern void break_things(void);
345 G_INLINE_FUNC void break_things(void) { }
349 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
350 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
351 [/* #undef G_INLINE_FUNC */
353 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
354 [#define G_IMPLEMENT_INLINES 1