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