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