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([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([GLib GNU inline workaround])
92 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
94 # This test will only work if we have a version of GCC that implements
95 # C99 inline semantics by default.
98 extern inline void my_dup_fn(void) { }
100 int main(void) { return 0; }
104 extern inline void my_dup_fn(void) { }
108 AT_DATA([test.sh.in],
110 @CC@ @CPPFLAGS@ @CFLAGS@ -c a.c || exit 77
111 @CC@ @CPPFLAGS@ @CFLAGS@ -c b.c || exit 77
112 @CC@ @CFLAGS@ @LDFLAGS@ a.o b.o || exit 0
117 [[#define GLIB_CHECK_VERSION(x, y, z) 1
118 const char *g_get_prgname(void);
121 TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
123 AC_CONFIG_FILES([test.sh], [chmod +x test.sh])
126 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
127 AT_CHECK([./test.sh], [0], [ignore], [ignore])
129 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
130 [/* #undef G_INLINE_FUNC */
132 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
133 [/* #undef G_IMPLEMENT_INLINES */
136 cp glib.h glib-orig.h
137 cat glib-orig.h - >glib.h <<'EOF'
138 #ifndef G_INLINE_FUNC
139 # define G_INLINE_FUNC extern inline
141 G_INLINE_FUNC void break_things(void) { }
144 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
145 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
146 [#define G_INLINE_FUNC static inline
148 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
149 [/* #undef G_IMPLEMENT_INLINES */
152 cat glib-orig.h - >glib.h <<'EOF'
153 #define G_INLINE_FUNC extern inline
154 #ifdef G_IMPLEMENT_INLINES
155 extern void break_things(void);
157 G_INLINE_FUNC void break_things(void) { }
161 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
162 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
163 [/* #undef G_INLINE_FUNC */
165 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
166 [#define G_IMPLEMENT_INLINES 1