Commit | Line | Data |
---|---|---|
ba6e6b64 MW |
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]) | |
1c8e76bd | 34 | AM_INIT_AUTOMAKE([foreign parallel-tests color-tests subdir-objects]) |
08e2be29 | 35 | AC_CANONICAL_HOST |
ba6e6b64 MW |
36 | mdw_SILENT_RULES |
37 | ||
38 | AC_PROG_CC | |
39 | AX_CFLAGS_WARN_ALL | |
40 | AM_PROG_LIBTOOL | |
41 | mdw_LIBTOOL_VERSION_INFO | |
42 | ||
6adca914 MW |
43 | AM_PROG_AS |
44 | ||
ba6e6b64 MW |
45 | AC_PROG_YACC |
46 | ||
47 | AC_SUBST(AM_CFLAGS) | |
48 | ||
49 | dnl-------------------------------------------------------------------------- | |
08e2be29 MW |
50 | dnl Host-specific configuration. |
51 | ||
ff1f7e22 MW |
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. | |
08e2be29 | 57 | AC_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 | |
65 | dnl A utility to clear the `seen' flags, used so as to process each CPU or | |
66 | dnl ABI once. | |
67 | m4_define([catacomb_CLEAR_FLAGS], | |
68 | [m4_ifdef([catacomb_seen_cpu/$2], | |
69 | [m4_undefine([catacomb_seen_cpu/$2])])dnl | |
70 | m4_ifdef([catacomb_seen_abi/$3], | |
71 | [m4_undefine([catacomb_seen_abi/$3])])]) | |
08e2be29 | 72 | |
ff1f7e22 MW |
73 | dnl Identify the current host. |
74 | case $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 ;; |
80 | esac | |
81 | ||
82 | dnl Figure out the current CPU. | |
83 | catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS]) | |
84 | case $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']) ;; | |
94 | esac | |
95 | AC_SUBST([CPUFAM]) | |
96 | ||
97 | dnl Figure out the current ABI. | |
98 | catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS]) | |
99 | case $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']) ;; | |
109 | esac | |
110 | AC_SUBST([ABI]) | |
111 | ||
112 | dnl Establish Automake conditions for things. | |
113 | catacomb_CPU_FAMILIES([catacomb_CLEAR_FLAGS]) | |
114 | m4_define([catacomb_COND_CPU], | |
115 | [m4_define([_CPU], m4_translit([$2], [a-z], [A-Z])) | |
116 | m4_define([_ABI], m4_translit([$3], [a-z], [A-Z])) | |
117 | AM_CONDITIONAL([CPUABI_]_CPU[_]_ABI, [test x$CPUFAM/$ABI = x$2/$3]) | |
118 | m4_ifdef([catacomb_seen_cpu/$2], [], | |
119 | [AM_CONDITIONAL([CPUFAM_]_CPU, [test x$CPUFAM = x$2])dnl | |
120 | m4_define([catacomb_seen_cpu/$2], [t])]) | |
121 | m4_ifdef([catacomb_seen_abi/$3], [], | |
122 | [AM_CONDITIONAL([ABI_]_ABI, [test x$ABI = x$3])dnl | |
123 | m4_define([catacomb_seen_abi/$3], [t])])]) | |
124 | catacomb_CPU_FAMILIES([catacomb_COND_CPU]) | |
125 | AM_CONDITIONAL([KNOWN_CPUFAM], [test x$CPUFAM != xnil]) | |
126 | ||
127 | dnl Report on what we found. | |
128 | case $CPUFAM in | |
129 | nil) AC_MSG_RESULT([not supported]) ;; | |
130 | *) AC_MSG_RESULT([$CPUFAM/$ABI]) ;; | |
08e2be29 | 131 | esac |
08e2be29 MW |
132 | |
133 | dnl-------------------------------------------------------------------------- | |
ba6e6b64 MW |
134 | dnl C programming environment. |
135 | ||
fedd2209 MW |
136 | AC_LANG([C]) |
137 | ||
02fe0bac MW |
138 | CATACOMB_LIBS= |
139 | ||
0f00dc4c MW |
140 | dnl Find out if we're cross-compiling. |
141 | AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes]) | |
142 | ||
ba6e6b64 MW |
143 | dnl Various standard types. |
144 | AC_CHECK_TYPE([pid_t], [int]) | |
145 | AC_TYPE_UID_T | |
146 | AC_CHECK_TYPE([ssize_t], [int]) | |
67ea7285 | 147 | AC_CHECK_TYPE([socklen_t], [int]) |
ba6e6b64 MW |
148 | |
149 | dnl The maths library. | |
1504e033 | 150 | mdw_ORIG_LIBS=$LIBS LIBS= |
ba6e6b64 MW |
151 | AC_SEARCH_LIBS([log], [m]) |
152 | AC_SEARCH_LIBS([sqrt], [m]) | |
1504e033 | 153 | AC_SUBST([MATHLIBS], [$LIBS]) |
ba6e6b64 MW |
154 | LIBS=$mdw_ORIG_LIBS |
155 | ||
1c3d4cf5 MW |
156 | dnl Find out whether very long integer types are available. |
157 | AC_CHECK_HEADERS([stdint.h]) | |
158 | AC_SUBST([have_stdint_h]) | |
159 | AC_C_LONG_LONG | |
160 | ||
fedd2209 MW |
161 | dnl Some equipment wanted for checking CPU features at runtime. |
162 | AC_CHECK_HEADERS([asm/hwcap.h]) | |
163 | AC_CHECK_HEADERS([sys/auxv.h]) | |
164 | AC_CHECK_HEADERS([linux/auxvec.h]) | |
165 | AC_CHECK_FUNCS([getauxval]) | |
166 | ||
1c3d4cf5 MW |
167 | dnl Find the bit lengths of the obvious integer types. This will be useful |
168 | dnl when deciding on a representation for multiprecision integers. | |
169 | type_bits="" type_bits_sep="" | |
170 | AC_DEFUN([catacomb_UINT_BITS], | |
171 | [mdw_UINT_BITS([$2], [$1]) | |
172 | type_bits="$type_bits$type_bits_sep('$1', $[]$1_bits)" | |
173 | type_bits_sep=", "]) | |
174 | catacomb_UINT_BITS([uchar], [unsigned char]) | |
175 | catacomb_UINT_BITS([ushort], [unsigned short]) | |
176 | catacomb_UINT_BITS([uint], [unsigned int]) | |
177 | catacomb_UINT_BITS([ulong], [unsigned long]) | |
178 | if test "$ac_cv_c_long_long" = "yes"; then | |
179 | catacomb_UINT_BITS([ullong], [unsigned long long]) | |
180 | fi | |
181 | if test "$ac_cv_header_stdint_h" = "yes"; then | |
182 | catacomb_UINT_BITS([uintmax], [uintmax_t]) | |
183 | fi | |
184 | AC_SUBST([type_bits]) | |
185 | ||
186 | dnl Determine the limits of common C integer types. | |
187 | limits="" limits_sep="" | |
188 | AC_DEFUN([catacomb_COMPILE_TIME_CONSTANT], | |
189 | [case "$2" in | |
190 | =*) | |
191 | $1="$2"; $1=${$1#=} | |
192 | ;; | |
193 | *) | |
194 | AC_CACHE_CHECK([compile-time value of $2], [mdw_cv_constant_$3], | |
195 | [mdw_PROBE_CONSTANT([mdw_cv_constant_$3], [$2], [$4])]) | |
196 | $1=$mdw_cv_constant_$3 | |
197 | ;; | |
198 | esac]) | |
199 | AC_DEFUN([catacomb_LIMIT], | |
200 | [catacomb_COMPILE_TIME_CONSTANT([lo], [$2], [$1_min], | |
201 | [#include <limits.h> | |
202 | #include <stddef.h>]) | |
203 | catacomb_COMPILE_TIME_CONSTANT([hi], [$3], [$1_max], | |
204 | [#include <limits.h> | |
205 | #include <stddef.h>]) | |
206 | limits="$limits$limits_sep('$1', $lo, $hi)" limits_sep=", "]) | |
207 | catacomb_LIMIT([SCHAR], [SCHAR_MIN], [SCHAR_MAX]) | |
208 | catacomb_LIMIT([CHAR], [CHAR_MIN], [CHAR_MAX]) | |
209 | catacomb_LIMIT([UCHAR], [=0], [UCHAR_MAX]) | |
210 | catacomb_LIMIT([UINT8], [=0], [=0xff]) | |
211 | catacomb_LIMIT([SHRT], [SHRT_MIN], [SHRT_MAX]) | |
212 | catacomb_LIMIT([USHRT], [=0], [USHRT_MAX]) | |
213 | catacomb_LIMIT([UINT16], [=0], [=0xffff]) | |
214 | catacomb_LIMIT([INT], [INT_MIN], [INT_MAX]) | |
215 | catacomb_LIMIT([UINT], [=0], [UINT_MAX]) | |
216 | catacomb_LIMIT([LONG], [LONG_MIN], [LONG_MAX]) | |
217 | catacomb_LIMIT([ULONG], [=0], [ULONG_MAX]) | |
218 | catacomb_LIMIT([UINT32], [=0], [=0xffffffff]) | |
219 | if test "$ac_cv_c_long_long" = "yes"; then | |
220 | catacomb_LIMIT([LLONG], [LLONG_MIN], [LLONG_MAX]) | |
221 | catacomb_LIMIT([ULLONG], [=0], [ULLONG_MAX]) | |
222 | fi | |
223 | catacomb_LIMIT([SIZET], [=0], [~(size_t)0]) | |
224 | AC_SUBST([limits]) | |
225 | ||
ba6e6b64 MW |
226 | dnl Functions used for noise-gathering. |
227 | AC_CHECK_FUNCS([setgroups]) | |
baf5b59c | 228 | AC_CHECK_HEADERS([linux/random.h]) |
8039afaf MW |
229 | mdw_ORIG_LIBS=$LIBS LIBS=$CATACOMB_LIBS |
230 | AC_SEARCH_LIBS([clock_gettime], [rt]) | |
231 | CATACOMB_LIBS=$LIBS LIBS=$mdw_ORIG_LIBS | |
fe54dc64 | 232 | if test "$ac_cv_search_clock_gettime" != no; then |
8039afaf MW |
233 | AC_DEFINE([HAVE_CLOCK_GETTIME], [1], |
234 | [Define if you have the \`clock_gettime' function.]) | |
235 | fi | |
6d4416cc | 236 | AC_CHECK_FUNCS([getentropy]) |
ba6e6b64 MW |
237 | AC_CACHE_CHECK([whether the freewheel noise generator will work], |
238 | [catacomb_cv_freewheel], | |
239 | [AC_TRY_LINK( | |
240 | [#include <setjmp.h> | |
241 | #include <sys/time.h>], | |
242 | [struct itimerval itv = { { 0, 0 }, { 0, 5000 } }; | |
243 | jmp_buf j; | |
244 | setitimer(ITIMER_REAL, &itv, 0); | |
f6ca8103 | 245 | sigsetjmp(j, 1);], |
ba6e6b64 MW |
246 | [catacomb_cv_freewheel=yes], |
247 | [catacomb_cv_freewheel=no])]) | |
248 | case $catacomb_cv_freewheel in | |
249 | yes) | |
250 | AC_DEFINE([USE_FREEWHEEL], [1], | |
251 | [Define if you want to use the freewheel noise generator.]) | |
252 | ;; | |
253 | esac | |
254 | ||
255 | dnl Support for the passphrase pixie. | |
256 | mdw_ORIG_LIBS=$LIBS | |
257 | AC_SEARCH_LIBS([socket], [socket]) | |
258 | AC_SUBST([PIXIE_LIBS], [$LIBS]) | |
259 | LIBS=$mdw_ORIG_LIBS | |
260 | ||
261 | dnl Memory locking support. | |
262 | AC_CHECK_FUNCS([mlock]) | |
263 | ||
02fe0bac MW |
264 | dnl Set the master libraries we need. |
265 | AC_SUBST([CATACOMB_LIBS]) | |
266 | ||
ba6e6b64 | 267 | dnl Necessary support libraries. |
a1acefec | 268 | PKG_CHECK_MODULES([mLib], [mLib >= 2.2.2.1]) |
ba6e6b64 MW |
269 | AM_CFLAGS="$AM_CFLAGS $mLib_CFLAGS" |
270 | ||
271 | dnl-------------------------------------------------------------------------- | |
272 | dnl Python. | |
273 | ||
274 | dnl Make sure we have a suitable version. | |
275 | AM_PATH_PYTHON([2.5]) | |
276 | ||
277 | dnl-------------------------------------------------------------------------- | |
278 | dnl Special debugging options. | |
279 | ||
280 | AC_ARG_ENABLE([mpw], | |
281 | [AS_HELP_STRING([--enable-mpw], [force small-width mp digits])], | |
282 | [case "$enableval" in | |
283 | y*|t*|short) | |
284 | AC_DEFINE([FORCE_MPW_SHORT], [1], | |
285 | [Define to force small-width mp digits.]) | |
286 | ;; | |
287 | cussid) | |
288 | AC_DEFINE([FORCE_MPW_CUSSID], [1], | |
289 | [Define to force strange-width mp digits.]) | |
290 | ;; | |
291 | esac]) | |
292 | ||
293 | dnl-------------------------------------------------------------------------- | |
294 | dnl Produce output. | |
295 | ||
296 | AC_CONFIG_HEADER([config/config.h]) | |
297 | ||
298 | AC_CONFIG_FILES( | |
0f00dc4c MW |
299 | [Makefile] |
300 | [base/Makefile] | |
301 | [key/Makefile] | |
302 | [math/Makefile] | |
303 | [misc/Makefile] | |
304 | [pub/Makefile] | |
305 | [rand/Makefile] | |
306 | [symm/Makefile] | |
307 | [progs/Makefile]) | |
ba6e6b64 MW |
308 | AC_OUTPUT |
309 | ||
310 | dnl----- That's all, folks -------------------------------------------------- |