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