Merge branch '2.5.x'
[catacomb] / configure.ac
CommitLineData
ba6e6b64
MW
1dnl -*-autoconf-*-
2dnl
3dnl Configuration script for Catacomb
4dnl
5dnl (c) 2013 Straylight/Edgeware
6dnl
7
8dnl----- Licensing notice ---------------------------------------------------
9dnl
10dnl This file is part of Catacomb.
11dnl
12dnl Catacomb is free software; you can redistribute it and/or modify
13dnl it under the terms of the GNU Library General Public License as
14dnl published by the Free Software Foundation; either version 2 of the
15dnl License, or (at your option) any later version.
16dnl
17dnl Catacomb is distributed in the hope that it will be useful,
18dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
19dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20dnl GNU Library General Public License for more details.
21dnl
22dnl You should have received a copy of the GNU Library General Public
23dnl License along with Catacomb; if not, write to the Free
24dnl Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25dnl MA 02111-1307, USA.
26
27dnl--------------------------------------------------------------------------
28dnl Initialization.
29
30mdw_AUTO_VERSION
31AC_INIT([catacomb], AUTO_VERSION, [mdw@distorted.org.uk])
32AC_CONFIG_SRCDIR([catacomb.pc.in])
33AC_CONFIG_AUX_DIR([config])
1c8e76bd 34AM_INIT_AUTOMAKE([foreign parallel-tests color-tests subdir-objects])
08e2be29 35AC_CANONICAL_HOST
ba6e6b64
MW
36mdw_SILENT_RULES
37
38AC_PROG_CC
39AX_CFLAGS_WARN_ALL
40AM_PROG_LIBTOOL
41mdw_LIBTOOL_VERSION_INFO
42
6adca914
MW
43AM_PROG_AS
44
ba6e6b64
MW
45AC_PROG_YACC
46
47AC_SUBST(AM_CFLAGS)
48
49dnl--------------------------------------------------------------------------
7a5af13c
MW
50dnl Define language support for assembler.
51dnl
52dnl This is stolen from https://gitlab.crest.iu.edu/jsfiroz/hpx/commit/
53dnl 84be4345db6eec3797a57b8e53483cb43f4733bf
54
55AC_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'])
61
62AC_DEFUN([AC_LANG_PREPROC(CPPAS)], [AC_REQUIRE([AC_PROG_CPP])])
63AC_DEFUN([AC_LANG_COMPILER(CPPAS)], [AC_REQUIRE([AM_PROG_AS])])
64AC_DEFUN([AC_LANG_CONFTEST(CPPAS)],
65 [cat confdefs.h - <<_ACEOF >conftest.$ac_ext
66/* end confdefs.h. */
67$1
68_ACEOF])
69
7a5af13c 70dnl--------------------------------------------------------------------------
08e2be29
MW
71dnl Host-specific configuration.
72
ff1f7e22
MW
73dnl The table of CPU families and ABIs which we might support. Support is
74dnl not uniform: each dispatched function might or might not have an
75dnl implementation for any particular CPU/ABI combination.
08e2be29 76AC_DEFUN([catacomb_CPU_FAMILIES],
0f23f75f
MW
77 [$1([i[[3-6]]86,cygwin], [x86], [win])
78 $1([i[[3-6]]86,*], [x86], [sysv])
79 $1([x86_64,cygwin], [amd64], [win])
61bd904b 80 $1([x86_64,*], [amd64], [sysv])
e492db88
MW
81 $1([arm,* | armv*,*], [armel], [std])
82 $1([aarch64,*], [arm64], [std])])
ff1f7e22
MW
83
84dnl A utility to clear the `seen' flags, used so as to process each CPU or
85dnl ABI once.
86m4_define([catacomb_CLEAR_FLAGS],
87[m4_ifdef([catacomb_seen_cpu/$2],
88 [m4_undefine([catacomb_seen_cpu/$2])])dnl
89m4_ifdef([catacomb_seen_abi/$3],
90 [m4_undefine([catacomb_seen_abi/$3])])])
08e2be29 91
ff1f7e22 92dnl Identify the current host.
401722dc
MW
93case $host_cpu,$host_os in
94 m4_define([catacomb_CPU_CASE],
95 [$1) CPUFAM=$2 ABI=$3 ;;
08e2be29 96])
401722dc
MW
97 catacomb_CPU_FAMILIES([catacomb_CPU_CASE])
98 *) CPUFAM=nil ABI=nil ;;
99esac
100
8ed49b83
MW
101dnl Now check the assembler. We have target-specific requirements here, so
102dnl we couldn't do this any earlier.
401722dc
MW
103AC_CACHE_CHECK(
104 [whether the assembler is likely to work], [mdw_cv_gnuish_as],
105 [AC_LANG_PUSH([CPPAS])
106 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
107 .text
108 .L\$_test = 23
109.macro mymac
110 .L\$_test = .L\$_test + 1
111.endm
112 .globl foo
113 .extern bar
114 mymac]])],
115 [mdw_cv_gnuish_as=yes], [mdw_cv_gnuish_as=no])
8ed49b83
MW
116 case $CPUFAM in
117 x86 | amd64)
118 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
119 .text
120 .arch pentium4
121 .intel_syntax noprefix
122 .globl foo
123foo:
124 adcd var, 0
125 ret
126 .data
127var: .long 1
128 ]])],
129 [:], [mdw_cv_gnuish_as=no])
130 ;;
131 esac
401722dc
MW
132 AC_LANG_POP([CPPAS])])
133AM_CONDITIONAL([GNUISH_AS], [test $mdw_cv_gnuish_as = yes])
134if test $mdw_cv_gnuish_as = no; then CPUFAM=nil ABI=nil; fi
ff1f7e22 135
58a125f0
MW
136dnl A hairy macro used to set the `CPUFAM_...' and `ABI_...' variables. We
137dnl basically need to do the same thing for the family and ABI, so it's worth
138dnl some effort to hide the ugliness.
139m4_define([catacomb_DEFINE_CPU_OR_ABI],
140[case $$1 in
141 m4_define([_def],
142 [m4_ifdef([catacomb_seen_$3/$$2], [],
143 [$$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])
ff1f7e22 147 nil) ;;
22cfd817 148 *) AC_MSG_ERROR([BUG: unexpected $1 \`$$1']) ;;
58a125f0 149esac])
ff1f7e22 150
401722dc
MW
151dnl Now that's out the way, we can explain what we're doing.
152AC_MSG_CHECKING([CPU family and ABI])
153
58a125f0 154dnl Figure out the target CPU family and ABI.
ff1f7e22 155catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
58a125f0
MW
156catacomb_DEFINE_CPU_OR_ABI([CPUFAM], [2], [cpu],
157 [CPUFAM_], [Define if target CPU is \`$][2\'.])
158catacomb_DEFINE_CPU_OR_ABI([ABI], [3], [abi],
159 [ABI_], [Define if target ABI is \`$][3\'.])
ff1f7e22
MW
160
161dnl Establish Automake conditions for things.
162catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
163m4_define([catacomb_COND_CPU],
164[m4_define([_CPU], m4_translit([$2], [a-z], [A-Z]))
165m4_define([_ABI], m4_translit([$3], [a-z], [A-Z]))
166AM_CONDITIONAL([CPUABI_]_CPU[_]_ABI, [test x$CPUFAM/$ABI = x$2/$3])
167m4_ifdef([catacomb_seen_cpu/$2], [],
168[AM_CONDITIONAL([CPUFAM_]_CPU, [test x$CPUFAM = x$2])dnl
169m4_define([catacomb_seen_cpu/$2], [t])])
170m4_ifdef([catacomb_seen_abi/$3], [],
171[AM_CONDITIONAL([ABI_]_ABI, [test x$ABI = x$3])dnl
172m4_define([catacomb_seen_abi/$3], [t])])])
173catacomb_CPU_FAMILIES([catacomb_COND_CPU])
174AM_CONDITIONAL([KNOWN_CPUFAM], [test x$CPUFAM != xnil])
175
176dnl Report on what we found.
177case $CPUFAM in
178 nil) AC_MSG_RESULT([not supported]) ;;
179 *) AC_MSG_RESULT([$CPUFAM/$ABI]) ;;
08e2be29 180esac
08e2be29 181
10ac2992 182dnl Consider enabling support for assembler-level debugging toys.
eb9c5e88
MW
183AC_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])
187case $CPUFAM in nil) mdw_asm_debug=no ;; esac
f111fa69 188case $mdw_asm_debug in
eb9c5e88
MW
189 no) ;;
190 *) AC_DEFINE([ENABLE_ASM_DEBUG], [1],
191 [Define to enable assembler-level debugging.]) ;;
192esac
c36211b3 193AM_CONDITIONAL([ASM_DEBUG], [test x$mdw_asm_debug != xno])
eb9c5e88 194
772740dd
MW
195dnl Check for leading underscores on C symbols.
196LT_SYS_SYMBOL_USCORE
197case $sys_symbol_underscore in
198 yes) AC_DEFINE([SYM_USCORE], [1],
199 [Define if C symbols are prefixed with an underscore.]) ;;
200esac
201
08e2be29 202dnl--------------------------------------------------------------------------
26e182fc
MW
203dnl CPU-specific assembler features.
204
205AC_LANG([CPPAS])
206
207case $CPUFAM in
208 armel)
209 AC_CACHE_CHECK(
210 [whether the assembler understands ARMv8 crypto extensions],
211 [mdw_cv_as_armv8_crypto],
212 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
213 .arch armv8-a
214 .fpu crypto-neon-fp-armv8
215
216 .text
217 .globl foo
218foo:
219 vldmia r0, {d0-d3}
220 aese.8 q0, q1
221 aesmc.8 q0, q0
222 vstmia r0, {d0, d1}
223 bx r14]])],
224 [mdw_cv_as_armv8_crypto=yes],
225 [mdw_cv_as_armv8_crypto=no])])
226 ;;
227esac
228
229: ${mdw_cv_as_armv8_crypto=no}
230AM_CONDITIONAL([HAVE_AS_ARMV8_CRYPTO], [test $mdw_cv_as_armv8_crypto = yes])
231if 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.])
234fi
235
236dnl--------------------------------------------------------------------------
ba6e6b64
MW
237dnl C programming environment.
238
fedd2209
MW
239AC_LANG([C])
240
02fe0bac
MW
241CATACOMB_LIBS=
242
0f00dc4c
MW
243dnl Find out if we're cross-compiling.
244AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
245
ba6e6b64 246dnl Various standard types.
2527c2f7
MW
247AC_CHECK_TYPE([pid_t], [],
248 [AC_DEFINE([pid_t], [int],
249 [Define to `int' if <sys/types.h> does not define])])
ba6e6b64 250AC_TYPE_UID_T
2527c2f7
MW
251AC_CHECK_TYPE([ssize_t], [],
252 [AC_DEFINE([ssize_t], [int],
253 [Define to `int' if <sys/types.h> does not define])])
254AC_CHECK_TYPE([socklen_t], [],
255 [AC_DEFINE([socklen_t], [int],
256 [Define to `int' if <sys/socket.h> does not define])],
257 [AC_INCLUDES_DEFAULT
258#include <sys/socket.h>
259])
ba6e6b64
MW
260
261dnl The maths library.
f72de1ee 262mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
ba6e6b64
MW
263AC_SEARCH_LIBS([log], [m])
264AC_SEARCH_LIBS([sqrt], [m])
f72de1ee 265CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
ba6e6b64 266
be12dd9f
MW
267dnl Logging is weird under Termux. Unfortunately, it involves macros, so we
268dnl have to do this the hard way.
269AC_CACHE_CHECK(
270 [library needed for syslog], [mdw_cv_syslog_lib],
271 [mdw_ORIG_LIBS=$LIBS LIBS=
272 for i in 0 1; do
273 AC_TRY_LINK([#include <syslog.h>],
274 [openlog("test", LOG_PID, LOG_DAEMON);
275 syslog(LOG_ERR, "this is a test");],
276 [ok=t], [ok=nil])
277 case $i,$ok in
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") ;;
281 esac
282 done
283 LIBS=$mdw_ORIG_LIBS])
284case $mdw_cv_syslog_lib in
285 none) LOGLIBS= ;;
286 *) LOGLIBS=$mdw_cv_syslog_lib ;;
287esac
288AC_SUBST([LOGLIBS])
289
1c3d4cf5
MW
290dnl Find out whether very long integer types are available.
291AC_CHECK_HEADERS([stdint.h])
292AC_SUBST([have_stdint_h])
729a52ce 293AX_C_LONG_LONG
1c3d4cf5 294
fedd2209
MW
295dnl Some equipment wanted for checking CPU features at runtime.
296AC_CHECK_HEADERS([asm/hwcap.h])
297AC_CHECK_HEADERS([sys/auxv.h])
298AC_CHECK_HEADERS([linux/auxvec.h])
299AC_CHECK_FUNCS([getauxval])
300
8ae2bc5c
MW
301dnl Some equipment for measuring CPU performance.
302AC_CHECK_HEADERS([linux/perf_event.h])
303
1c3d4cf5
MW
304dnl Find the bit lengths of the obvious integer types. This will be useful
305dnl when deciding on a representation for multiprecision integers.
306type_bits="" type_bits_sep=""
307AC_DEFUN([catacomb_UINT_BITS],
308 [mdw_UINT_BITS([$2], [$1])
309 type_bits="$type_bits$type_bits_sep('$1', $[]$1_bits)"
310 type_bits_sep=", "])
311catacomb_UINT_BITS([uchar], [unsigned char])
312catacomb_UINT_BITS([ushort], [unsigned short])
313catacomb_UINT_BITS([uint], [unsigned int])
314catacomb_UINT_BITS([ulong], [unsigned long])
315if test "$ac_cv_c_long_long" = "yes"; then
316 catacomb_UINT_BITS([ullong], [unsigned long long])
317fi
318if test "$ac_cv_header_stdint_h" = "yes"; then
319 catacomb_UINT_BITS([uintmax], [uintmax_t])
320fi
321AC_SUBST([type_bits])
322
323dnl Determine the limits of common C integer types.
324limits="" limits_sep=""
325AC_DEFUN([catacomb_COMPILE_TIME_CONSTANT],
326 [case "$2" in
327 =*)
328 $1="$2"; $1=${$1#=}
329 ;;
330 *)
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
334 ;;
335 esac])
336AC_DEFUN([catacomb_LIMIT],
337[catacomb_COMPILE_TIME_CONSTANT([lo], [$2], [$1_min],
338[#include <limits.h>
339#include <stddef.h>])
340 catacomb_COMPILE_TIME_CONSTANT([hi], [$3], [$1_max],
341[#include <limits.h>
342#include <stddef.h>])
343 limits="$limits$limits_sep('$1', $lo, $hi)" limits_sep=", "])
344catacomb_LIMIT([SCHAR], [SCHAR_MIN], [SCHAR_MAX])
345catacomb_LIMIT([CHAR], [CHAR_MIN], [CHAR_MAX])
346catacomb_LIMIT([UCHAR], [=0], [UCHAR_MAX])
347catacomb_LIMIT([UINT8], [=0], [=0xff])
348catacomb_LIMIT([SHRT], [SHRT_MIN], [SHRT_MAX])
349catacomb_LIMIT([USHRT], [=0], [USHRT_MAX])
350catacomb_LIMIT([UINT16], [=0], [=0xffff])
351catacomb_LIMIT([INT], [INT_MIN], [INT_MAX])
352catacomb_LIMIT([UINT], [=0], [UINT_MAX])
353catacomb_LIMIT([LONG], [LONG_MIN], [LONG_MAX])
354catacomb_LIMIT([ULONG], [=0], [ULONG_MAX])
355catacomb_LIMIT([UINT32], [=0], [=0xffffffff])
356if test "$ac_cv_c_long_long" = "yes"; then
357 catacomb_LIMIT([LLONG], [LLONG_MIN], [LLONG_MAX])
358 catacomb_LIMIT([ULLONG], [=0], [ULLONG_MAX])
359fi
360catacomb_LIMIT([SIZET], [=0], [~(size_t)0])
361AC_SUBST([limits])
362
ee39a683
MW
363dnl Figure out other aspects of the implementation's arithmetic.
364AC_CACHE_CHECK([whether negative numbers use two's complement],
365 [catacomb_cv_neg_twoc],
366[AC_TRY_COMPILE(
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])])
371case $catacomb_cv_neg_twoc in
372 yes)
373 AC_DEFINE([NEG_TWOC], [1],
374 [Define if signed numbers are represented in two's complement.])
375 ;;
376esac
377
ba6e6b64
MW
378dnl Functions used for noise-gathering.
379AC_CHECK_FUNCS([setgroups])
baf5b59c 380AC_CHECK_HEADERS([linux/random.h])
8039afaf
MW
381mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
382AC_SEARCH_LIBS([clock_gettime], [rt])
383CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
fe54dc64 384if test "$ac_cv_search_clock_gettime" != no; then
8039afaf
MW
385 AC_DEFINE([HAVE_CLOCK_GETTIME], [1],
386 [Define if you have the \`clock_gettime' function.])
387fi
6d4416cc 388AC_CHECK_FUNCS([getentropy])
ba6e6b64
MW
389AC_CACHE_CHECK([whether the freewheel noise generator will work],
390 [catacomb_cv_freewheel],
391[AC_TRY_LINK(
392[#include <setjmp.h>
393#include <sys/time.h>],
394[struct itimerval itv = { { 0, 0 }, { 0, 5000 } };
395jmp_buf j;
396setitimer(ITIMER_REAL, &itv, 0);
f6ca8103 397sigsetjmp(j, 1);],
ba6e6b64
MW
398[catacomb_cv_freewheel=yes],
399[catacomb_cv_freewheel=no])])
400case $catacomb_cv_freewheel in
401 yes)
402 AC_DEFINE([USE_FREEWHEEL], [1],
403 [Define if you want to use the freewheel noise generator.])
404 ;;
405esac
406
407dnl Support for the passphrase pixie.
408mdw_ORIG_LIBS=$LIBS
409AC_SEARCH_LIBS([socket], [socket])
410AC_SUBST([PIXIE_LIBS], [$LIBS])
411LIBS=$mdw_ORIG_LIBS
412
413dnl Memory locking support.
414AC_CHECK_FUNCS([mlock])
415
1aaccf40
MW
416dnl See if we can find Valgrind's header files.
417AC_CHECK_HEADER([valgrind/memcheck.h],
418 AC_DEFINE([HAVE_VALGRIND_H], [1],
419 [Define if the Valgrind header files are available.])
420 [])
421
02fe0bac
MW
422dnl Set the master libraries we need.
423AC_SUBST([CATACOMB_LIBS])
424
ba6e6b64 425dnl Necessary support libraries.
79bc45d0 426PKG_CHECK_MODULES([mLib], [mLib >= 2.4.1])
ba6e6b64
MW
427AM_CFLAGS="$AM_CFLAGS $mLib_CFLAGS"
428
429dnl--------------------------------------------------------------------------
430dnl Python.
431
432dnl Make sure we have a suitable version.
433AM_PATH_PYTHON([2.5])
434
435dnl--------------------------------------------------------------------------
436dnl Special debugging options.
437
438AC_ARG_ENABLE([mpw],
439 [AS_HELP_STRING([--enable-mpw], [force small-width mp digits])],
440 [case "$enableval" in
441 y*|t*|short)
442 AC_DEFINE([FORCE_MPW_SHORT], [1],
443 [Define to force small-width mp digits.])
444 ;;
445 cussid)
446 AC_DEFINE([FORCE_MPW_CUSSID], [1],
447 [Define to force strange-width mp digits.])
448 ;;
449 esac])
450
451dnl--------------------------------------------------------------------------
452dnl Produce output.
453
454AC_CONFIG_HEADER([config/config.h])
455
456AC_CONFIG_FILES(
0f00dc4c
MW
457 [Makefile]
458 [base/Makefile]
459 [key/Makefile]
460 [math/Makefile]
461 [misc/Makefile]
462 [pub/Makefile]
463 [rand/Makefile]
464 [symm/Makefile]
465 [progs/Makefile])
ba6e6b64
MW
466AC_OUTPUT
467
468dnl----- That's all, folks --------------------------------------------------