3 dnl Configuration script for Catacomb
5 dnl (c) 2013 Straylight/Edgeware
8 dnl----- Licensing notice ---------------------------------------------------
10 dnl This file is part of Catacomb.
12 dnl Catacomb is free software; you can redistribute it and/or modify
13 dnl it under the terms of the GNU Library General Public License as
14 dnl published by the Free Software Foundation; either version 2 of the
15 dnl License, or (at your option) any later version.
17 dnl Catacomb is distributed in the hope that it will be useful,
18 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
19 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 dnl GNU Library General Public License for more details.
22 dnl You should have received a copy of the GNU Library General Public
23 dnl License along with Catacomb; if not, write to the Free
24 dnl Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 dnl MA 02111-1307, USA.
27 dnl--------------------------------------------------------------------------
31 AC_INIT([catacomb], AUTO_VERSION, [mdw@distorted.org.uk])
32 AC_CONFIG_SRCDIR([catacomb.pc.in])
33 AC_CONFIG_AUX_DIR([config])
34 AM_INIT_AUTOMAKE([foreign parallel-tests color-tests subdir-objects])
41 mdw_LIBTOOL_VERSION_INFO
49 dnl--------------------------------------------------------------------------
50 dnl Define language support for assembler.
52 dnl This is stolen from https://gitlab.crest.iu.edu/jsfiroz/hpx/commit/
53 dnl 84be4345db6eec3797a57b8e53483cb43f4733bf
55 AC_LANG_DEFINE([CPPAS], [cppas], [CPPAS], [CCAS], [C],
56 [ac_ext=S ac_cpp='$CPP $CPPFLAGS'
57 ac_compile='$CCAS -c $CCASFLAGS $CPPFLAGS dnl
58 conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
59 ac_link='$CCAS -oconftest$ac_exeext $CCASFLAGS $CPPFLAGS $LDFLAGS dnl
60 conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'])
62 AC_DEFUN([AC_LANG_PREPROC(CPPAS)], [AC_REQUIRE([AC_PROG_CPP])])
63 AC_DEFUN([AC_LANG_COMPILER(CPPAS)], [AC_REQUIRE([AM_PROG_AS])])
64 AC_DEFUN([AC_LANG_CONFTEST(CPPAS)],
65 [cat confdefs.h - <<_ACEOF >conftest.$ac_ext
70 dnl--------------------------------------------------------------------------
71 dnl Host-specific configuration.
73 dnl The table of CPU families and ABIs which we might support. Support is
74 dnl not uniform: each dispatched function might or might not have an
75 dnl implementation for any particular CPU/ABI combination.
76 AC_DEFUN([catacomb_CPU_FAMILIES],
77 [$1([i[[3-6]]86,cygwin], [x86], [win])
78 $1([i[[3-6]]86,*], [x86], [sysv])
79 $1([x86_64,cygwin], [amd64], [win])
80 $1([x86_64,*], [amd64], [sysv])
81 $1([arm,* | armv*,*], [armel], [std])
82 $1([aarch64,*], [arm64], [std])])
84 dnl A utility to clear the `seen' flags, used so as to process each CPU or
86 m4_define([catacomb_CLEAR_FLAGS],
87 [m4_ifdef([catacomb_seen_cpu/$2],
88 [m4_undefine([catacomb_seen_cpu/$2])])dnl
89 m4_ifdef([catacomb_seen_abi/$3],
90 [m4_undefine([catacomb_seen_abi/$3])])])
92 dnl Identify the current host.
93 case $host_cpu,$host_os in
94 m4_define([catacomb_CPU_CASE],
95 [$1) CPUFAM=$2 ABI=$3 ;;
97 catacomb_CPU_FAMILIES([catacomb_CPU_CASE])
98 *) CPUFAM=nil ABI=nil ;;
101 dnl Now check the assembler. We have target-specific requirements here, so
102 dnl we couldn't do this any earlier.
104 [whether the assembler is likely to work], [mdw_cv_gnuish_as],
105 [AC_LANG_PUSH([CPPAS])
106 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
110 .L\$_test = .L\$_test + 1
115 [mdw_cv_gnuish_as=yes], [mdw_cv_gnuish_as=no])
118 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
121 .intel_syntax noprefix
129 [:], [mdw_cv_gnuish_as=no])
132 AC_LANG_POP([CPPAS])])
133 AM_CONDITIONAL([GNUISH_AS], [test $mdw_cv_gnuish_as = yes])
134 if test $mdw_cv_gnuish_as = no; then CPUFAM=nil ABI=nil; fi
136 dnl A hairy macro used to set the `CPUFAM_...' and `ABI_...' variables. We
137 dnl basically need to do the same thing for the family and ABI, so it's worth
138 dnl some effort to hide the ugliness.
139 m4_define([catacomb_DEFINE_CPU_OR_ABI],
142 [m4_ifdef([catacomb_seen_$3/$$2], [],
144 AC_DEFINE([$4]m4_translit([$$2], [a-z], [A-Z]), [1], [$5])
145 ;;m4_define([catacomb_seen_$3/$$2], [t])])])
146 catacomb_CPU_FAMILIES([_def])
148 *) AC_MSG_ERROR([BUG: unexpected $1 \`$$1']) ;;
151 dnl Now that's out the way, we can explain what we're doing.
152 AC_MSG_CHECKING([CPU family and ABI])
154 dnl Figure out the target CPU family and ABI.
155 catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
156 catacomb_DEFINE_CPU_OR_ABI([CPUFAM], [2], [cpu],
157 [CPUFAM_], [Define if target CPU is \`$][2\'.])
158 catacomb_DEFINE_CPU_OR_ABI([ABI], [3], [abi],
159 [ABI_], [Define if target ABI is \`$][3\'.])
161 dnl Establish Automake conditions for things.
162 catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
163 m4_define([catacomb_COND_CPU],
164 [m4_define([_CPU], m4_translit([$2], [a-z], [A-Z]))
165 m4_define([_ABI], m4_translit([$3], [a-z], [A-Z]))
166 AM_CONDITIONAL([CPUABI_]_CPU[_]_ABI, [test x$CPUFAM/$ABI = x$2/$3])
167 m4_ifdef([catacomb_seen_cpu/$2], [],
168 [AM_CONDITIONAL([CPUFAM_]_CPU, [test x$CPUFAM = x$2])dnl
169 m4_define([catacomb_seen_cpu/$2], [t])])
170 m4_ifdef([catacomb_seen_abi/$3], [],
171 [AM_CONDITIONAL([ABI_]_ABI, [test x$ABI = x$3])dnl
172 m4_define([catacomb_seen_abi/$3], [t])])])
173 catacomb_CPU_FAMILIES([catacomb_COND_CPU])
174 AM_CONDITIONAL([KNOWN_CPUFAM], [test x$CPUFAM != xnil])
176 dnl Report on what we found.
178 nil) AC_MSG_RESULT([not supported]) ;;
179 *) AC_MSG_RESULT([$CPUFAM/$ABI]) ;;
182 dnl Consider enabling support for assembler-level debugging toys.
183 AC_ARG_ENABLE([asm-debug],
184 AS_HELP_STRING([--enable-asm-debug],
185 [enable assembler debugging features]),
186 [mdw_asm_debug=$enableval], [mdw_asm_debug=no])
187 case $CPUFAM in nil) mdw_asm_debug=no ;; esac
188 case $mdw_asm_debug in
190 *) AC_DEFINE([ENABLE_ASM_DEBUG], [1],
191 [Define to enable assembler-level debugging.]) ;;
193 AM_CONDITIONAL([ASM_DEBUG], [test x$mdw_asm_debug != xno])
195 dnl Check for leading underscores on C symbols.
197 case $sys_symbol_underscore in
198 yes) AC_DEFINE([SYM_USCORE], [1],
199 [Define if C symbols are prefixed with an underscore.]) ;;
202 dnl--------------------------------------------------------------------------
203 dnl CPU-specific assembler features.
210 [whether the assembler understands ARMv8 crypto extensions],
211 [mdw_cv_as_armv8_crypto],
212 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
214 .fpu crypto-neon-fp-armv8
224 [mdw_cv_as_armv8_crypto=yes],
225 [mdw_cv_as_armv8_crypto=no])])
229 : ${mdw_cv_as_armv8_crypto=no}
230 AM_CONDITIONAL([HAVE_AS_ARMV8_CRYPTO], [test $mdw_cv_as_armv8_crypto = yes])
231 if test $mdw_cv_as_armv8_crypto = yes; then
232 AC_DEFINE([HAVE_AS_ARMV8_CRYPTO], [1],
233 [Define to 1 if your ARM assembler supports the ARMv8 crypto instructions.])
236 dnl--------------------------------------------------------------------------
237 dnl C programming environment.
243 dnl Find out if we're cross-compiling.
244 AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
246 dnl Various standard types.
247 AC_CHECK_TYPE([pid_t], [],
248 [AC_DEFINE([pid_t], [int],
249 [Define to `int' if <sys/types.h> does not define])])
251 AC_CHECK_TYPE([ssize_t], [],
252 [AC_DEFINE([ssize_t], [int],
253 [Define to `int' if <sys/types.h> does not define])])
254 AC_CHECK_TYPE([socklen_t], [],
255 [AC_DEFINE([socklen_t], [int],
256 [Define to `int' if <sys/socket.h> does not define])],
258 #include <sys/socket.h>
261 dnl The maths library.
262 mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
263 AC_SEARCH_LIBS([log], [m])
264 AC_SEARCH_LIBS([sqrt], [m])
265 CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
267 dnl Logging is weird under Termux. Unfortunately, it involves macros, so we
268 dnl have to do this the hard way.
270 [library needed for syslog], [mdw_cv_syslog_lib],
271 [mdw_ORIG_LIBS=$LIBS LIBS=
273 AC_TRY_LINK([#include <syslog.h>],
274 [openlog("test", LOG_PID, LOG_DAEMON);
275 syslog(LOG_ERR, "this is a test");],
278 *,t) mdw_cv_syslog_lib=${LIBS:-none}; break ;;
279 0,nil) LIBS="-llog" ;;
280 1,nil) AC_MSG_ERROR("failed to link test program") ;;
283 LIBS=$mdw_ORIG_LIBS])
284 case $mdw_cv_syslog_lib in
286 *) LOGLIBS=$mdw_cv_syslog_lib ;;
290 dnl Find out whether very long integer types are available.
291 AC_CHECK_HEADERS([stdint.h])
292 AC_SUBST([have_stdint_h])
295 dnl Some equipment wanted for checking CPU features at runtime.
296 AC_CHECK_HEADERS([asm/hwcap.h])
297 AC_CHECK_HEADERS([sys/auxv.h])
298 AC_CHECK_HEADERS([linux/auxvec.h])
299 AC_CHECK_FUNCS([getauxval])
301 dnl Some equipment for measuring CPU performance.
302 AC_CHECK_HEADERS([linux/perf_event.h])
304 dnl Find the bit lengths of the obvious integer types. This will be useful
305 dnl when deciding on a representation for multiprecision integers.
306 type_bits="" type_bits_sep=""
307 AC_DEFUN([catacomb_UINT_BITS],
308 [mdw_UINT_BITS([$2], [$1])
309 type_bits="$type_bits$type_bits_sep('$1', $[]$1_bits)"
311 catacomb_UINT_BITS([uchar], [unsigned char])
312 catacomb_UINT_BITS([ushort], [unsigned short])
313 catacomb_UINT_BITS([uint], [unsigned int])
314 catacomb_UINT_BITS([ulong], [unsigned long])
315 if test "$ac_cv_c_long_long" = "yes"; then
316 catacomb_UINT_BITS([ullong], [unsigned long long])
318 if test "$ac_cv_header_stdint_h" = "yes"; then
319 catacomb_UINT_BITS([uintmax], [uintmax_t])
321 AC_SUBST([type_bits])
323 dnl Determine the limits of common C integer types.
324 limits="" limits_sep=""
325 AC_DEFUN([catacomb_COMPILE_TIME_CONSTANT],
331 AC_CACHE_CHECK([compile-time value of $2], [mdw_cv_constant_$3],
332 [mdw_PROBE_CONSTANT([mdw_cv_constant_$3], [$2], [$4])])
333 $1=$mdw_cv_constant_$3
336 AC_DEFUN([catacomb_LIMIT],
337 [catacomb_COMPILE_TIME_CONSTANT([lo], [$2], [$1_min],
339 #include <stddef.h>])
340 catacomb_COMPILE_TIME_CONSTANT([hi], [$3], [$1_max],
342 #include <stddef.h>])
343 limits="$limits$limits_sep('$1', $lo, $hi)" limits_sep=", "])
344 catacomb_LIMIT([SCHAR], [SCHAR_MIN], [SCHAR_MAX])
345 catacomb_LIMIT([CHAR], [CHAR_MIN], [CHAR_MAX])
346 catacomb_LIMIT([UCHAR], [=0], [UCHAR_MAX])
347 catacomb_LIMIT([UINT8], [=0], [=0xff])
348 catacomb_LIMIT([SHRT], [SHRT_MIN], [SHRT_MAX])
349 catacomb_LIMIT([USHRT], [=0], [USHRT_MAX])
350 catacomb_LIMIT([UINT16], [=0], [=0xffff])
351 catacomb_LIMIT([INT], [INT_MIN], [INT_MAX])
352 catacomb_LIMIT([UINT], [=0], [UINT_MAX])
353 catacomb_LIMIT([LONG], [LONG_MIN], [LONG_MAX])
354 catacomb_LIMIT([ULONG], [=0], [ULONG_MAX])
355 catacomb_LIMIT([UINT32], [=0], [=0xffffffff])
356 if test "$ac_cv_c_long_long" = "yes"; then
357 catacomb_LIMIT([LLONG], [LLONG_MIN], [LLONG_MAX])
358 catacomb_LIMIT([ULLONG], [=0], [ULLONG_MAX])
360 catacomb_LIMIT([SIZET], [=0], [~(size_t)0])
363 dnl Figure out other aspects of the implementation's arithmetic.
364 AC_CACHE_CHECK([whether negative numbers use two's complement],
365 [catacomb_cv_neg_twoc],
367 [#include <limits.h>],
368 [int check[2*!!(-INT_MAX == INT_MIN + 1) - 1];],
369 [catacomb_cv_neg_twoc=yes],
370 [catacomb_cv_neg_twoc=no])])
371 case $catacomb_cv_neg_twoc in
373 AC_DEFINE([NEG_TWOC], [1],
374 [Define if signed numbers are represented in two's complement.])
378 dnl Functions used for noise-gathering.
379 AC_CHECK_FUNCS([setgroups])
380 AC_CHECK_HEADERS([linux/random.h])
381 mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
382 AC_SEARCH_LIBS([clock_gettime], [rt])
383 CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
384 if test "$ac_cv_search_clock_gettime" != no; then
385 AC_DEFINE([HAVE_CLOCK_GETTIME], [1],
386 [Define if you have the \`clock_gettime' function.])
388 AC_CHECK_FUNCS([getentropy])
389 AC_CACHE_CHECK([whether the freewheel noise generator will work],
390 [catacomb_cv_freewheel],
393 #include <sys/time.h>],
394 [struct itimerval itv = { { 0, 0 }, { 0, 5000 } };
396 setitimer(ITIMER_REAL, &itv, 0);
398 [catacomb_cv_freewheel=yes],
399 [catacomb_cv_freewheel=no])])
400 case $catacomb_cv_freewheel in
402 AC_DEFINE([USE_FREEWHEEL], [1],
403 [Define if you want to use the freewheel noise generator.])
407 dnl Support for the passphrase pixie.
409 AC_SEARCH_LIBS([socket], [socket])
410 AC_SUBST([PIXIE_LIBS], [$LIBS])
413 dnl Memory locking support.
414 AC_CHECK_FUNCS([mlock])
416 dnl See if we can find Valgrind's header files.
417 AC_CHECK_HEADER([valgrind/memcheck.h],
418 AC_DEFINE([HAVE_VALGRIND_H], [1],
419 [Define if the Valgrind header files are available.])
422 dnl Set the master libraries we need.
423 AC_SUBST([CATACOMB_LIBS])
425 dnl Necessary support libraries.
426 PKG_CHECK_MODULES([mLib], [mLib >= 2.4.1])
427 AM_CFLAGS="$AM_CFLAGS $mLib_CFLAGS"
429 dnl--------------------------------------------------------------------------
432 dnl Make sure we have a suitable version.
433 AM_PATH_PYTHON([2.5])
435 dnl--------------------------------------------------------------------------
436 dnl Special debugging options.
439 [AS_HELP_STRING([--enable-mpw], [force small-width mp digits])],
440 [case "$enableval" in
442 AC_DEFINE([FORCE_MPW_SHORT], [1],
443 [Define to force small-width mp digits.])
446 AC_DEFINE([FORCE_MPW_CUSSID], [1],
447 [Define to force strange-width mp digits.])
451 dnl--------------------------------------------------------------------------
454 AC_CONFIG_HEADER([config/config.h])
468 dnl----- That's all, folks --------------------------------------------------