--- /dev/null
+dnl Copyright © 2009, 2019 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.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+dnl DX_LIB_GLIB2([min-version], [modules], [action-if-ok], [action-if-fail])
+dnl
+dnl Search for GLib-2 libraries, with the given minimum version. The modules
+dnl argument specifies which additional GLib libraries are required, which is
+dnl a space-separated list of zero or more of the following values:
+dnl
+dnl gthread
+dnl gobject
+dnl gio
+dnl gio-unix
+dnl gmodule
+dnl
+dnl Each detected module's flags are set in LIBxxx_CFLAGS and LIBxxx_LIBS,
+dnl where xxx is the module's name in all capital letters and with hyphens
+dnl converted to underscores (cf. AS_TR_SH). The core GLib flags are set
+dnl in LIBGLIB_CFLAGS and LIBGLIB_LIBS. The combination of all selected
+dnl and detected modules is set in GLIB_CFLAGS and GLIB_LIBS. All of
+dnl these variables are substituted as normal.
+dnl
+dnl If GLib and all selected modules are successfully found, action-if-ok
+dnl is run. Otherwise, action-if-fail is run. If necessary, use the
+dnl dx_cv_libxxx_lib_found cache variables to determine exactly which
+dnl modules are not available.
+AC_DEFUN([DX_LIB_GLIB2],
+[GLIB_CFLAGS= GLIB_LIBS= _dx_lib_glib_search_ok=true
+m4_define([_DX_LIB_GLIB2_TESTHEAD], [#include <glib.h>])dnl
+_DX_LIB_GLIB2_VERSION_TEST(m4_split([$1], [\.]))dnl
+m4_define([_DX_LIB_GLIB2_TESTMAIN],
+ [const char *v = glib_check_version(2,0,0);])dnl
+m4_define([_DX_GLIB_MODULES], [glib])dnl
+m4_append_uniq_w([_DX_GLIB_MODULES], [$2])dnl
+
+m4_map_args_w(m4_defn([_DX_GLIB_MODULES]), [_DX_LIB_GLIB2_MODULE(], [)])
+AC_SUBST([GLIB_CFLAGS])dnl
+AC_SUBST([GLIB_LIBS])dnl
+AS_IF([$_dx_lib_glib_search_ok], [$3], [m4_default([$4], [AC_MSG_FAILURE(
+[GLib[]m4_ifnblank([$1], [ version $1 or newer]) is required. The latest
+version may be found at <https://www.gtk.org/>.
+m4_newline([DX_LIB_USERFLAG_BLURB([libglib], [GLib])])
+m4_newline([DX_LIB_PKGCONFIG_BLURB([glib], [GLib])])
+])])])])
+
+AC_DEFUN([_DX_LIB_GLIB2_MODULE],
+[DX_LIB_SETUP([lib$1],
+[m4_if([$1], [glib], [GLib],
+ [$1], [gio], [GIO],
+ [$1], [gio-unix], [GIO-Unix],
+ [$1], [gthread], [GThread],
+ [$1], [gobject], [GObject],
+ [$1], [gmodule], [GModule])])dnl
+DX_LIB_PKGCONFIG_FLAGS([lib$1],
+ [m4_if([$1], [gmodule], [gmodule-no-export-2.0], [$1-2.0])])
+AC_MSG_CHECKING([for lib$1])
+DX_LIB_SEARCH_LINK([lib$1],
+ [AC_LANG_PROGRAM([_DX_LIB_GLIB2_TESTHEAD
+m4_n(m4_if([$1], [gobject], [[#include <glib-object.h>]]))dnl
+m4_n(m4_if([$1], [gio], [[#include <gio/gio.h>]]))dnl
+m4_n(m4_if([$1], [gio-unix], [[#include <gio/gunixmounts.h>]]))dnl
+m4_n(m4_if([$1], [gmodule], [[#include <gmodule.h>]]))],
+ [_DX_LIB_GLIB2_TESTMAIN
+m4_if([$1], [glib], [],
+ [$1], [gobject], [g_type_init();
+{ GObject *obj = g_object_new(G_TYPE_OBJECT, NULL); }],
+ [$1], [gthread], [g_thread_init(NULL);
+{ GThread *thr = g_thread_self(); }],
+ [$1], [gio], [{ GFile *f = g_file_new_for_path("/"); }],
+ [$1], [gio-unix], [{ GUnixMountEntry *m = g_unix_mount_at("/", NULL); }],
+ [$1], [gmodule], [{ GModule *m = g_module_open(NULL, 0); }],
+ [DX_LIB_COMPILE_ERROR([unsupported module])])])],
+ [ [[$LIBGLIB_CFLAGS m4_if([$1], [glib], [], [m4_toupper([$lib$1_cflags])])],
+ [$LIBGLIB_LIBS m4_if([$1], [glib], [], [m4_toupper([$lib$1_libs])])]],
+ [[$AS_TR_SH([dx_cv_lib$1_pkg_cflags])],
+ [$AS_TR_SH([dx_cv_lib$1_pkg_libs])],
+ [test x"$AS_TR_SH([dx_cv_lib$1_pkg_found])" = x"yes"]],
+ m4_if([$1], [gthread], [[[$LIBGLIB_CFLAGS -pthread],
+ [-pthread -lgthread-2.0 -lglib-2.0]],])
+ [[$LIBGLIB_CFLAGS], [m4_if([$1], [glib], [], [-l$1-2.0]) -lglib-2.0]],
+ ])
+AS_IF([test x"$AS_TR_SH([dx_cv_lib$1_lib_found])" = x"yes"],
+[set -f
+set x $AS_TR_SH([m4_toupper([lib$1_cflags])]); shift
+for _dx_i
+do
+ for _dx_j in $GLIB_CFLAGS; do
+ if test x"$_dx_i" = x"$_dx_j"; then
+ shift; continue 2
+ fi
+ done
+ set x ${1+"$[]@"} "$[]1"; shift; shift
+done
+GLIB_CFLAGS=${GLIB_CFLAGS:+"$GLIB_CFLAGS "}$[]*
+set x $AS_TR_SH([m4_toupper([lib$1_libs])]); shift
+for _dx_i
+do
+ for _dx_j in $GLIB_LIBS; do
+ if test x"$_dx_i" = x"$_dx_j"; then
+ shift; continue 2
+ fi
+ done
+ set x ${1+"$[]@"} "$[]1"; shift; shift
+done
+GLIB_LIBS=$[]*${GLIB_LIBS:+" $GLIB_LIBS"}
+set +f],
+ [_dx_lib_glib_search_ok=false])
+])
+
+AC_DEFUN([_DX_LIB_GLIB2_VERSION_TEST], [m4_append([_DX_LIB_GLIB2_TESTHEAD], [
+[#if !GLIB_CHECK_VERSION(]m4_default([$1],
+[0]), m4_default([$2],
+[0]), m4_default([$3],
+[0]))
+DX_LIB_COMPILE_ERROR([glib version insufficient])
+#endif])])