configure.ac: Don't be so picky about identifying ARM variants.
[catacomb] / configure.ac
1 dnl -*-autoconf-*-
2 dnl
3 dnl Configuration script for Catacomb
4 dnl
5 dnl (c) 2013 Straylight/Edgeware
6 dnl
7
8 dnl----- Licensing notice ---------------------------------------------------
9 dnl
10 dnl This file is part of Catacomb.
11 dnl
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.
16 dnl
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.
21 dnl
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.
26
27 dnl--------------------------------------------------------------------------
28 dnl Initialization.
29
30 mdw_AUTO_VERSION
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])
35 AC_CANONICAL_HOST
36 mdw_SILENT_RULES
37
38 AC_PROG_CC
39 AX_CFLAGS_WARN_ALL
40 AM_PROG_LIBTOOL
41 mdw_LIBTOOL_VERSION_INFO
42
43 AM_PROG_AS
44
45 AC_PROG_YACC
46
47 AC_SUBST(AM_CFLAGS)
48
49 dnl--------------------------------------------------------------------------
50 dnl Define language support for assembler.
51 dnl
52 dnl This is stolen from https://gitlab.crest.iu.edu/jsfiroz/hpx/commit/
53 dnl 84be4345db6eec3797a57b8e53483cb43f4733bf
54
55 AC_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
62 AC_DEFUN([AC_LANG_PREPROC(CPPAS)], [AC_REQUIRE([AC_PROG_CPP])])
63 AC_DEFUN([AC_LANG_COMPILER(CPPAS)], [AC_REQUIRE([AM_PROG_AS])])
64 AC_DEFUN([AC_LANG_CONFTEST(CPPAS)],
65 [cat confdefs.h - <<_ACEOF >conftest.$ac_ext
66 /* end confdefs.h. */
67 $1
68 _ACEOF])
69
70 dnl--------------------------------------------------------------------------
71 dnl Host-specific configuration.
72
73 dnl The table of CPU families and ABIs which we might support. Support is
74 dnl not uniform: each dispatched function might or might not have an
75 dnl implementation for any particular CPU/ABI combination.
76 AC_DEFUN([catacomb_CPU_FAMILIES],
77 [$1([i[[3-6]]86,cygwin], [x86], [win])
78 $1([i[[3-6]]86,*], [x86], [sysv])
79 $1([x86_64,cygwin], [amd64], [win])
80 $1([x86_64,*], [amd64], [sysv])
81 $1([arm,* | armv*,*], [armel], [std])])
82
83 dnl A utility to clear the `seen' flags, used so as to process each CPU or
84 dnl ABI once.
85 m4_define([catacomb_CLEAR_FLAGS],
86 [m4_ifdef([catacomb_seen_cpu/$2],
87 [m4_undefine([catacomb_seen_cpu/$2])])dnl
88 m4_ifdef([catacomb_seen_abi/$3],
89 [m4_undefine([catacomb_seen_abi/$3])])])
90
91 dnl Identify the current host.
92 case $host_cpu,$host_os in
93 m4_define([catacomb_CPU_CASE],
94 [$1) CPUFAM=$2 ABI=$3 ;;
95 ])
96 catacomb_CPU_FAMILIES([catacomb_CPU_CASE])
97 *) CPUFAM=nil ABI=nil ;;
98 esac
99
100 dnl Now check the assembler. We have target-specific requirements here, so
101 dnl we couldn't do this any earlier.
102 AC_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])
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
122 foo:
123 adcd var, 0
124 ret
125 .data
126 var: .long 1
127 ]])],
128 [:], [mdw_cv_gnuish_as=no])
129 ;;
130 esac
131 AC_LANG_POP([CPPAS])])
132 AM_CONDITIONAL([GNUISH_AS], [test $mdw_cv_gnuish_as = yes])
133 if test $mdw_cv_gnuish_as = no; then CPUFAM=nil ABI=nil; fi
134
135 dnl A hairy macro used to set the `CPUFAM_...' and `ABI_...' variables. We
136 dnl basically need to do the same thing for the family and ABI, so it's worth
137 dnl some effort to hide the ugliness.
138 m4_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])
146 nil) ;;
147 *) AC_MSG_ERROR([BUG: unexpected $1 \`$1']) ;;
148 esac])
149
150 dnl Now that's out the way, we can explain what we're doing.
151 AC_MSG_CHECKING([CPU family and ABI])
152
153 dnl Figure out the target CPU family and ABI.
154 catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
155 catacomb_DEFINE_CPU_OR_ABI([CPUFAM], [2], [cpu],
156 [CPUFAM_], [Define if target CPU is \`$][2\'.])
157 catacomb_DEFINE_CPU_OR_ABI([ABI], [3], [abi],
158 [ABI_], [Define if target ABI is \`$][3\'.])
159
160 dnl Establish Automake conditions for things.
161 catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
162 m4_define([catacomb_COND_CPU],
163 [m4_define([_CPU], m4_translit([$2], [a-z], [A-Z]))
164 m4_define([_ABI], m4_translit([$3], [a-z], [A-Z]))
165 AM_CONDITIONAL([CPUABI_]_CPU[_]_ABI, [test x$CPUFAM/$ABI = x$2/$3])
166 m4_ifdef([catacomb_seen_cpu/$2], [],
167 [AM_CONDITIONAL([CPUFAM_]_CPU, [test x$CPUFAM = x$2])dnl
168 m4_define([catacomb_seen_cpu/$2], [t])])
169 m4_ifdef([catacomb_seen_abi/$3], [],
170 [AM_CONDITIONAL([ABI_]_ABI, [test x$ABI = x$3])dnl
171 m4_define([catacomb_seen_abi/$3], [t])])])
172 catacomb_CPU_FAMILIES([catacomb_COND_CPU])
173 AM_CONDITIONAL([KNOWN_CPUFAM], [test x$CPUFAM != xnil])
174
175 dnl Report on what we found.
176 case $CPUFAM in
177 nil) AC_MSG_RESULT([not supported]) ;;
178 *) AC_MSG_RESULT([$CPUFAM/$ABI]) ;;
179 esac
180
181 dnl--------------------------------------------------------------------------
182 dnl CPU-specific assembler features.
183
184 AC_LANG([CPPAS])
185
186 case $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
197 foo:
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 ;;
206 esac
207
208 : ${mdw_cv_as_armv8_crypto=no}
209 AM_CONDITIONAL([HAVE_AS_ARMV8_CRYPTO], [test $mdw_cv_as_armv8_crypto = yes])
210 if 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.])
213 fi
214
215 dnl--------------------------------------------------------------------------
216 dnl C programming environment.
217
218 AC_LANG([C])
219
220 CATACOMB_LIBS=
221
222 dnl Find out if we're cross-compiling.
223 AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
224
225 dnl Various standard types.
226 AC_CHECK_TYPE([pid_t], [],
227 [AC_DEFINE([pid_t], [int],
228 [Define to `int' if <sys/types.h> does not define])])
229 AC_TYPE_UID_T
230 AC_CHECK_TYPE([ssize_t], [],
231 [AC_DEFINE([ssize_t], [int],
232 [Define to `int' if <sys/types.h> does not define])])
233 AC_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 ])
239
240 dnl The maths library.
241 mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
242 AC_SEARCH_LIBS([log], [m])
243 AC_SEARCH_LIBS([sqrt], [m])
244 CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
245
246 dnl Logging is weird under Termux. Unfortunately, it involves macros, so we
247 dnl have to do this the hard way.
248 AC_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])
263 case $mdw_cv_syslog_lib in
264 none) LOGLIBS= ;;
265 *) LOGLIBS=$mdw_cv_syslog_lib ;;
266 esac
267 AC_SUBST([LOGLIBS])
268
269 dnl Find out whether very long integer types are available.
270 AC_CHECK_HEADERS([stdint.h])
271 AC_SUBST([have_stdint_h])
272 AX_C_LONG_LONG
273
274 dnl Some equipment wanted for checking CPU features at runtime.
275 AC_CHECK_HEADERS([asm/hwcap.h])
276 AC_CHECK_HEADERS([sys/auxv.h])
277 AC_CHECK_HEADERS([linux/auxvec.h])
278 AC_CHECK_FUNCS([getauxval])
279
280 dnl Find the bit lengths of the obvious integer types. This will be useful
281 dnl when deciding on a representation for multiprecision integers.
282 type_bits="" type_bits_sep=""
283 AC_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=", "])
287 catacomb_UINT_BITS([uchar], [unsigned char])
288 catacomb_UINT_BITS([ushort], [unsigned short])
289 catacomb_UINT_BITS([uint], [unsigned int])
290 catacomb_UINT_BITS([ulong], [unsigned long])
291 if test "$ac_cv_c_long_long" = "yes"; then
292 catacomb_UINT_BITS([ullong], [unsigned long long])
293 fi
294 if test "$ac_cv_header_stdint_h" = "yes"; then
295 catacomb_UINT_BITS([uintmax], [uintmax_t])
296 fi
297 AC_SUBST([type_bits])
298
299 dnl Determine the limits of common C integer types.
300 limits="" limits_sep=""
301 AC_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])
312 AC_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=", "])
320 catacomb_LIMIT([SCHAR], [SCHAR_MIN], [SCHAR_MAX])
321 catacomb_LIMIT([CHAR], [CHAR_MIN], [CHAR_MAX])
322 catacomb_LIMIT([UCHAR], [=0], [UCHAR_MAX])
323 catacomb_LIMIT([UINT8], [=0], [=0xff])
324 catacomb_LIMIT([SHRT], [SHRT_MIN], [SHRT_MAX])
325 catacomb_LIMIT([USHRT], [=0], [USHRT_MAX])
326 catacomb_LIMIT([UINT16], [=0], [=0xffff])
327 catacomb_LIMIT([INT], [INT_MIN], [INT_MAX])
328 catacomb_LIMIT([UINT], [=0], [UINT_MAX])
329 catacomb_LIMIT([LONG], [LONG_MIN], [LONG_MAX])
330 catacomb_LIMIT([ULONG], [=0], [ULONG_MAX])
331 catacomb_LIMIT([UINT32], [=0], [=0xffffffff])
332 if test "$ac_cv_c_long_long" = "yes"; then
333 catacomb_LIMIT([LLONG], [LLONG_MIN], [LLONG_MAX])
334 catacomb_LIMIT([ULLONG], [=0], [ULLONG_MAX])
335 fi
336 catacomb_LIMIT([SIZET], [=0], [~(size_t)0])
337 AC_SUBST([limits])
338
339 dnl Figure out other aspects of the implementation's arithmetic.
340 AC_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])])
347 case $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 ;;
352 esac
353
354 dnl Functions used for noise-gathering.
355 AC_CHECK_FUNCS([setgroups])
356 AC_CHECK_HEADERS([linux/random.h])
357 mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS
358 AC_SEARCH_LIBS([clock_gettime], [rt])
359 CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS
360 if test "$ac_cv_search_clock_gettime" != no; then
361 AC_DEFINE([HAVE_CLOCK_GETTIME], [1],
362 [Define if you have the \`clock_gettime' function.])
363 fi
364 AC_CHECK_FUNCS([getentropy])
365 AC_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 } };
371 jmp_buf j;
372 setitimer(ITIMER_REAL, &itv, 0);
373 sigsetjmp(j, 1);],
374 [catacomb_cv_freewheel=yes],
375 [catacomb_cv_freewheel=no])])
376 case $catacomb_cv_freewheel in
377 yes)
378 AC_DEFINE([USE_FREEWHEEL], [1],
379 [Define if you want to use the freewheel noise generator.])
380 ;;
381 esac
382
383 dnl Support for the passphrase pixie.
384 mdw_ORIG_LIBS=$LIBS
385 AC_SEARCH_LIBS([socket], [socket])
386 AC_SUBST([PIXIE_LIBS], [$LIBS])
387 LIBS=$mdw_ORIG_LIBS
388
389 dnl Memory locking support.
390 AC_CHECK_FUNCS([mlock])
391
392 dnl See if we can find Valgrind's header files.
393 AC_CHECK_HEADER([valgrind/memcheck.h],
394 AC_DEFINE([HAVE_VALGRIND_H], [1],
395 [Define if the Valgrind header files are available.])
396 [])
397
398 dnl Set the master libraries we need.
399 AC_SUBST([CATACOMB_LIBS])
400
401 dnl Necessary support libraries.
402 PKG_CHECK_MODULES([mLib], [mLib >= 2.2.2.1])
403 AM_CFLAGS="$AM_CFLAGS $mLib_CFLAGS"
404
405 dnl--------------------------------------------------------------------------
406 dnl Python.
407
408 dnl Make sure we have a suitable version.
409 AM_PATH_PYTHON([2.5])
410
411 dnl--------------------------------------------------------------------------
412 dnl Special debugging options.
413
414 AC_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
427 dnl--------------------------------------------------------------------------
428 dnl Produce output.
429
430 AC_CONFIG_HEADER([config/config.h])
431
432 AC_CONFIG_FILES(
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])
442 AC_OUTPUT
443
444 dnl----- That's all, folks --------------------------------------------------