AC_SUBST(AM_CFLAGS)
dnl--------------------------------------------------------------------------
-dnl Host-specific configuration.
+dnl Define language support for assembler.
+dnl
+dnl This is stolen from https://gitlab.crest.iu.edu/jsfiroz/hpx/commit/
+dnl 84be4345db6eec3797a57b8e53483cb43f4733bf
+
+AC_LANG_DEFINE([CPPAS], [cppas], [CPPAS], [CCAS], [C],
+ [ac_ext=S ac_cpp='$CPP $CPPFLAGS'
+ ac_compile='$CCAS -c $CCASFLAGS $CPPFLAGS dnl
+ conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
+ ac_link='$CCAS -oconftest$ac_exeext $CCASFLAGS $CPPFLAGS $LDFLAGS dnl
+ conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'])
+
+AC_DEFUN([AC_LANG_PREPROC(CPPAS)], [AC_REQUIRE([AC_PROG_CPP])])
+AC_DEFUN([AC_LANG_COMPILER(CPPAS)], [AC_REQUIRE([AM_PROG_AS])])
+AC_DEFUN([AC_LANG_CONFTEST(CPPAS)],
+ [cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+$1
+_ACEOF])
-AC_MSG_CHECKING([CPU family and ABI])
+dnl--------------------------------------------------------------------------
+dnl Host-specific configuration.
dnl The table of CPU families and ABIs which we might support. Support is
dnl not uniform: each dispatched function might or might not have an
$1([i[[3-6]]86,*], [x86], [sysv])
$1([x86_64,cygwin], [amd64], [win])
$1([x86_64,*], [amd64], [sysv])
- $1([arm,*-gnueabi | arm,*-gnueabihf | dnl
- armv*,*-gnueabi | armv*,*-gnueabihf], [armel], [gnueabi])])
+ $1([arm,* | armv*,*], [armel], [std])
+ $1([aarch64,*], [arm64], [std])])
dnl A utility to clear the `seen' flags, used so as to process each CPU or
dnl ABI once.
*) CPUFAM=nil ABI=nil ;;
esac
-dnl Figure out the current CPU.
-catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
-case $CPUFAM in
- m4_define([catacomb_DEFINE_CPU],
- [m4_ifdef([catacomb_seen_cpu/$2], [],
- [$2)
- AC_DEFINE([CPUFAM_]m4_translit([$2], [a-z], [A-Z]), [1],
- [Define if host CPU family is \`$2\'.])
- ;;m4_define([catacomb_seen_cpu/$2], [t])])])
- catacomb_CPU_FAMILIES([catacomb_DEFINE_CPU])
+dnl Now check the assembler. We have target-specific requirements here, so
+dnl we couldn't do this any earlier.
+AC_CACHE_CHECK(
+ [whether the assembler is likely to work], [mdw_cv_gnuish_as],
+ [AC_LANG_PUSH([CPPAS])
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+ .text
+ .L\$_test = 23
+.macro mymac
+ .L\$_test = .L\$_test + 1
+.endm
+ .globl foo
+ .extern bar
+ mymac]])],
+ [mdw_cv_gnuish_as=yes], [mdw_cv_gnuish_as=no])
+ case $CPUFAM in
+ x86 | amd64)
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+ .text
+ .arch pentium4
+ .intel_syntax noprefix
+ .globl foo
+foo:
+ adcd var, 0
+ ret
+ .data
+var: .long 1
+ ]])],
+ [:], [mdw_cv_gnuish_as=no])
+ ;;
+ esac
+ AC_LANG_POP([CPPAS])])
+AM_CONDITIONAL([GNUISH_AS], [test $mdw_cv_gnuish_as = yes])
+if test $mdw_cv_gnuish_as = no; then CPUFAM=nil ABI=nil; fi
+
+dnl A hairy macro used to set the `CPUFAM_...' and `ABI_...' variables. We
+dnl basically need to do the same thing for the family and ABI, so it's worth
+dnl some effort to hide the ugliness.
+m4_define([catacomb_DEFINE_CPU_OR_ABI],
+[case $$1 in
+ m4_define([_def],
+ [m4_ifdef([catacomb_seen_$3/$$2], [],
+ [$$2)
+ AC_DEFINE([$4]m4_translit([$$2], [a-z], [A-Z]), [1], [$5])
+ ;;m4_define([catacomb_seen_$3/$$2], [t])])])
+ catacomb_CPU_FAMILIES([_def])
nil) ;;
- *) AC_MSG_ERROR([BUG: unexpected cpufam \`$CPUFAM']) ;;
-esac
-AC_SUBST([CPUFAM])
+ *) AC_MSG_ERROR([BUG: unexpected $1 \`$1']) ;;
+esac])
+
+dnl Now that's out the way, we can explain what we're doing.
+AC_MSG_CHECKING([CPU family and ABI])
-dnl Figure out the current ABI.
+dnl Figure out the target CPU family and ABI.
catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
-case $ABI in
- m4_define([catacomb_DEFINE_ABI],
- [m4_ifdef([catacomb_seen_abi/$3], [],
- [$3)
- AC_DEFINE([ABI_]m4_translit([$3], [a-z], [A-Z]), [1],
- [Define if host ABI variant is \`$3\'.])
- ;;m4_define([catacomb_seen_abi/$3], [t])])])
- catacomb_CPU_FAMILIES([catacomb_DEFINE_ABI])
- nil) ;;
- *) AC_MSG_ERROR([BUG: unexpected ABI \`$ABI']) ;;
-esac
-AC_SUBST([ABI])
+catacomb_DEFINE_CPU_OR_ABI([CPUFAM], [2], [cpu],
+ [CPUFAM_], [Define if target CPU is \`$][2\'.])
+catacomb_DEFINE_CPU_OR_ABI([ABI], [3], [abi],
+ [ABI_], [Define if target ABI is \`$][3\'.])
dnl Establish Automake conditions for things.
catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
*) AC_MSG_RESULT([$CPUFAM/$ABI]) ;;
esac
-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--------------------------------------------------------------------------
+dnl CPU-specific assembler features.
+
+AC_LANG([CPPAS])
+
+case $CPUFAM in
+ armel)
+ AC_CACHE_CHECK(
+ [whether the assembler understands ARMv8 crypto extensions],
+ [mdw_cv_as_armv8_crypto],
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+ .arch armv8-a
+ .fpu crypto-neon-fp-armv8
+
+ .text
+ .globl foo
+foo:
+ vldmia r0, {d0-d3}
+ aese.8 q0, q1
+ aesmc.8 q0, q0
+ vstmia r0, {d0, d1}
+ bx r14]])],
+ [mdw_cv_as_armv8_crypto=yes],
+ [mdw_cv_as_armv8_crypto=no])])
+ ;;
+esac
+
+: ${mdw_cv_as_armv8_crypto=no}
+AM_CONDITIONAL([HAVE_AS_ARMV8_CRYPTO], [test $mdw_cv_as_armv8_crypto = yes])
+if test $mdw_cv_as_armv8_crypto = yes; then
+ AC_DEFINE([HAVE_AS_ARMV8_CRYPTO], [1],
+ [Define to 1 if your ARM assembler supports the ARMv8 crypto instructions.])
+fi
dnl--------------------------------------------------------------------------
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], [int])
+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], [int])
-AC_CHECK_TYPE([socklen_t], [int])
+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=
+mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
AC_SEARCH_LIBS([log], [m])
AC_SEARCH_LIBS([sqrt], [m])
-AC_SUBST([MATHLIBS], [$LIBS])
-LIBS=$mdw_ORIG_LIBS
+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])
-AC_C_LONG_LONG
+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 Find the bit lengths of the obvious integer types. This will be useful
dnl when deciding on a representation for multiprecision integers.
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])
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])