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