rand/noise.c (noise_devrandom): Use new Linux system call `getrandom'.
[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
42
6adca914
MW
43AM_PROG_AS
44
ba6e6b64
MW
45AC_PROG_YACC
46
47AC_SUBST(AM_CFLAGS)
48
49dnl--------------------------------------------------------------------------
08e2be29
MW
50dnl Host-specific configuration.
51
ff1f7e22
MW
52AC_MSG_CHECKING([CPU family and ABI])
53
54dnl The table of CPU families and ABIs which we might support. Support is
55dnl not uniform: each dispatched function might or might not have an
56dnl implementation for any particular CPU/ABI combination.
08e2be29 57AC_DEFUN([catacomb_CPU_FAMILIES],
0f23f75f
MW
58 [$1([i[[3-6]]86,cygwin], [x86], [win])
59 $1([i[[3-6]]86,*], [x86], [sysv])
60 $1([x86_64,cygwin], [amd64], [win])
61bd904b 61 $1([x86_64,*], [amd64], [sysv])
2cbeb9a2
MW
62 $1([arm,*-gnueabi | arm,*-gnueabihf | dnl
63 armv*,*-gnueabi | armv*,*-gnueabihf], [armel], [gnueabi])])
ff1f7e22
MW
64
65dnl A utility to clear the `seen' flags, used so as to process each CPU or
66dnl ABI once.
67m4_define([catacomb_CLEAR_FLAGS],
68[m4_ifdef([catacomb_seen_cpu/$2],
69 [m4_undefine([catacomb_seen_cpu/$2])])dnl
70m4_ifdef([catacomb_seen_abi/$3],
71 [m4_undefine([catacomb_seen_abi/$3])])])
08e2be29 72
ff1f7e22
MW
73dnl Identify the current host.
74case $host_cpu,$host_os in
08e2be29 75 m4_define([catacomb_CPU_CASE],
ff1f7e22 76 [$1) CPUFAM=$2 ABI=$3 ;;
08e2be29
MW
77])
78 catacomb_CPU_FAMILIES([catacomb_CPU_CASE])
ff1f7e22
MW
79 *) CPUFAM=nil ABI=nil ;;
80esac
81
82dnl Figure out the current CPU.
83catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
84case $CPUFAM in
85 m4_define([catacomb_DEFINE_CPU],
86 [m4_ifdef([catacomb_seen_cpu/$2], [],
87 [$2)
88 AC_DEFINE([CPUFAM_]m4_translit([$2], [a-z], [A-Z]), [1],
89 [Define if host CPU family is \`$2\'.])
90 ;;m4_define([catacomb_seen_cpu/$2], [t])])])
91 catacomb_CPU_FAMILIES([catacomb_DEFINE_CPU])
92 nil) ;;
93 *) AC_MSG_ERROR([BUG: unexpected cpufam \`$CPUFAM']) ;;
94esac
95AC_SUBST([CPUFAM])
96
97dnl Figure out the current ABI.
98catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
99case $ABI in
100 m4_define([catacomb_DEFINE_ABI],
101 [m4_ifdef([catacomb_seen_abi/$3], [],
102 [$3)
103 AC_DEFINE([ABI_]m4_translit([$3], [a-z], [A-Z]), [1],
104 [Define if host ABI variant is \`$3\'.])
105 ;;m4_define([catacomb_seen_abi/$3], [t])])])
106 catacomb_CPU_FAMILIES([catacomb_DEFINE_ABI])
107 nil) ;;
108 *) AC_MSG_ERROR([BUG: unexpected ABI \`$ABI']) ;;
109esac
110AC_SUBST([ABI])
111
112dnl Establish Automake conditions for things.
113catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS])
114m4_define([catacomb_COND_CPU],
115[m4_define([_CPU], m4_translit([$2], [a-z], [A-Z]))
116m4_define([_ABI], m4_translit([$3], [a-z], [A-Z]))
117AM_CONDITIONAL([CPUABI_]_CPU[_]_ABI, [test x$CPUFAM/$ABI = x$2/$3])
118m4_ifdef([catacomb_seen_cpu/$2], [],
119[AM_CONDITIONAL([CPUFAM_]_CPU, [test x$CPUFAM = x$2])dnl
120m4_define([catacomb_seen_cpu/$2], [t])])
121m4_ifdef([catacomb_seen_abi/$3], [],
122[AM_CONDITIONAL([ABI_]_ABI, [test x$ABI = x$3])dnl
123m4_define([catacomb_seen_abi/$3], [t])])])
124catacomb_CPU_FAMILIES([catacomb_COND_CPU])
125AM_CONDITIONAL([KNOWN_CPUFAM], [test x$CPUFAM != xnil])
126
127dnl Report on what we found.
128case $CPUFAM in
129 nil) AC_MSG_RESULT([not supported]) ;;
130 *) AC_MSG_RESULT([$CPUFAM/$ABI]) ;;
08e2be29 131esac
08e2be29 132
a02a22d4
MW
133dnl Some equipment wanted for checking CPU features at runtime.
134AC_CHECK_HEADERS([asm/hwcap.h])
135AC_CHECK_HEADERS([sys/auxv.h])
136AC_CHECK_HEADERS([linux/auxvec.h])
137AC_CHECK_FUNCS([getauxval])
138
08e2be29 139dnl--------------------------------------------------------------------------
ba6e6b64
MW
140dnl C programming environment.
141
0f00dc4c
MW
142dnl Find out if we're cross-compiling.
143AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
144
ba6e6b64
MW
145dnl Various standard types.
146AC_CHECK_TYPE([pid_t], [int])
147AC_TYPE_UID_T
148AC_CHECK_TYPE([ssize_t], [int])
67ea7285 149AC_CHECK_TYPE([socklen_t], [int])
ba6e6b64
MW
150
151dnl The maths library.
1504e033 152mdw_ORIG_LIBS=$LIBS LIBS=
ba6e6b64
MW
153AC_SEARCH_LIBS([log], [m])
154AC_SEARCH_LIBS([sqrt], [m])
1504e033 155AC_SUBST([MATHLIBS], [$LIBS])
ba6e6b64
MW
156LIBS=$mdw_ORIG_LIBS
157
1c3d4cf5
MW
158dnl Find out whether very long integer types are available.
159AC_CHECK_HEADERS([stdint.h])
160AC_SUBST([have_stdint_h])
161AC_C_LONG_LONG
162
163dnl Find the bit lengths of the obvious integer types. This will be useful
164dnl when deciding on a representation for multiprecision integers.
165type_bits="" type_bits_sep=""
166AC_DEFUN([catacomb_UINT_BITS],
167 [mdw_UINT_BITS([$2], [$1])
168 type_bits="$type_bits$type_bits_sep('$1', $[]$1_bits)"
169 type_bits_sep=", "])
170catacomb_UINT_BITS([uchar], [unsigned char])
171catacomb_UINT_BITS([ushort], [unsigned short])
172catacomb_UINT_BITS([uint], [unsigned int])
173catacomb_UINT_BITS([ulong], [unsigned long])
174if test "$ac_cv_c_long_long" = "yes"; then
175 catacomb_UINT_BITS([ullong], [unsigned long long])
176fi
177if test "$ac_cv_header_stdint_h" = "yes"; then
178 catacomb_UINT_BITS([uintmax], [uintmax_t])
179fi
180AC_SUBST([type_bits])
181
182dnl Determine the limits of common C integer types.
183limits="" limits_sep=""
184AC_DEFUN([catacomb_COMPILE_TIME_CONSTANT],
185 [case "$2" in
186 =*)
187 $1="$2"; $1=${$1#=}
188 ;;
189 *)
190 AC_CACHE_CHECK([compile-time value of $2], [mdw_cv_constant_$3],
191 [mdw_PROBE_CONSTANT([mdw_cv_constant_$3], [$2], [$4])])
192 $1=$mdw_cv_constant_$3
193 ;;
194 esac])
195AC_DEFUN([catacomb_LIMIT],
196[catacomb_COMPILE_TIME_CONSTANT([lo], [$2], [$1_min],
197[#include <limits.h>
198#include <stddef.h>])
199 catacomb_COMPILE_TIME_CONSTANT([hi], [$3], [$1_max],
200[#include <limits.h>
201#include <stddef.h>])
202 limits="$limits$limits_sep('$1', $lo, $hi)" limits_sep=", "])
203catacomb_LIMIT([SCHAR], [SCHAR_MIN], [SCHAR_MAX])
204catacomb_LIMIT([CHAR], [CHAR_MIN], [CHAR_MAX])
205catacomb_LIMIT([UCHAR], [=0], [UCHAR_MAX])
206catacomb_LIMIT([UINT8], [=0], [=0xff])
207catacomb_LIMIT([SHRT], [SHRT_MIN], [SHRT_MAX])
208catacomb_LIMIT([USHRT], [=0], [USHRT_MAX])
209catacomb_LIMIT([UINT16], [=0], [=0xffff])
210catacomb_LIMIT([INT], [INT_MIN], [INT_MAX])
211catacomb_LIMIT([UINT], [=0], [UINT_MAX])
212catacomb_LIMIT([LONG], [LONG_MIN], [LONG_MAX])
213catacomb_LIMIT([ULONG], [=0], [ULONG_MAX])
214catacomb_LIMIT([UINT32], [=0], [=0xffffffff])
215if test "$ac_cv_c_long_long" = "yes"; then
216 catacomb_LIMIT([LLONG], [LLONG_MIN], [LLONG_MAX])
217 catacomb_LIMIT([ULLONG], [=0], [ULLONG_MAX])
218fi
219catacomb_LIMIT([SIZET], [=0], [~(size_t)0])
220AC_SUBST([limits])
221
ba6e6b64
MW
222dnl Functions used for noise-gathering.
223AC_CHECK_FUNCS([setgroups])
baf5b59c 224AC_CHECK_HEADERS([linux/random.h])
ba6e6b64
MW
225AC_CACHE_CHECK([whether the freewheel noise generator will work],
226 [catacomb_cv_freewheel],
227[AC_TRY_LINK(
228[#include <setjmp.h>
229#include <sys/time.h>],
230[struct itimerval itv = { { 0, 0 }, { 0, 5000 } };
231jmp_buf j;
232setitimer(ITIMER_REAL, &itv, 0);
f6ca8103 233sigsetjmp(j, 1);],
ba6e6b64
MW
234[catacomb_cv_freewheel=yes],
235[catacomb_cv_freewheel=no])])
236case $catacomb_cv_freewheel in
237 yes)
238 AC_DEFINE([USE_FREEWHEEL], [1],
239 [Define if you want to use the freewheel noise generator.])
240 ;;
241esac
242
243dnl Support for the passphrase pixie.
244mdw_ORIG_LIBS=$LIBS
245AC_SEARCH_LIBS([socket], [socket])
246AC_SUBST([PIXIE_LIBS], [$LIBS])
247LIBS=$mdw_ORIG_LIBS
248
249dnl Memory locking support.
250AC_CHECK_FUNCS([mlock])
251
252dnl Necessary support libraries.
a1acefec 253PKG_CHECK_MODULES([mLib], [mLib >= 2.2.2.1])
ba6e6b64
MW
254AM_CFLAGS="$AM_CFLAGS $mLib_CFLAGS"
255
256dnl--------------------------------------------------------------------------
257dnl Python.
258
259dnl Make sure we have a suitable version.
260AM_PATH_PYTHON([2.5])
261
262dnl--------------------------------------------------------------------------
263dnl Special debugging options.
264
265AC_ARG_ENABLE([mpw],
266 [AS_HELP_STRING([--enable-mpw], [force small-width mp digits])],
267 [case "$enableval" in
268 y*|t*|short)
269 AC_DEFINE([FORCE_MPW_SHORT], [1],
270 [Define to force small-width mp digits.])
271 ;;
272 cussid)
273 AC_DEFINE([FORCE_MPW_CUSSID], [1],
274 [Define to force strange-width mp digits.])
275 ;;
276 esac])
277
278dnl--------------------------------------------------------------------------
279dnl Produce output.
280
281AC_CONFIG_HEADER([config/config.h])
282
283AC_CONFIG_FILES(
0f00dc4c
MW
284 [Makefile]
285 [base/Makefile]
286 [key/Makefile]
287 [math/Makefile]
288 [misc/Makefile]
289 [pub/Makefile]
290 [rand/Makefile]
291 [symm/Makefile]
292 [progs/Makefile])
ba6e6b64
MW
293AC_OUTPUT
294
295dnl----- That's all, folks --------------------------------------------------