+dnl *@-mdw_INIT_LIB-@*
+dnl
+dnl Author: Mark Wooding
+dnl
+dnl Synopsis: mdw_INIT_LIB(LIB, NAME, VERSION, [PACKAGE])
+dnl
+dnl Arguments: LIB = the name of the library (and the package)
+dnl NAME = a presentable version of the library's name
+dnl VERSION = version of the library
+dnl PACKAGE = package name to pass on to AM_INIT_AUTOMAKE
+dnl
+dnl Use: Sets up various useful variables. This macro calls
+dnl AM_INIT_AUTOMAKE, which might be considered useful. It also
+dnl provides variables for the use of `lib-config.in'.
+
+AC_DEFUN([mdw_INIT_LIB],
+[AM_INIT_AUTOMAKE(ifelse([$4], [], [$1], [$4]), [$3])
+LIBRARY="$1" AC_SUBST(LIBRARY)
+LIBNAME="$2" AC_SUBST(LIBNAME)])
+
+dnl *@-mdw_LIB_CONFIG-@*
+dnl
+dnl Author: Mark Wooding
+dnl
+dnl Synopsis: mdw_LIB_CONFIG(LIB, NAME, VERSION, IF-FOUND, IF-NOT-FOUND)
+dnl
+dnl Arguments: LIB = the name of the library (and its configuration program)
+dnl NAME = a presentable version of the library's name
+dnl VERSION = version of library required
+dnl IF-FOUND = what to do if found
+dnl IF-NOT-FOUND = what to do if not found
+dnl
+dnl Use: Configures a library client program, using a configuration
+dnl script provided by the library maintainer.
+dnl
+dnl The default version is 1.0.0pre0; the default action is to
+dnl add everything to the CFLAGS and LIBS variables, and complain
+dnl if the library couldn't be found.
+dnl
+dnl The variable LIB_VERSION contains the version number of
+dnl the library; LIB_CFLAGS is the C compiler flags required
+dnl and LIB_LIBS is the linker flags.
+
+AC_DEFUN([mdw_LIB_CONFIG],
+[pushdef([upname], translit([$1], [a-z], [A-Z]))dnl
+AC_MSG_CHECKING([for $2 library])
+if $1-config --check $3 >/dev/null 2>&1; then
+ upname[]_VERSION=`$1-config --version`
+ upname[]_CFLAGS=`$1-config --cflags`
+ upname[]_LIBS=`$1-config --libs`
+ AC_SUBST(upname[]_VERSION)
+ AC_SUBST(upname[]_CFLAGS)
+ AC_SUBST(upname[]_LIBS)
+ ifelse([$4], [],
+ [CFLAGS="$CFLAGS $upname[]_CFLAGS"
+ LIBS="$upname[]_LIBS $LIBS"],
+ $4)
+ AC_MSG_RESULT([$upname[]_VERSION])
+else
+ ifelse([$5], [],
+ AC_MSG_ERROR([$2 library not found or too old.]),
+ $5)
+ AC_MSG_RESULT([not found])
+fi])
+
+dnl *@-mdw_MLIB-@*
+dnl
+dnl Author: Mark Wooding
+dnl
+dnl Synopsis: mdw_MLIB(VERSION, IF-FOUND, IF-NOT-FOUND
+dnl
+dnl Arguments: VERSION = version of library required
+dnl IF-FOUND = what to do if found
+dnl IF-NOT-FOUND = what to do if not found
+dnl
+dnl Use: Configures an mLib client program.
+
+AC_DEFUN([mdw_MLIB], [mdw_LIB_CONFIG(mLib, mLib, $@)])
+
+dnl *@-mdw_MGLIB-@*
+dnl
+dnl Author: Mark Wooding
+dnl
+dnl Synopsis: mdw_MGLIB(VERSION, IF-FOUND, IF-NOT-FOUND
+dnl
+dnl Arguments: VERSION = version of library required
+dnl IF-FOUND = what to do if found
+dnl IF-NOT-FOUND = what to do if not found
+dnl
+dnl Use: Configures an mgLib client program.
+
+AC_DEFUN([mdw_MGLIB],
+[mdw_REQUIRE([mdw_MLIB], [1.6.0])
+mdw_LIB_CONFIG(mgLib, mgLib, $@)])
+
+dnl *@-mdw_CATACOMB-@*
+dnl
+dnl Author: Mark Wooding
+dnl
+dnl Synopsis: mdw_CATACOMB([VERSION], [IF-FOUND], [IF-NOT-FOUND])
+dnl
+dnl Arguments: VERSION = version of Catacomb required
+dnl IF-FOUND = what to do if found
+dnl IF-NOT-FOUND = what to do if not found
+dnl
+dnl Use: Configures the program as a Catacomb client.
+
+AC_DEFUN([mdw_CATACOMB],
+[mdw_REQUIRE([mdw_MLIB], [1.6.0])
+mdw_LIB_CONFIG(catacomb, Catacomb, $@)])
+
+dnl *@-mdw_PK-@*
+dnl
+dnl Author: Mark Wooding
+dnl
+dnl Synopsis: mdw_PK([VERSION], [IF-FOUND], [IF-NOT-FOUND])
+dnl
+dnl Arguments: VERSION = version of PK required
+dnl IF-FOUND = what to do if found
+dnl IF-NOT-FOUND = what to do if not found
+dnl
+dnl Use: Configures the program as a PK client.
+
+AC_DEFUN([mdw_PK],
+[mdw_REQUIRE([mdw_MLIB], [1.6.0])
+mdw_LIB_CONFIG(pk, PK, $@)])
+