1 dnl Copyright © 2019 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[;;
26 printf '%s %s\n' "\$cflags" "\$libs"
31 AT_SETUP([libdiscid probes])
32 AT_KEYWORDS([libdiscid])
35 AT_DATA([discid/discid.h],
36 [[typedef void DiscId;
37 DiscId *discid_new(void);
38 void discid_free(DiscId *);
39 #ifndef DISCID_VERSION_MAJOR
40 # define DISCID_VERSION_MAJOR 2
50 TEST_CONFIGURE_AC([[DX_LIB_LIBDISCID([1.2.3], [HAVE_LIBDISCID=yes],
52 AC_SUBST([HAVE_LIBDISCID])
53 AC_CONFIG_FILES([test])
57 # Check the search via explicit flags
58 TEST_CONFIGURE([LIBDISCID_CFLAGS=-I. LIBDISCID_LIBS="$builddir/t/libdummy.a"])
59 AT_CHECK_UNQUOTED([cat test], [0], [yes
61 $builddir/t/libdummy.a
64 # Check the search via pkg-config
65 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
66 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
67 AT_CHECK_UNQUOTED([cat test], [0], [yes
69 $builddir/t/libdummy.a
72 # Check the default -ldiscid search
73 cp "$builddir/t/libdummy.a" libdiscid.a
74 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS=-I. LDFLAGS=-L.])
75 AT_CHECK_UNQUOTED([cat test], [0], [yes
80 # Check the failure case
81 TEST_CONFIGURE([PKG_CONFIG=false CFLAGS='-I. -DDISCID_VERSION_MAJOR=0'])
82 AT_CHECK_UNQUOTED([cat test], [0], [no
89 AT_SETUP([GLib GNU inline workaround])
91 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
93 # This test will only work if we have a version of GCC that implements
94 # C99 inline semantics by default.
97 extern inline void my_dup_fn(void) { }
99 int main(void) { return 0; }
103 extern inline void my_dup_fn(void) { }
107 AT_DATA([test.sh.in],
109 @CC@ @CPPFLAGS@ @CFLAGS@ -c a.c || exit 77
110 @CC@ @CPPFLAGS@ @CFLAGS@ -c b.c || exit 77
111 @CC@ @CFLAGS@ @LDFLAGS@ a.o b.o || exit 0
116 [[#define GLIB_CHECK_VERSION(x, y, z) 1
117 const char *g_get_prgname(void);
120 TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
122 AC_CONFIG_FILES([test.sh], [chmod +x test.sh])
125 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
126 AT_CHECK([./test.sh], [0], [ignore], [ignore])
128 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
129 [/* #undef G_INLINE_FUNC */
131 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
132 [/* #undef G_IMPLEMENT_INLINES */
135 cp glib.h glib-orig.h
136 cat glib-orig.h - >glib.h <<'EOF'
137 #ifndef G_INLINE_FUNC
138 # define G_INLINE_FUNC extern inline
140 G_INLINE_FUNC void break_things(void) { }
143 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
144 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
145 [#define G_INLINE_FUNC static inline
147 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
148 [/* #undef G_IMPLEMENT_INLINES */
151 cat glib-orig.h - >glib.h <<'EOF'
152 #define G_INLINE_FUNC extern inline
153 #ifdef G_IMPLEMENT_INLINES
154 extern void break_things(void);
156 G_INLINE_FUNC void break_things(void) { }
160 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
161 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
162 [/* #undef G_INLINE_FUNC */
164 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
165 [#define G_IMPLEMENT_INLINES 1