]> git.draconx.ca Git - dxcommon.git/blob - tests/libs.at
c57f68076cb60aec3d1680daad7042026fd74df4
[dxcommon.git] / tests / libs.at
1 dnl Copyright © 2019-2020, 2022 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   --atleast-pkgconfig-version) exit;;
25   esac
26 done
27 printf '%s %s\n' "\$cflags" "\$libs"
28 EOF
29 chmod +x pkg-config
30 ]])
31
32 AT_SETUP([libdiscid probes])
33 AT_KEYWORDS([libdiscid])
34
35 mkdir discid
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
42 #endif
43 ]])
44
45 AT_DATA([test.in],
46 [[@HAVE_LIBDISCID@
47 @LIBDISCID_CFLAGS@
48 @LIBDISCID_LIBS@
49 ]])
50
51 TEST_CONFIGURE_AC([[DX_LIB_LIBDISCID([1.2.3], [HAVE_LIBDISCID=yes],
52                                               [HAVE_LIBDISCID=no])
53 AC_SUBST([HAVE_LIBDISCID])
54 AC_CONFIG_FILES([test])
55 ]])
56 TEST_AUTORECONF
57
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
61 -I.
62 $builddir/t/libdummy.a
63 ])
64
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
69 -I.
70 $builddir/t/libdummy.a
71 ])
72
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
77
78 -ldiscid
79 ])
80
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
84
85
86 ])
87
88 AT_CLEANUP
89
90 AT_SETUP([GLib GNU inline workaround])
91
92 TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
93
94 # This test will only work if we have a version of GCC that implements
95 # C99 inline semantics by default.
96 AT_DATA([a.c],
97 [[#if __GNUC__
98 extern inline void my_dup_fn(void) { }
99 #endif
100 int main(void) { return 0; }
101 ]])
102 AT_DATA([b.c],
103 [[#if __GNUC__
104 extern inline void my_dup_fn(void) { }
105 #endif
106 ]])
107
108 AT_DATA([test.sh.in],
109 [[#!/bin/sh
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
113 exit 77
114 ]])
115
116 AT_DATA([glib.h],
117 [[#define GLIB_CHECK_VERSION(x, y, z) 1
118 const char *g_get_prgname(void);
119 ]])
120
121 TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
122 DX_LIB_GLIB2
123 AC_CONFIG_FILES([test.sh], [chmod +x test.sh])
124 ]])
125 TEST_AUTORECONF
126 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
127 AT_CHECK([./test.sh], [0], [ignore], [ignore])
128
129 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
130 [/* #undef G_INLINE_FUNC */
131 ])
132 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
133 [/* #undef G_IMPLEMENT_INLINES */
134 ])
135
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
140 #endif
141 G_INLINE_FUNC void break_things(void) { }
142 EOF
143
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
147 ])
148 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
149 [/* #undef G_IMPLEMENT_INLINES */
150 ])
151
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);
156 #else
157 G_INLINE_FUNC void break_things(void) { }
158 #endif
159 EOF
160
161 TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
162 AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
163 [/* #undef G_INLINE_FUNC */
164 ])
165 AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
166 [#define G_IMPLEMENT_INLINES 1
167 ])
168
169 AT_CLEANUP