-dnl Copyright © 2019 Nick Bowler
+dnl Copyright © 2019-2020, 2022 Nick Bowler
dnl
dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
dnl This is free software: you are free to do what the fuck you want to.
case \$arg in
--cflags) cflags=]$1[;;
--libs) libs=]$2[;;
+ --atleast-pkgconfig-version) exit;;
esac
done
printf '%s %s\n' "\$cflags" "\$libs"
])
AT_CLEANUP
+
+AT_SETUP([GLib GNU inline workaround])
+
+TEST_DUMMY_PKGCONFIG([-I.], [$builddir/t/libdummy.a])
+
+# This test will only work if we have a version of GCC that implements
+# C99 inline semantics by default.
+AT_DATA([a.c],
+[[#if __GNUC__
+extern inline void my_dup_fn(void) { }
+#endif
+int main(void) { return 0; }
+]])
+AT_DATA([b.c],
+[[#if __GNUC__
+extern inline void my_dup_fn(void) { }
+#endif
+]])
+
+AT_DATA([test.sh.in],
+[[#!/bin/sh
+@CC@ @CPPFLAGS@ @CFLAGS@ -c a.c || exit 77
+@CC@ @CPPFLAGS@ @CFLAGS@ -c b.c || exit 77
+@CC@ @CFLAGS@ @LDFLAGS@ a.o b.o || exit 0
+exit 77
+]])
+
+AT_DATA([glib.h],
+[[#define GLIB_CHECK_VERSION(x, y, z) 1
+const char *g_get_prgname(void);
+]])
+
+TEST_CONFIGURE_AC([[AC_CONFIG_HEADERS([config.h])
+DX_LIB_GLIB2
+AC_CONFIG_FILES([test.sh], [chmod +x test.sh])
+]])
+TEST_AUTORECONF
+TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
+AT_CHECK([./test.sh], [0], [ignore], [ignore])
+
+AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
+[/* #undef G_INLINE_FUNC */
+])
+AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
+[/* #undef G_IMPLEMENT_INLINES */
+])
+
+cp glib.h glib-orig.h
+cat glib-orig.h - >glib.h <<'EOF'
+#ifndef G_INLINE_FUNC
+# define G_INLINE_FUNC extern inline
+#endif
+G_INLINE_FUNC void break_things(void) { }
+EOF
+
+TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
+AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
+[#define G_INLINE_FUNC static inline
+])
+AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
+[/* #undef G_IMPLEMENT_INLINES */
+])
+
+cat glib-orig.h - >glib.h <<'EOF'
+#define G_INLINE_FUNC extern inline
+#ifdef G_IMPLEMENT_INLINES
+extern void break_things(void);
+#else
+G_INLINE_FUNC void break_things(void) { }
+#endif
+EOF
+
+TEST_CONFIGURE([PKG_CONFIG=$PWD/pkg-config])
+AT_CHECK([grep '#.*G_INLINE_FUNC' config.h], [0],
+[/* #undef G_INLINE_FUNC */
+])
+AT_CHECK([grep '#.*G_IMPLEMENT_INLINES' config.h], [0],
+[#define G_IMPLEMENT_INLINES 1
+])
+
+AT_CLEANUP