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