]> git.draconx.ca Git - dxcommon.git/blob - tests/libs.at
Improve GLib probe against old GLib versions.
[dxcommon.git] / tests / libs.at
1 dnl Copyright © 2019 Nick Bowler
2 dnl
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.
6
7 AT_BANNER([Library tests])
8
9 dnl TEST_DUMMY_PKGCONFIG([cflags], [libs])
10 dnl
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
17 #!/bin/sh
18 cflags= libs=
19 for arg
20 do
21   case \$arg in
22   --cflags) cflags=]$1[;;
23   --libs) libs=]$2[;;
24   esac
25 done
26 printf '%s %s\n' "\$cflags" "\$libs"
27 EOF
28 chmod +x pkg-config
29 ]])
30
31 AT_SETUP([libdiscid probes])
32 AT_KEYWORDS([libdiscid])
33
34 mkdir discid
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
41 #endif
42 ]])
43
44 AT_DATA([test.in],
45 [[@HAVE_LIBDISCID@
46 @LIBDISCID_CFLAGS@
47 @LIBDISCID_LIBS@
48 ]])
49
50 TEST_CONFIGURE_AC([[DX_LIB_LIBDISCID([1.2.3], [HAVE_LIBDISCID=yes],
51                                               [HAVE_LIBDISCID=no])
52 AC_SUBST([HAVE_LIBDISCID])
53 AC_CONFIG_FILES([test])
54 ]])
55 TEST_AUTORECONF
56
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
60 -I.
61 $builddir/t/libdummy.a
62 ])
63
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
68 -I.
69 $builddir/t/libdummy.a
70 ])
71
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
76
77 -ldiscid
78 ])
79
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
83
84
85 ])
86
87 AT_CLEANUP
88
89 AT_SETUP([GLib GNU inline workaround])
90
91 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
92
93 # This test will only work if we have a version of GCC that implements
94 # C99 inline semantics by default.
95 AT_DATA([a.c],
96 [[#if __GNUC__
97 extern inline void my_dup_fn(void) { }
98 #endif
99 int main(void) { return 0; }
100 ]])
101 AT_DATA([b.c],
102 [[#if __GNUC__
103 extern inline void my_dup_fn(void) { }
104 #endif
105 ]])
106
107 AT_DATA([test.sh.in],
108 [[#!/bin/sh
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
112 exit 77
113 ]])
114
115 AT_DATA([glib.h],
116 [[#define GLIB_CHECK_VERSION(x, y, z) 1
117 const char *g_get_prgname(void);
118 ]])
119
120 TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
121 DX_LIB_GLIB2
122 AC_CONFIG_FILES([test.sh], [chmod +x test.sh])
123 ]])
124 TEST_AUTORECONF
125 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
126 AT_CHECK([./test.sh], [0], [ignore], [ignore])
127
128 AT_CHECK([grep G_INLINE_FUNC config.h], [0],
129 [/* #undef G_INLINE_FUNC */
130 ])
131
132 cat >>glib.h <<'EOF'
133 #ifndef G_INLINE_FUNC
134 #  define G_INLINE_FUNC extern inline
135 #endif
136 G_INLINE_FUNC void break_things(void) { }
137 EOF
138
139 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
140 AT_CHECK([grep G_INLINE_FUNC config.h], [0],
141 [#define G_INLINE_FUNC static inline
142 ])
143
144 AT_CLEANUP