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
43 cygwin* | mingw* | pw32* | os2* | darwin* | cegcc*)
44 TEST_LDFLAGS=-no-fast-install ;;
46 TEST_LDFLAGS=-no-install ;;
48 AC_SUBST([TEST_LDFLAGS])
56 dnl--------------------------------------------------------------------------
57 dnl Define language support for assembler.
59 dnl This is stolen from https://gitlab.crest.iu.edu/jsfiroz/hpx/commit/
60 dnl 84be4345db6eec3797a57b8e53483cb43f4733bf
62 AC_LANG_DEFINE([CPPAS], [cppas], [CPPAS], [CCAS], [C],
63 [ac_ext=S ac_cpp='$CPP $CPPFLAGS'
64 ac_compile='$CCAS -c $CCASFLAGS $CPPFLAGS dnl
65 conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
66 ac_link='$CCAS -oconftest$ac_exeext $CCASFLAGS $CPPFLAGS $LDFLAGS dnl
67 conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'])
69 AC_DEFUN([AC_LANG_PREPROC(CPPAS)], [AC_REQUIRE([AC_PROG_CPP])])
70 AC_DEFUN([AC_LANG_COMPILER(CPPAS)], [AC_REQUIRE([AM_PROG_AS])])
71 AC_DEFUN([AC_LANG_CONFTEST(CPPAS)],
72 [cat confdefs.h - <<_ACEOF >conftest.$ac_ext
77 dnl--------------------------------------------------------------------------
78 dnl Host-specific configuration.
80 dnl The table of CPU families and ABIs which we might support. Support is
81 dnl not uniform: each dispatched function might or might not have an
82 dnl implementation for any particular CPU/ABI combination.
83 AC_DEFUN([catacomb_CPU_FAMILIES],
84 [$1([i[[3-6]]86,cygwin], [x86], [win])
85 $1([i[[3-6]]86,*], [x86], [sysv])
86 $1([x86_64,cygwin], [amd64], [win])
87 $1([x86_64,*], [amd64], [sysv])
88 $1([arm,* | armv*,*], [armel], [std])
89 $1([aarch64,*], [arm64], [std])])
91 dnl A utility to clear the `seen' flags, used so as to process each CPU or
93 m4_define([catacomb_CLEAR_FLAGS],
94 [m4_ifdef([catacomb_seen_cpu/$2],
95 [m4_undefine([catacomb_seen_cpu/$2])])dnl
96 m4_ifdef([catacomb_seen_abi/$3],
97 [m4_undefine([catacomb_seen_abi/$3])])])
99 dnl Identify the current host.
100 case $host_cpu,$host_os in
101 m4_define([catacomb_CPU_CASE],
102 [$1) CPUFAM=$2 ABI=$3 ;;
104 catacomb_CPU_FAMILIES([catacomb_CPU_CASE])
105 *) CPUFAM=nil ABI=nil ;;
108 dnl Now check the assembler. We have target-specific requirements here, so
109 dnl we couldn't do this any earlier.
111 [whether the assembler is likely to work], [mdw_cv_gnuish_as],
112 [AC_LANG_PUSH([CPPAS])
113 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
117 .L\$_test = .L\$_test + 1
122 [mdw_cv_gnuish_as=yes], [mdw_cv_gnuish_as=no])
125 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
128 .intel_syntax noprefix
136 [:], [mdw_cv_gnuish_as=no])
139 AC_LANG_POP([CPPAS])])
140 AM_CONDITIONAL([GNUISH_AS], [test $mdw_cv_gnuish_as = yes])
141 if test $mdw_cv_gnuish_as = no; then CPUFAM=nil ABI=nil; fi
143 dnl A hairy macro used to set the `CPUFAM_...' and `ABI_...' variables. We
144 dnl basically need to do the same thing for the family and ABI, so it's worth
145 dnl some effort to hide the ugliness.
146 m4_define([catacomb_DEFINE_CPU_OR_ABI],
149 [m4_ifdef([catacomb_seen_$3/$$2], [],
151 AC_DEFINE([$4]m4_translit([$$2], [a-z], [A-Z]), [1], [$5])
152 ;;m4_define([catacomb_seen_$3/$$2], [t])])])
153 catacomb_CPU_FAMILIES([_def])
155 *) AC_MSG_ERROR([BUG: unexpected $1 \`$$1']) ;;
158 dnl Now that's out the way, we can explain what we're doing.
159 AC_MSG_CHECKING([CPU family and ABI])
161 dnl Figure out the target CPU family and ABI.
162 catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
163 catacomb_DEFINE_CPU_OR_ABI([CPUFAM], [2], [cpu],
164 [CPUFAM_], [Define if target CPU is \`$][2\'.])
165 catacomb_DEFINE_CPU_OR_ABI([ABI], [3], [abi],
166 [ABI_], [Define if target ABI is \`$][3\'.])
168 dnl Establish Automake conditions for things.
169 catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
170 m4_define([catacomb_COND_CPU],
171 [m4_define([_CPU], m4_translit([$2], [a-z], [A-Z]))
172 m4_define([_ABI], m4_translit([$3], [a-z], [A-Z]))
173 AM_CONDITIONAL([CPUABI_]_CPU[_]_ABI, [test x$CPUFAM/$ABI = x$2/$3])
174 m4_ifdef([catacomb_seen_cpu/$2], [],
175 [AM_CONDITIONAL([CPUFAM_]_CPU, [test x$CPUFAM = x$2])dnl
176 m4_define([catacomb_seen_cpu/$2], [t])])
177 m4_ifdef([catacomb_seen_abi/$3], [],
178 [AM_CONDITIONAL([ABI_]_ABI, [test x$ABI = x$3])dnl
179 m4_define([catacomb_seen_abi/$3], [t])])])
180 catacomb_CPU_FAMILIES([catacomb_COND_CPU])
181 AM_CONDITIONAL([KNOWN_CPUFAM], [test x$CPUFAM != xnil])
183 dnl Report on what we found.
185 nil) AC_MSG_RESULT([not supported]) ;;
186 *) AC_MSG_RESULT([$CPUFAM/$ABI]) ;;
189 dnl Consider enabling support for assembler-level debugging toys.
190 AC_ARG_ENABLE([asm-debug],
191 AS_HELP_STRING([--enable-asm-debug],
192 [enable assembler debugging features]),
193 [mdw_asm_debug=$enableval], [mdw_asm_debug=no])
194 case $CPUFAM in nil) mdw_asm_debug=no ;; esac
195 case $mdw_asm_debug in
197 *) AC_DEFINE([ENABLE_ASM_DEBUG], [1],
198 [Define to enable assembler-level debugging.]) ;;
200 AM_CONDITIONAL([ASM_DEBUG], [test x$mdw_asm_debug != xno])
202 dnl Check for leading underscores on C symbols.
204 case $sys_symbol_underscore in
205 yes) AC_DEFINE([SYM_USCORE], [1],
206 [Define if C symbols are prefixed with an underscore.]) ;;
209 dnl--------------------------------------------------------------------------
210 dnl CPU-specific assembler features.
217 [whether the assembler understands ARMv8 crypto extensions],
218 [mdw_cv_as_armv8_crypto],
219 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
221 .fpu crypto-neon-fp-armv8
231 [mdw_cv_as_armv8_crypto=yes],
232 [mdw_cv_as_armv8_crypto=no])])
236 : ${mdw_cv_as_armv8_crypto=no}
237 AM_CONDITIONAL([HAVE_AS_ARMV8_CRYPTO], [test $mdw_cv_as_armv8_crypto = yes])
238 if test $mdw_cv_as_armv8_crypto = yes; then
239 AC_DEFINE([HAVE_AS_ARMV8_CRYPTO], [1],
240 [Define to 1 if your ARM assembler supports the ARMv8 crypto instructions.])
243 dnl--------------------------------------------------------------------------
244 dnl C programming environment.
250 dnl Find out if we're cross-compiling.
251 AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
253 dnl Various standard types.
254 AC_CHECK_TYPE([pid_t], [],
255 [AC_DEFINE([pid_t], [int],
256 [Define to `int' if <sys/types.h> does not define])])
258 AC_CHECK_TYPE([ssize_t], [],
259 [AC_DEFINE([ssize_t], [int],
260 [Define to `int' if <sys/types.h> does not define])])
261 AC_CHECK_TYPE([socklen_t], [],
262 [AC_DEFINE([socklen_t], [int],
263 [Define to `int' if <sys/socket.h> does not define])],
265 #include <sys/socket.h>
268 dnl The maths library.
269 mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
270 AC_SEARCH_LIBS([log], [m])
271 AC_SEARCH_LIBS([sqrt], [m])
272 CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
274 dnl Logging is weird under Termux. Unfortunately, it involves macros, so we
275 dnl have to do this the hard way.
277 [library needed for syslog], [mdw_cv_syslog_lib],
278 [mdw_ORIG_LIBS=$LIBS LIBS=
280 AC_TRY_LINK([#include <syslog.h>],
281 [openlog("test", LOG_PID, LOG_DAEMON);
282 syslog(LOG_ERR, "this is a test");],
285 *,t) mdw_cv_syslog_lib=${LIBS:-none}; break ;;
286 0,nil) LIBS="-llog" ;;
287 1,nil) AC_MSG_ERROR("failed to link test program") ;;
290 LIBS=$mdw_ORIG_LIBS])
291 case $mdw_cv_syslog_lib in
293 *) LOGLIBS=$mdw_cv_syslog_lib ;;
297 dnl Find out whether very long integer types are available.
298 AC_CHECK_HEADERS([stdint.h])
299 AC_SUBST([have_stdint_h])
302 dnl Some equipment wanted for checking CPU features at runtime.
303 AC_CHECK_HEADERS([asm/hwcap.h])
304 AC_CHECK_HEADERS([sys/auxv.h])
305 AC_CHECK_HEADERS([linux/auxvec.h])
306 AC_CHECK_FUNCS([getauxval])
308 dnl Some equipment for measuring CPU performance.
309 AC_CHECK_HEADERS([linux/perf_event.h])
311 dnl Find the bit lengths of the obvious integer types. This will be useful
312 dnl when deciding on a representation for multiprecision integers.
313 type_bits="" type_bits_sep=""
314 AC_DEFUN([catacomb_UINT_BITS],
315 [mdw_UINT_BITS([$2], [$1])
316 type_bits="$type_bits$type_bits_sep('$1', $[]$1_bits)"
318 catacomb_UINT_BITS([uchar], [unsigned char])
319 catacomb_UINT_BITS([ushort], [unsigned short])
320 catacomb_UINT_BITS([uint], [unsigned int])
321 catacomb_UINT_BITS([ulong], [unsigned long])
322 if test "$ac_cv_c_long_long" = "yes"; then
323 catacomb_UINT_BITS([ullong], [unsigned long long])
325 if test "$ac_cv_header_stdint_h" = "yes"; then
326 catacomb_UINT_BITS([uintmax], [uintmax_t])
328 AC_SUBST([type_bits])
330 dnl Determine the limits of common C integer types.
331 limits="" limits_sep=""
332 AC_DEFUN([catacomb_COMPILE_TIME_CONSTANT],
338 AC_CACHE_CHECK([compile-time value of $2], [mdw_cv_constant_$3],
339 [mdw_PROBE_CONSTANT([mdw_cv_constant_$3], [$2], [$4])])
340 $1=$mdw_cv_constant_$3
343 AC_DEFUN([catacomb_LIMIT],
344 [catacomb_COMPILE_TIME_CONSTANT([lo], [$2], [$1_min],
346 #include <stddef.h>])
347 catacomb_COMPILE_TIME_CONSTANT([hi], [$3], [$1_max],
349 #include <stddef.h>])
350 limits="$limits$limits_sep('$1', $lo, $hi)" limits_sep=", "])
351 catacomb_LIMIT([SCHAR], [SCHAR_MIN], [SCHAR_MAX])
352 catacomb_LIMIT([CHAR], [CHAR_MIN], [CHAR_MAX])
353 catacomb_LIMIT([UCHAR], [=0], [UCHAR_MAX])
354 catacomb_LIMIT([UINT8], [=0], [=0xff])
355 catacomb_LIMIT([SHRT], [SHRT_MIN], [SHRT_MAX])
356 catacomb_LIMIT([USHRT], [=0], [USHRT_MAX])
357 catacomb_LIMIT([UINT16], [=0], [=0xffff])
358 catacomb_LIMIT([INT], [INT_MIN], [INT_MAX])
359 catacomb_LIMIT([UINT], [=0], [UINT_MAX])
360 catacomb_LIMIT([LONG], [LONG_MIN], [LONG_MAX])
361 catacomb_LIMIT([ULONG], [=0], [ULONG_MAX])
362 catacomb_LIMIT([UINT32], [=0], [=0xffffffff])
363 if test "$ac_cv_c_long_long" = "yes"; then
364 catacomb_LIMIT([LLONG], [LLONG_MIN], [LLONG_MAX])
365 catacomb_LIMIT([ULLONG], [=0], [ULLONG_MAX])
367 catacomb_LIMIT([SIZET], [=0], [~(size_t)0])
370 dnl Figure out other aspects of the implementation's arithmetic.
371 AC_CACHE_CHECK([whether negative numbers use two's complement],
372 [catacomb_cv_neg_twoc],
374 [#include <limits.h>],
375 [int check[2*!!(-INT_MAX == INT_MIN + 1) - 1];],
376 [catacomb_cv_neg_twoc=yes],
377 [catacomb_cv_neg_twoc=no])])
378 case $catacomb_cv_neg_twoc in
380 AC_DEFINE([NEG_TWOC], [1],
381 [Define if signed numbers are represented in two's complement.])
385 dnl Functions used for noise-gathering.
386 AC_CHECK_FUNCS([setgroups])
387 AC_CHECK_HEADERS([linux/random.h])
388 mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
389 AC_SEARCH_LIBS([clock_gettime], [rt])
390 CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
391 if test "$ac_cv_search_clock_gettime" != no; then
392 AC_DEFINE([HAVE_CLOCK_GETTIME], [1],
393 [Define if you have the \`clock_gettime' function.])
395 AC_CHECK_FUNCS([getentropy])
396 AC_CACHE_CHECK([whether the freewheel noise generator will work],
397 [catacomb_cv_freewheel],
400 #include <sys/time.h>],
401 [struct itimerval itv = { { 0, 0 }, { 0, 5000 } };
403 setitimer(ITIMER_REAL, &itv, 0);
405 [catacomb_cv_freewheel=yes],
406 [catacomb_cv_freewheel=no])])
407 case $catacomb_cv_freewheel in
409 AC_DEFINE([USE_FREEWHEEL], [1],
410 [Define if you want to use the freewheel noise generator.])
414 dnl Support for the passphrase pixie.
416 AC_SEARCH_LIBS([socket], [socket])
417 AC_SUBST([PIXIE_LIBS], [$LIBS])
420 dnl Memory locking support.
421 AC_CHECK_FUNCS([mlock])
423 dnl See if we can find Valgrind's header files.
424 AC_CHECK_HEADER([valgrind/memcheck.h],
425 AC_DEFINE([HAVE_VALGRIND_H], [1],
426 [Define if the Valgrind header files are available.])
429 dnl Set the master libraries we need.
430 AC_SUBST([CATACOMB_LIBS])
432 dnl Necessary support libraries.
433 PKG_CHECK_MODULES([mLib], [mLib >= 2.4.1])
434 AM_CFLAGS="$AM_CFLAGS $mLib_CFLAGS"
436 dnl--------------------------------------------------------------------------
439 dnl Make sure we have a suitable version.
440 AM_PATH_PYTHON([2.5])
442 dnl--------------------------------------------------------------------------
443 dnl Special debugging options.
446 [AS_HELP_STRING([--enable-mpw], [force small-width mp digits])],
447 [case "$enableval" in
449 AC_DEFINE([FORCE_MPW_SHORT], [1],
450 [Define to force small-width mp digits.])
453 AC_DEFINE([FORCE_MPW_CUSSID], [1],
454 [Define to force strange-width mp digits.])
458 dnl--------------------------------------------------------------------------
461 AC_CONFIG_HEADER([config/config.h])
475 dnl----- That's all, folks --------------------------------------------------