-
Notifications
You must be signed in to change notification settings - Fork 53
/
configure.ac
389 lines (346 loc) · 8.5 KB
/
configure.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# Package version (semver)
define(MAJOR, 2)
define(MINOR, 99)
define(PATCH, 0)
# Shared library version
# see: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
define(CURRENT, 2)
define(REVISION, 0)
define(AGE, 0)
AC_PREREQ([2.57])
AC_INIT([hnsd], m4_join([.], MAJOR, MINOR, PATCH), [[email protected]])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
AC_SUBST(LINKER_VERSION, m4_join([:], CURRENT, REVISION, AGE))
AC_CANONICAL_HOST
AC_ENABLE_SHARED
AC_ENABLE_STATIC
AC_PROG_CXX
AC_PROG_CC
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_PROG_LIBTOOL
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
LT_INIT
AH_TOP([#ifndef _HSK_CONFIG_H])
AH_TOP([#define _HSK_CONFIG_H])
AH_BOTTOM([#endif /* _HSK_CONFIG_H */])
AC_CONFIG_SRCDIR([src/bio.h])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_SUBDIRS([uv])
dnl PKG_PROG_PKG_CONFIG
AC_C_BIGENDIAN(
[AC_DEFINE(HSK_BIG_ENDIAN, 1, [define if built for a big endian system])],
,
[AC_MSG_WARN([falling back to little endian])]
)
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_INT8_T
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_SYS_LARGEFILE
AC_CHECK_FUNCS([ \
memset \
strcasecmp \
strdup \
strchr \
getrandom \
arc4random \
random \
])
AC_CHECK_HEADERS([ \
arpa/inet.h \
fcntl.h \
limits.h \
netinet/in.h \
stddef.h \
stdint.h \
stdlib.h \
string.h \
strings.h \
sys/random.h \
unistd.h \
])
AC_ARG_WITH([network],
[AS_HELP_STRING(
[--with-network=main|testnet|regtest|simnet],
[Specify network. Default is main.]
)],
[hsk_network=$withval],
[hsk_network=main])
case $hsk_network in
main | yes)
AC_DEFINE(HSK_NETWORK, HSK_MAIN,
[Define this symbol to choose a network])
;;
testnet)
AC_DEFINE(HSK_NETWORK, HSK_TESTNET,
[Define this symbol to choose a network])
;;
regtest)
AC_DEFINE(HSK_NETWORK, HSK_REGTEST,
[Define this symbol to choose a network])
;;
simnet)
AC_DEFINE(HSK_NETWORK, HSK_SIMNET,
[Define this symbol to choose a network])
;;
*)
AC_MSG_ERROR([invalid network])
;;
esac
dnl
dnl Secp256k1
dnl
AX_PROG_CC_FOR_BUILD
AM_PROG_CC_C_O
AC_PROG_CC_C89
if test x"$ac_cv_prog_cc_c89" = x"no"; then
AC_MSG_ERROR([c89 compiler support required])
fi
AM_PROG_AS
AC_ARG_ENABLE(endomorphism,
AS_HELP_STRING(
[--enable-endomorphism],
[Enable endomorphism. Default is yes.)]
),
[use_endomorphism=$enableval],
[use_endomorphism=no])
AC_ARG_ENABLE(ecmult_static_precomputation,
AS_HELP_STRING(
[--enable-ecmult-static-precomputation],
[Enable precomputed ecmult table for signing. Default is yes.)]
),
[use_precomp=$enableval],
[use_precomp=yes])
AC_ARG_WITH([field],
[AS_HELP_STRING(
[--with-field=64bit|32bit|auto],
[Specify Field Implementation. Default is auto.]
)],
[req_field=$withval],
[req_field=auto])
AC_ARG_WITH([scalar],
[AS_HELP_STRING(
[--with-scalar=64bit|32bit|auto],
[Specify scalar implementation. Default is auto.]
)],
[req_scalar=$withval],
[req_scalar=auto])
AC_ARG_WITH([asm],
[AS_HELP_STRING(
[--with-asm=x86_64|arm|no|auto]
[Specify assembly optimizations to use. Default is auto.]
)],
[req_asm=$withval],
[req_asm=auto])
AC_ARG_WITH([unbound],
[AS_HELP_STRING(
[--with-unbound=path]
[Use libunbound installed at path. Default is to search system paths.]
)],
[libunbound_path=$withval],
[libunbound_path=yes])
AC_ARG_WITH([sanitizers],
[AS_HELP_STRING(
[--with-sanitizers]
[comma separated list of extra sanitizers to build with (default is none)]
)],
[SANITIZER_FLAGS="-g -fsanitize=$withval"])
AC_SUBST(SANITIZER_FLAGS, ${SANITIZER_FLAGS})
AC_CHECK_TYPES([__int128])
AC_MSG_CHECKING([for __builtin_expect])
AC_COMPILE_IFELSE(
[AC_LANG_SOURCE([[void myfunc() {__builtin_expect(0,0);}]])],
[
AC_MSG_RESULT([yes]);
AC_DEFINE(HAVE_BUILTIN_EXPECT, 1,
[Define this symbol if __builtin_expect is available])
],
[ AC_MSG_RESULT([no]) ]
)
if test x"$req_asm" = x"auto"; then
SECP_64BIT_ASM_CHECK
if test x"$has_64bit_asm" = x"yes"; then
set_asm=x86_64
fi
if test x"$set_asm" = x; then
set_asm=no
fi
else
set_asm=$req_asm
case $set_asm in
x86_64)
SECP_64BIT_ASM_CHECK
if test x"$has_64bit_asm" != x"yes"; then
AC_MSG_ERROR([x86_64 assembly optimization requested but not available])
fi
;;
arm)
;;
no)
;;
*)
AC_MSG_ERROR([invalid assembly optimization selection])
;;
esac
fi
if test x"$req_field" = x"auto"; then
if test x"set_asm" = x"x86_64"; then
set_field=64bit
fi
if test x"$set_field" = x; then
SECP_INT128_CHECK
if test x"$has_int128" = x"yes"; then
set_field=64bit
fi
fi
if test x"$set_field" = x; then
set_field=32bit
fi
else
set_field=$req_field
case $set_field in
64bit)
if test x"$set_asm" != x"x86_64"; then
SECP_INT128_CHECK
if test x"$has_int128" != x"yes"; then
AC_MSG_ERROR([Neither __int128 support or x86_64 assembly available])
fi
fi
;;
32bit)
;;
*)
AC_MSG_ERROR([invalid field implementation selection])
;;
esac
fi
if test x"$req_scalar" = x"auto"; then
SECP_INT128_CHECK
if test x"$has_int128" = x"yes"; then
set_scalar=64bit
fi
if test x"$set_scalar" = x; then
set_scalar=32bit
fi
else
set_scalar=$req_scalar
case $set_scalar in
64bit)
SECP_INT128_CHECK
if test x"$has_int128" != x"yes"; then
AC_MSG_ERROR([__int128 support not available])
fi
;;
32bit)
;;
*)
AC_MSG_ERROR([invalid scalar implementation selected])
;;
esac
fi
use_external_asm=no
case $set_asm in
x86_64)
AC_DEFINE(HSK_USE_ASM_X86_64, 1,
[Define this symbol to enable x86_64 assembly optimizations])
;;
arm)
use_external_asm=yes
;;
no)
;;
*)
AC_MSG_ERROR([invalid assembly optimizations])
;;
esac
case $set_field in
64bit)
AC_DEFINE(HSK_USE_FIELD_5X52, 1,
[Define this symbol to use the FIELD_5X52 implementation])
;;
32bit)
AC_DEFINE(HSK_USE_FIELD_10X26, 1,
[Define this symbol to use the FIELD_10X26 implementation])
;;
*)
AC_MSG_ERROR([invalid field implementation])
;;
esac
case $set_scalar in
64bit)
AC_DEFINE(HSK_USE_SCALAR_4X64, 1,
[Define this symbol to use the 4x64 scalar implementation])
;;
32bit)
AC_DEFINE(HSK_USE_SCALAR_8X32, 1,
[Define this symbol to use the 8x32 scalar implementation])
;;
*)
AC_MSG_ERROR([invalid scalar implementation])
;;
esac
if test x"$use_endomorphism" = x"yes"; then
AC_DEFINE(HSK_USE_ENDOMORPHISM, 1,
[Define this symbol to use endomorphism optimization])
fi
if test x"$use_precomp" = x"yes"; then
AC_DEFINE(HSK_USE_ECMULT_STATIC_PRECOMPUTATION, 1,
[Define this symbol to use a statically generated ecmult table])
fi
if test x"$use_external_asm" = x"yes"; then
AC_DEFINE(HSK_USE_EXTERNAL_ASM, 1,
[Define this symbol if an external assembly implementation is used])
fi
dnl Find libunbound, and define LIB_UNBOUND/INC_UNBOUND for hnsd.
dnl Don't add these to the default libs/includes, they're not needed by the
dnl other targets.
case $libunbound_path in
no)
AC_MSG_ERROR([libunbound is required])
;;
yes)
AC_CHECK_LIB(unbound, ub_ctx_create, LIB_UNBOUND="-lunbound",
AC_MSG_ERROR([Unable to find libunbound]))
AC_CHECK_HEADER(unbound.h, INC_UNBOUND="",
AC_MSG_ERROR([Unable to found unbound.h]))
;;
*)
LIB_UNBOUND="-L${libunbound_path}/lib -lunbound"
INC_UNBOUND="-I${libunbound_path}/include"
;;
esac
AC_SUBST(LIB_UNBOUND, ${LIB_UNBOUND})
AC_SUBST(INC_UNBOUND, ${INC_UNBOUND})
dnl Platform-specific libraries
case "${host_os}" in
mingw*)
AC_SUBST(LIB_WINBCRYPT, "-lbcrypt")
;;
esac
AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism])
AC_MSG_NOTICE([Using static precomputation: $use_precomp])
AC_MSG_NOTICE([Using assembly optimizations: $set_asm])
AC_MSG_NOTICE([Using field implementation: $set_field])
AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
AC_MSG_NOTICE([Linker flags for libunbound: $LIB_UNBOUND])
AC_MSG_NOTICE([Compiler flags for libunbound: $INC_UNBOUND])
AM_CONDITIONAL(
[HSK_USE_ECMULT_STATIC_PRECOMPUTATION],
[test x"$use_precomp" = x"yes"])
AM_CONDITIONAL([HSK_USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
AM_CONDITIONAL([HSK_USE_ASM_ARM], [test x"$set_asm" = x"arm"])
dnl
dnl /Secp256k1
dnl
AC_OUTPUT