+dnl C programming environment.
+
+AC_LANG([C])
+
+CATACOMB_LIBS=
+
+dnl Find out if we're cross-compiling.
+AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
+
+dnl Various standard types.
+AC_CHECK_TYPE([pid_t], [],
+ [AC_DEFINE([pid_t], [int],
+ [Define to `int' if <sys/types.h> does not define])])
+AC_TYPE_UID_T
+AC_CHECK_TYPE([ssize_t], [],
+ [AC_DEFINE([ssize_t], [int],
+ [Define to `int' if <sys/types.h> does not define])])
+AC_CHECK_TYPE([socklen_t], [],
+ [AC_DEFINE([socklen_t], [int],
+ [Define to `int' if <sys/socket.h> does not define])],
+ [AC_INCLUDES_DEFAULT
+#include <sys/socket.h>
+])
+
+dnl The maths library.
+mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
+AC_SEARCH_LIBS([log], [m])
+AC_SEARCH_LIBS([sqrt], [m])
+CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
+
+dnl Logging is weird under Termux. Unfortunately, it involves macros, so we
+dnl have to do this the hard way.
+AC_CACHE_CHECK(
+ [library needed for syslog], [mdw_cv_syslog_lib],
+ [mdw_ORIG_LIBS=$LIBS LIBS=
+ for i in 0 1; do
+ AC_TRY_LINK([#include <syslog.h>],
+ [openlog("test", LOG_PID, LOG_DAEMON);
+ syslog(LOG_ERR, "this is a test");],
+ [ok=t], [ok=nil])
+ case $i,$ok in
+ *,t) mdw_cv_syslog_lib=${LIBS:-none}; break ;;
+ 0,nil) LIBS="-llog" ;;
+ 1,nil) AC_MSG_ERROR("failed to link test program") ;;
+ esac
+ done
+ LIBS=$mdw_ORIG_LIBS])
+case $mdw_cv_syslog_lib in
+ none) LOGLIBS= ;;
+ *) LOGLIBS=$mdw_cv_syslog_lib ;;
+esac
+AC_SUBST([LOGLIBS])
+
+dnl Find out whether very long integer types are available.
+AC_CHECK_HEADERS([stdint.h])
+AC_SUBST([have_stdint_h])
+AX_C_LONG_LONG
+
+dnl Some equipment wanted for checking CPU features at runtime.
+AC_CHECK_HEADERS([asm/hwcap.h])
+AC_CHECK_HEADERS([sys/auxv.h])
+AC_CHECK_HEADERS([linux/auxvec.h])
+AC_CHECK_FUNCS([getauxval])
+
+dnl Some equipment for measuring CPU performance.
+AC_CHECK_HEADERS([linux/perf_event.h])
+
+dnl Find the bit lengths of the obvious integer types. This will be useful
+dnl when deciding on a representation for multiprecision integers.
+type_bits="" type_bits_sep=""
+AC_DEFUN([catacomb_UINT_BITS],
+ [mdw_UINT_BITS([$2], [$1])
+ type_bits="$type_bits$type_bits_sep('$1', $[]$1_bits)"
+ type_bits_sep=", "])
+catacomb_UINT_BITS([uchar], [unsigned char])
+catacomb_UINT_BITS([ushort], [unsigned short])
+catacomb_UINT_BITS([uint], [unsigned int])
+catacomb_UINT_BITS([ulong], [unsigned long])
+if test "$ac_cv_c_long_long" = "yes"; then
+ catacomb_UINT_BITS([ullong], [unsigned long long])
+fi
+if test "$ac_cv_header_stdint_h" = "yes"; then
+ catacomb_UINT_BITS([uintmax], [uintmax_t])
+fi
+AC_SUBST([type_bits])
+
+dnl Determine the limits of common C integer types.
+limits="" limits_sep=""
+AC_DEFUN([catacomb_COMPILE_TIME_CONSTANT],
+ [case "$2" in
+ =*)
+ $1="$2"; $1=${$1#=}
+ ;;
+ *)
+ AC_CACHE_CHECK([compile-time value of $2], [mdw_cv_constant_$3],
+ [mdw_PROBE_CONSTANT([mdw_cv_constant_$3], [$2], [$4])])
+ $1=$mdw_cv_constant_$3
+ ;;
+ esac])
+AC_DEFUN([catacomb_LIMIT],
+[catacomb_COMPILE_TIME_CONSTANT([lo], [$2], [$1_min],
+[#include <limits.h>
+#include <stddef.h>])
+ catacomb_COMPILE_TIME_CONSTANT([hi], [$3], [$1_max],
+[#include <limits.h>
+#include <stddef.h>])
+ limits="$limits$limits_sep('$1', $lo, $hi)" limits_sep=", "])
+catacomb_LIMIT([SCHAR], [SCHAR_MIN], [SCHAR_MAX])
+catacomb_LIMIT([CHAR], [CHAR_MIN], [CHAR_MAX])
+catacomb_LIMIT([UCHAR], [=0], [UCHAR_MAX])
+catacomb_LIMIT([UINT8], [=0], [=0xff])
+catacomb_LIMIT([SHRT], [SHRT_MIN], [SHRT_MAX])
+catacomb_LIMIT([USHRT], [=0], [USHRT_MAX])
+catacomb_LIMIT([UINT16], [=0], [=0xffff])
+catacomb_LIMIT([INT], [INT_MIN], [INT_MAX])
+catacomb_LIMIT([UINT], [=0], [UINT_MAX])
+catacomb_LIMIT([LONG], [LONG_MIN], [LONG_MAX])
+catacomb_LIMIT([ULONG], [=0], [ULONG_MAX])
+catacomb_LIMIT([UINT32], [=0], [=0xffffffff])
+if test "$ac_cv_c_long_long" = "yes"; then
+ catacomb_LIMIT([LLONG], [LLONG_MIN], [LLONG_MAX])
+ catacomb_LIMIT([ULLONG], [=0], [ULLONG_MAX])
+fi
+catacomb_LIMIT([SIZET], [=0], [~(size_t)0])
+AC_SUBST([limits])
+
+dnl Figure out other aspects of the implementation's arithmetic.
+AC_CACHE_CHECK([whether negative numbers use two's complement],
+ [catacomb_cv_neg_twoc],
+[AC_TRY_COMPILE(
+[#include <limits.h>],
+[int check[2*!!(-INT_MAX == INT_MIN + 1) - 1];],
+[catacomb_cv_neg_twoc=yes],
+[catacomb_cv_neg_twoc=no])])
+case $catacomb_cv_neg_twoc in
+ yes)
+ AC_DEFINE([NEG_TWOC], [1],
+ [Define if signed numbers are represented in two's complement.])
+ ;;
+esac
+
+dnl Functions used for noise-gathering.
+AC_CHECK_FUNCS([setgroups])
+AC_CHECK_HEADERS([linux/random.h])
+mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
+AC_SEARCH_LIBS([clock_gettime], [rt])
+CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
+if test "$ac_cv_search_clock_gettime" != no; then
+ AC_DEFINE([HAVE_CLOCK_GETTIME], [1],
+ [Define if you have the \`clock_gettime' function.])
+fi
+AC_CHECK_FUNCS([getentropy])
+AC_CACHE_CHECK([whether the freewheel noise generator will work],
+ [catacomb_cv_freewheel],
+[AC_TRY_LINK(
+[#include <setjmp.h>
+#include <sys/time.h>],
+[struct itimerval itv = { { 0, 0 }, { 0, 5000 } };
+jmp_buf j;
+setitimer(ITIMER_REAL, &itv, 0);
+sigsetjmp(j, 1);],
+[catacomb_cv_freewheel=yes],
+[catacomb_cv_freewheel=no])])
+case $catacomb_cv_freewheel in
+ yes)
+ AC_DEFINE([USE_FREEWHEEL], [1],
+ [Define if you want to use the freewheel noise generator.])
+ ;;
+esac
+
+dnl Support for the passphrase pixie.
+mdw_ORIG_LIBS=$LIBS
+AC_SEARCH_LIBS([socket], [socket])
+AC_SUBST([PIXIE_LIBS], [$LIBS])
+LIBS=$mdw_ORIG_LIBS
+
+dnl Memory locking support.
+AC_CHECK_FUNCS([mlock])
+
+dnl See if we can find Valgrind's header files.
+AC_CHECK_HEADER([valgrind/memcheck.h],
+ AC_DEFINE([HAVE_VALGRIND_H], [1],
+ [Define if the Valgrind header files are available.])
+ [])
+
+dnl Set the master libraries we need.
+AC_SUBST([CATACOMB_LIBS])
+
+dnl Necessary support libraries.
+PKG_CHECK_MODULES([mLib], [mLib >= 2.4.1])
+AM_CFLAGS="$AM_CFLAGS $mLib_CFLAGS"
+
+dnl--------------------------------------------------------------------------
+dnl Python.
+
+dnl Make sure we have a suitable version.
+AM_PATH_PYTHON([2.5])
+
+dnl--------------------------------------------------------------------------
+dnl Special debugging options.
+
+AC_ARG_ENABLE([mpw],
+ [AS_HELP_STRING([--enable-mpw], [force small-width mp digits])],
+ [case "$enableval" in
+ y*|t*|short)
+ AC_DEFINE([FORCE_MPW_SHORT], [1],
+ [Define to force small-width mp digits.])
+ ;;
+ cussid)
+ AC_DEFINE([FORCE_MPW_CUSSID], [1],
+ [Define to force strange-width mp digits.])
+ ;;
+ esac])
+
+dnl--------------------------------------------------------------------------
+dnl Produce output.
+
+AC_CONFIG_HEADER([config/config.h])