configure.ac: Don't be so picky about identifying ARM variants.
[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])
f1232872 81 $1([arm,* | armv*,*], [armel], [std])])
ff1f7e22
MW
82
83dnl A utility to clear the `seen' flags, used so as to process each CPU or
84dnl ABI once.
85m4_define([catacomb_CLEAR_FLAGS],
86[m4_ifdef([catacomb_seen_cpu/$2],
87 [m4_undefine([catacomb_seen_cpu/$2])])dnl
88m4_ifdef([catacomb_seen_abi/$3],
89 [m4_undefine([catacomb_seen_abi/$3])])])
08e2be29 90
ff1f7e22 91dnl Identify the current host.
401722dc
MW
92case $host_cpu,$host_os in
93 m4_define([catacomb_CPU_CASE],
94 [$1) CPUFAM=$2 ABI=$3 ;;
08e2be29 95])
401722dc
MW
96 catacomb_CPU_FAMILIES([catacomb_CPU_CASE])
97 *) CPUFAM=nil ABI=nil ;;
98esac
99
8ed49b83
MW
100dnl Now check the assembler. We have target-specific requirements here, so
101dnl we couldn't do this any earlier.
401722dc
MW
102AC_CACHE_CHECK(
103 [whether the assembler is likely to work], [mdw_cv_gnuish_as],
104 [AC_LANG_PUSH([CPPAS])
105 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
106 .text
107 .L\$_test = 23
108.macro mymac
109 .L\$_test = .L\$_test + 1
110.endm
111 .globl foo
112 .extern bar
113 mymac]])],
114 [mdw_cv_gnuish_as=yes], [mdw_cv_gnuish_as=no])
8ed49b83
MW
115 case $CPUFAM in
116 x86 | amd64)
117 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
118 .text
119 .arch pentium4
120 .intel_syntax noprefix
121 .globl foo
122foo:
123 adcd var, 0
124 ret
125 .data
126var: .long 1
127 ]])],
128 [:], [mdw_cv_gnuish_as=no])
129 ;;
130 esac
401722dc
MW
131 AC_LANG_POP([CPPAS])])
132AM_CONDITIONAL([GNUISH_AS], [test $mdw_cv_gnuish_as = yes])
133if test $mdw_cv_gnuish_as = no; then CPUFAM=nil ABI=nil; fi
ff1f7e22 134
58a125f0
MW
135dnl A hairy macro used to set the `CPUFAM_...' and `ABI_...' variables. We
136dnl basically need to do the same thing for the family and ABI, so it's worth
137dnl some effort to hide the ugliness.
138m4_define([catacomb_DEFINE_CPU_OR_ABI],
139[case $$1 in
140 m4_define([_def],
141 [m4_ifdef([catacomb_seen_$3/$$2], [],
142 [$$2)
143 AC_DEFINE([$4]m4_translit([$$2], [a-z], [A-Z]), [1], [$5])
144 ;;m4_define([catacomb_seen_$3/$$2], [t])])])
145 catacomb_CPU_FAMILIES([_def])
ff1f7e22 146 nil) ;;
58a125f0
MW
147 *) AC_MSG_ERROR([BUG: unexpected $1 \`$1']) ;;
148esac])
ff1f7e22 149
401722dc
MW
150dnl Now that's out the way, we can explain what we're doing.
151AC_MSG_CHECKING([CPU family and ABI])
152
58a125f0 153dnl Figure out the target CPU family and ABI.
ff1f7e22 154catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
58a125f0
MW
155catacomb_DEFINE_CPU_OR_ABI([CPUFAM], [2], [cpu],
156 [CPUFAM_], [Define if target CPU is \`$][2\'.])
157catacomb_DEFINE_CPU_OR_ABI([ABI], [3], [abi],
158 [ABI_], [Define if target ABI is \`$][3\'.])
ff1f7e22
MW
159
160dnl Establish Automake conditions for things.
161catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
162m4_define([catacomb_COND_CPU],
163[m4_define([_CPU], m4_translit([$2], [a-z], [A-Z]))
164m4_define([_ABI], m4_translit([$3], [a-z], [A-Z]))
165AM_CONDITIONAL([CPUABI_]_CPU[_]_ABI, [test x$CPUFAM/$ABI = x$2/$3])
166m4_ifdef([catacomb_seen_cpu/$2], [],
167[AM_CONDITIONAL([CPUFAM_]_CPU, [test x$CPUFAM = x$2])dnl
168m4_define([catacomb_seen_cpu/$2], [t])])
169m4_ifdef([catacomb_seen_abi/$3], [],
170[AM_CONDITIONAL([ABI_]_ABI, [test x$ABI = x$3])dnl
171m4_define([catacomb_seen_abi/$3], [t])])])
172catacomb_CPU_FAMILIES([catacomb_COND_CPU])
173AM_CONDITIONAL([KNOWN_CPUFAM], [test x$CPUFAM != xnil])
174
175dnl Report on what we found.
176case $CPUFAM in
177 nil) AC_MSG_RESULT([not supported]) ;;
178 *) AC_MSG_RESULT([$CPUFAM/$ABI]) ;;
08e2be29 179esac
08e2be29
MW
180
181dnl--------------------------------------------------------------------------
26e182fc
MW
182dnl CPU-specific assembler features.
183
184AC_LANG([CPPAS])
185
186case $CPUFAM in
187 armel)
188 AC_CACHE_CHECK(
189 [whether the assembler understands ARMv8 crypto extensions],
190 [mdw_cv_as_armv8_crypto],
191 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
192 .arch armv8-a
193 .fpu crypto-neon-fp-armv8
194
195 .text
196 .globl foo
197foo:
198 vldmia r0, {d0-d3}
199 aese.8 q0, q1
200 aesmc.8 q0, q0
201 vstmia r0, {d0, d1}
202 bx r14]])],
203 [mdw_cv_as_armv8_crypto=yes],
204 [mdw_cv_as_armv8_crypto=no])])
205 ;;
206esac
207
208: ${mdw_cv_as_armv8_crypto=no}
209AM_CONDITIONAL([HAVE_AS_ARMV8_CRYPTO], [test $mdw_cv_as_armv8_crypto = yes])
210if test $mdw_cv_as_armv8_crypto = yes; then
211 AC_DEFINE([HAVE_AS_ARMV8_CRYPTO], [1],
212 [Define to 1 if your ARM assembler supports the ARMv8 crypto instructions.])
213fi
214
215dnl--------------------------------------------------------------------------
ba6e6b64
MW
216dnl C programming environment.
217
fedd2209
MW
218AC_LANG([C])
219
02fe0bac
MW
220CATACOMB_LIBS=
221
0f00dc4c
MW
222dnl Find out if we're cross-compiling.
223AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
224
ba6e6b64 225dnl Various standard types.
2527c2f7
MW
226AC_CHECK_TYPE([pid_t], [],
227 [AC_DEFINE([pid_t], [int],
228 [Define to `int' if <sys/types.h> does not define])])
ba6e6b64 229AC_TYPE_UID_T
2527c2f7
MW
230AC_CHECK_TYPE([ssize_t], [],
231 [AC_DEFINE([ssize_t], [int],
232 [Define to `int' if <sys/types.h> does not define])])
233AC_CHECK_TYPE([socklen_t], [],
234 [AC_DEFINE([socklen_t], [int],
235 [Define to `int' if <sys/socket.h> does not define])],
236 [AC_INCLUDES_DEFAULT
237#include <sys/socket.h>
238])
ba6e6b64
MW
239
240dnl The maths library.
f72de1ee 241mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
ba6e6b64
MW
242AC_SEARCH_LIBS([log], [m])
243AC_SEARCH_LIBS([sqrt], [m])
f72de1ee 244CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
ba6e6b64 245
be12dd9f
MW
246dnl Logging is weird under Termux. Unfortunately, it involves macros, so we
247dnl have to do this the hard way.
248AC_CACHE_CHECK(
249 [library needed for syslog], [mdw_cv_syslog_lib],
250 [mdw_ORIG_LIBS=$LIBS LIBS=
251 for i in 0 1; do
252 AC_TRY_LINK([#include <syslog.h>],
253 [openlog("test", LOG_PID, LOG_DAEMON);
254 syslog(LOG_ERR, "this is a test");],
255 [ok=t], [ok=nil])
256 case $i,$ok in
257 *,t) mdw_cv_syslog_lib=${LIBS:-none}; break ;;
258 0,nil) LIBS="-llog" ;;
259 1,nil) AC_MSG_ERROR("failed to link test program") ;;
260 esac
261 done
262 LIBS=$mdw_ORIG_LIBS])
263case $mdw_cv_syslog_lib in
264 none) LOGLIBS= ;;
265 *) LOGLIBS=$mdw_cv_syslog_lib ;;
266esac
267AC_SUBST([LOGLIBS])
268
1c3d4cf5
MW
269dnl Find out whether very long integer types are available.
270AC_CHECK_HEADERS([stdint.h])
271AC_SUBST([have_stdint_h])
729a52ce 272AX_C_LONG_LONG
1c3d4cf5 273
fedd2209
MW
274dnl Some equipment wanted for checking CPU features at runtime.
275AC_CHECK_HEADERS([asm/hwcap.h])
276AC_CHECK_HEADERS([sys/auxv.h])
277AC_CHECK_HEADERS([linux/auxvec.h])
278AC_CHECK_FUNCS([getauxval])
279
1c3d4cf5
MW
280dnl Find the bit lengths of the obvious integer types. This will be useful
281dnl when deciding on a representation for multiprecision integers.
282type_bits="" type_bits_sep=""
283AC_DEFUN([catacomb_UINT_BITS],
284 [mdw_UINT_BITS([$2], [$1])
285 type_bits="$type_bits$type_bits_sep('$1', $[]$1_bits)"
286 type_bits_sep=", "])
287catacomb_UINT_BITS([uchar], [unsigned char])
288catacomb_UINT_BITS([ushort], [unsigned short])
289catacomb_UINT_BITS([uint], [unsigned int])
290catacomb_UINT_BITS([ulong], [unsigned long])
291if test "$ac_cv_c_long_long" = "yes"; then
292 catacomb_UINT_BITS([ullong], [unsigned long long])
293fi
294if test "$ac_cv_header_stdint_h" = "yes"; then
295 catacomb_UINT_BITS([uintmax], [uintmax_t])
296fi
297AC_SUBST([type_bits])
298
299dnl Determine the limits of common C integer types.
300limits="" limits_sep=""
301AC_DEFUN([catacomb_COMPILE_TIME_CONSTANT],
302 [case "$2" in
303 =*)
304 $1="$2"; $1=${$1#=}
305 ;;
306 *)
307 AC_CACHE_CHECK([compile-time value of $2], [mdw_cv_constant_$3],
308 [mdw_PROBE_CONSTANT([mdw_cv_constant_$3], [$2], [$4])])
309 $1=$mdw_cv_constant_$3
310 ;;
311 esac])
312AC_DEFUN([catacomb_LIMIT],
313[catacomb_COMPILE_TIME_CONSTANT([lo], [$2], [$1_min],
314[#include <limits.h>
315#include <stddef.h>])
316 catacomb_COMPILE_TIME_CONSTANT([hi], [$3], [$1_max],
317[#include <limits.h>
318#include <stddef.h>])
319 limits="$limits$limits_sep('$1', $lo, $hi)" limits_sep=", "])
320catacomb_LIMIT([SCHAR], [SCHAR_MIN], [SCHAR_MAX])
321catacomb_LIMIT([CHAR], [CHAR_MIN], [CHAR_MAX])
322catacomb_LIMIT([UCHAR], [=0], [UCHAR_MAX])
323catacomb_LIMIT([UINT8], [=0], [=0xff])
324catacomb_LIMIT([SHRT], [SHRT_MIN], [SHRT_MAX])
325catacomb_LIMIT([USHRT], [=0], [USHRT_MAX])
326catacomb_LIMIT([UINT16], [=0], [=0xffff])
327catacomb_LIMIT([INT], [INT_MIN], [INT_MAX])
328catacomb_LIMIT([UINT], [=0], [UINT_MAX])
329catacomb_LIMIT([LONG], [LONG_MIN], [LONG_MAX])
330catacomb_LIMIT([ULONG], [=0], [ULONG_MAX])
331catacomb_LIMIT([UINT32], [=0], [=0xffffffff])
332if test "$ac_cv_c_long_long" = "yes"; then
333 catacomb_LIMIT([LLONG], [LLONG_MIN], [LLONG_MAX])
334 catacomb_LIMIT([ULLONG], [=0], [ULLONG_MAX])
335fi
336catacomb_LIMIT([SIZET], [=0], [~(size_t)0])
337AC_SUBST([limits])
338
ee39a683
MW
339dnl Figure out other aspects of the implementation's arithmetic.
340AC_CACHE_CHECK([whether negative numbers use two's complement],
341 [catacomb_cv_neg_twoc],
342[AC_TRY_COMPILE(
343[#include <limits.h>],
344[int check[2*!!(-INT_MAX == INT_MIN + 1) - 1];],
345[catacomb_cv_neg_twoc=yes],
346[catacomb_cv_neg_twoc=no])])
347case $catacomb_cv_neg_twoc in
348 yes)
349 AC_DEFINE([NEG_TWOC], [1],
350 [Define if signed numbers are represented in two's complement.])
351 ;;
352esac
353
ba6e6b64
MW
354dnl Functions used for noise-gathering.
355AC_CHECK_FUNCS([setgroups])
baf5b59c 356AC_CHECK_HEADERS([linux/random.h])
8039afaf
MW
357mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
358AC_SEARCH_LIBS([clock_gettime], [rt])
359CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
fe54dc64 360if test "$ac_cv_search_clock_gettime" != no; then
8039afaf
MW
361 AC_DEFINE([HAVE_CLOCK_GETTIME], [1],
362 [Define if you have the \`clock_gettime' function.])
363fi
6d4416cc 364AC_CHECK_FUNCS([getentropy])
ba6e6b64
MW
365AC_CACHE_CHECK([whether the freewheel noise generator will work],
366 [catacomb_cv_freewheel],
367[AC_TRY_LINK(
368[#include <setjmp.h>
369#include <sys/time.h>],
370[struct itimerval itv = { { 0, 0 }, { 0, 5000 } };
371jmp_buf j;
372setitimer(ITIMER_REAL, &itv, 0);
f6ca8103 373sigsetjmp(j, 1);],
ba6e6b64
MW
374[catacomb_cv_freewheel=yes],
375[catacomb_cv_freewheel=no])])
376case $catacomb_cv_freewheel in
377 yes)
378 AC_DEFINE([USE_FREEWHEEL], [1],
379 [Define if you want to use the freewheel noise generator.])
380 ;;
381esac
382
383dnl Support for the passphrase pixie.
384mdw_ORIG_LIBS=$LIBS
385AC_SEARCH_LIBS([socket], [socket])
386AC_SUBST([PIXIE_LIBS], [$LIBS])
387LIBS=$mdw_ORIG_LIBS
388
389dnl Memory locking support.
390AC_CHECK_FUNCS([mlock])
391
1aaccf40
MW
392dnl See if we can find Valgrind's header files.
393AC_CHECK_HEADER([valgrind/memcheck.h],
394 AC_DEFINE([HAVE_VALGRIND_H], [1],
395 [Define if the Valgrind header files are available.])
396 [])
397
02fe0bac
MW
398dnl Set the master libraries we need.
399AC_SUBST([CATACOMB_LIBS])
400
ba6e6b64 401dnl Necessary support libraries.
a1acefec 402PKG_CHECK_MODULES([mLib], [mLib >= 2.2.2.1])
ba6e6b64
MW
403AM_CFLAGS="$AM_CFLAGS $mLib_CFLAGS"
404
405dnl--------------------------------------------------------------------------
406dnl Python.
407
408dnl Make sure we have a suitable version.
409AM_PATH_PYTHON([2.5])
410
411dnl--------------------------------------------------------------------------
412dnl Special debugging options.
413
414AC_ARG_ENABLE([mpw],
415 [AS_HELP_STRING([--enable-mpw], [force small-width mp digits])],
416 [case "$enableval" in
417 y*|t*|short)
418 AC_DEFINE([FORCE_MPW_SHORT], [1],
419 [Define to force small-width mp digits.])
420 ;;
421 cussid)
422 AC_DEFINE([FORCE_MPW_CUSSID], [1],
423 [Define to force strange-width mp digits.])
424 ;;
425 esac])
426
427dnl--------------------------------------------------------------------------
428dnl Produce output.
429
430AC_CONFIG_HEADER([config/config.h])
431
432AC_CONFIG_FILES(
0f00dc4c
MW
433 [Makefile]
434 [base/Makefile]
435 [key/Makefile]
436 [math/Makefile]
437 [misc/Makefile]
438 [pub/Makefile]
439 [rand/Makefile]
440 [symm/Makefile]
441 [progs/Makefile])
ba6e6b64
MW
442AC_OUTPUT
443
444dnl----- That's all, folks --------------------------------------------------