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