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