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