]>
Commit | Line | Data |
---|---|---|
78cd96b1 CF |
1 | AC_PREREQ([2.60]) |
2 | AC_INIT([libsecp256k1],[0.1]) | |
6fac238f | 3 | AC_CONFIG_AUX_DIR([build-aux]) |
4 | AC_CONFIG_MACRO_DIR([build-aux/m4]) | |
78cd96b1 CF |
5 | AC_CANONICAL_HOST |
6 | AH_TOP([#ifndef LIBSECP256K1_CONFIG_H]) | |
7 | AH_TOP([#define LIBSECP256K1_CONFIG_H]) | |
f735446c | 8 | AH_BOTTOM([#endif /*LIBSECP256K1_CONFIG_H*/]) |
5190079e | 9 | AM_INIT_AUTOMAKE([foreign subdir-objects]) |
78cd96b1 CF |
10 | LT_INIT |
11 | ||
53628757 CF |
12 | dnl make the compilation flags quiet unless V=1 is used |
13 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) | |
14 | ||
78cd96b1 CF |
15 | PKG_PROG_PKG_CONFIG |
16 | ||
3ab1178d CF |
17 | AC_PATH_TOOL(AR, ar) |
18 | AC_PATH_TOOL(RANLIB, ranlib) | |
19 | AC_PATH_TOOL(STRIP, strip) | |
fbecc38a | 20 | AX_PROG_CC_FOR_BUILD |
3ab1178d | 21 | |
056ad310 | 22 | if test "x$CFLAGS" = "x"; then |
c88e2b8c PW |
23 | CFLAGS="-O3 -g" |
24 | fi | |
25 | ||
f735446c GM |
26 | AC_PROG_CC_C89 |
27 | if test x"$ac_cv_prog_cc_c89" = x"no"; then | |
28 | AC_MSG_ERROR([c89 compiler support required]) | |
78cd96b1 CF |
29 | fi |
30 | ||
31 | case $host in | |
32 | *mingw*) | |
33 | use_pkgconfig=no | |
34 | ;; | |
35 | *) | |
36 | use_pkgconfig=yes | |
37 | ;; | |
38 | esac | |
39 | ||
a86f241d | 40 | case $host_os in |
e2274c58 CF |
41 | *darwin*) |
42 | if test x$cross_compiling != xyes; then | |
43 | AC_PATH_PROG([BREW],brew,) | |
44 | if test x$BREW != x; then | |
45 | dnl These Homebrew packages may be keg-only, meaning that they won't be found | |
46 | dnl in expected paths because they may conflict with system files. Ask | |
47 | dnl Homebrew where each one is located, then adjust paths accordingly. | |
48 | ||
49 | openssl_prefix=`$BREW --prefix openssl 2>/dev/null` | |
50 | gmp_prefix=`$BREW --prefix gmp 2>/dev/null` | |
51 | if test x$openssl_prefix != x; then | |
52 | PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH" | |
53 | export PKG_CONFIG_PATH | |
54 | fi | |
55 | if test x$gmp_prefix != x; then | |
56 | GMP_CPPFLAGS="-I$gmp_prefix/include" | |
57 | GMP_LIBS="-L$gmp_prefix/lib" | |
58 | fi | |
59 | else | |
60 | AC_PATH_PROG([PORT],port,) | |
61 | dnl if homebrew isn't installed and macports is, add the macports default paths | |
62 | dnl as a last resort. | |
63 | if test x$PORT != x; then | |
64 | CPPFLAGS="$CPPFLAGS -isystem /opt/local/include" | |
65 | LDFLAGS="$LDFLAGS -L/opt/local/lib" | |
66 | fi | |
67 | fi | |
68 | fi | |
69 | ;; | |
a86f241d PD |
70 | esac |
71 | ||
a099073a GM |
72 | CFLAGS="$CFLAGS -W" |
73 | ||
7c3771dd | 74 | warn_CFLAGS="-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings" |
a099073a GM |
75 | saved_CFLAGS="$CFLAGS" |
76 | CFLAGS="$CFLAGS $warn_CFLAGS" | |
77 | AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}]) | |
78 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], | |
79 | [ AC_MSG_RESULT([yes]) ], | |
80 | [ AC_MSG_RESULT([no]) | |
81 | CFLAGS="$saved_CFLAGS" | |
82 | ]) | |
83 | ||
84 | ||
78cd96b1 | 85 | AC_ARG_ENABLE(benchmark, |
8336040f | 86 | AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is no)]), |
78cd96b1 | 87 | [use_benchmark=$enableval], |
8336040f | 88 | [use_benchmark=no]) |
78cd96b1 CF |
89 | |
90 | AC_ARG_ENABLE(tests, | |
91 | AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]), | |
92 | [use_tests=$enableval], | |
93 | [use_tests=yes]) | |
94 | ||
95 | AC_ARG_ENABLE(endomorphism, | |
0e9baf6f | 96 | AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]), |
78cd96b1 | 97 | [use_endomorphism=$enableval], |
0e9baf6f | 98 | [use_endomorphism=no]) |
fbecc38a TD |
99 | |
100 | AC_ARG_ENABLE(ecmult_static_precomputation, | |
a83bb480 | 101 | AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing (default is yes)]), |
fbecc38a | 102 | [use_ecmult_static_precomputation=$enableval], |
a83bb480 | 103 | [use_ecmult_static_precomputation=yes]) |
78cd96b1 | 104 | |
7277fd76 | 105 | AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto], |
0e9baf6f | 106 | [Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto]) |
78cd96b1 | 107 | |
1ba4a60a | 108 | AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto], |
78cd96b1 CF |
109 | [Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto]) |
110 | ||
1d52a8b1 PW |
111 | AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto], |
112 | [Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto]) | |
113 | ||
1ba4a60a PW |
114 | AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|no|auto] |
115 | [Specify assembly optimizations to use. Default is auto])],[req_asm=$withval], [req_asm=auto]) | |
116 | ||
78cd96b1 CF |
117 | AC_CHECK_TYPES([__int128]) |
118 | ||
1f46b006 CF |
119 | AC_MSG_CHECKING([for __builtin_expect]) |
120 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_expect(0,0);}]])], | |
121 | [ AC_MSG_RESULT([yes]);AC_DEFINE(HAVE_BUILTIN_EXPECT,1,[Define this symbol if __builtin_expect is available]) ], | |
122 | [ AC_MSG_RESULT([no]) | |
123 | ]) | |
1c7fa133 | 124 | |
1ba4a60a | 125 | if test x"$req_asm" = x"auto"; then |
0e9baf6f CF |
126 | SECP_64BIT_ASM_CHECK |
127 | if test x"$has_64bit_asm" = x"yes"; then | |
1ba4a60a PW |
128 | set_asm=x86_64 |
129 | fi | |
130 | if test x"$set_asm" = x; then | |
131 | set_asm=no | |
78cd96b1 | 132 | fi |
1ba4a60a PW |
133 | else |
134 | set_asm=$req_asm | |
135 | case $set_asm in | |
136 | x86_64) | |
137 | SECP_64BIT_ASM_CHECK | |
138 | if test x"$has_64bit_asm" != x"yes"; then | |
139 | AC_MSG_ERROR([x86_64 assembly optimization requested but not available]) | |
140 | fi | |
141 | ;; | |
142 | no) | |
143 | ;; | |
144 | *) | |
145 | AC_MSG_ERROR([invalid assembly optimization selection]) | |
146 | ;; | |
147 | esac | |
148 | fi | |
78cd96b1 | 149 | |
1ba4a60a PW |
150 | if test x"$req_field" = x"auto"; then |
151 | if test x"set_asm" = x"x86_64"; then | |
152 | set_field=64bit | |
153 | fi | |
78cd96b1 CF |
154 | if test x"$set_field" = x; then |
155 | SECP_INT128_CHECK | |
156 | if test x"$has_int128" = x"yes"; then | |
0e9baf6f | 157 | set_field=64bit |
78cd96b1 CF |
158 | fi |
159 | fi | |
78cd96b1 | 160 | if test x"$set_field" = x; then |
0e9baf6f | 161 | set_field=32bit |
78cd96b1 CF |
162 | fi |
163 | else | |
164 | set_field=$req_field | |
165 | case $set_field in | |
0e9baf6f | 166 | 64bit) |
1ba4a60a PW |
167 | if test x"$set_asm" != x"x86_64"; then |
168 | SECP_INT128_CHECK | |
169 | if test x"$has_int128" != x"yes"; then | |
170 | AC_MSG_ERROR([64bit field explicitly requested but neither __int128 support or x86_64 assembly available]) | |
171 | fi | |
172 | fi | |
78cd96b1 | 173 | ;; |
0e9baf6f | 174 | 32bit) |
78cd96b1 CF |
175 | ;; |
176 | *) | |
177 | AC_MSG_ERROR([invalid field implementation selection]) | |
178 | ;; | |
179 | esac | |
180 | fi | |
181 | ||
1d52a8b1 | 182 | if test x"$req_scalar" = x"auto"; then |
1ba4a60a PW |
183 | SECP_INT128_CHECK |
184 | if test x"$has_int128" = x"yes"; then | |
185 | set_scalar=64bit | |
1d52a8b1 PW |
186 | fi |
187 | if test x"$set_scalar" = x; then | |
188 | set_scalar=32bit | |
189 | fi | |
190 | else | |
191 | set_scalar=$req_scalar | |
192 | case $set_scalar in | |
193 | 64bit) | |
194 | SECP_INT128_CHECK | |
1ba4a60a PW |
195 | if test x"$has_int128" != x"yes"; then |
196 | AC_MSG_ERROR([64bit scalar explicitly requested but __int128 support not available]) | |
197 | fi | |
1d52a8b1 PW |
198 | ;; |
199 | 32bit) | |
200 | ;; | |
201 | *) | |
202 | AC_MSG_ERROR([invalid scalar implementation selected]) | |
203 | ;; | |
204 | esac | |
205 | fi | |
206 | ||
78cd96b1 CF |
207 | if test x"$req_bignum" = x"auto"; then |
208 | SECP_GMP_CHECK | |
209 | if test x"$has_gmp" = x"yes"; then | |
210 | set_bignum=gmp | |
211 | fi | |
212 | ||
78cd96b1 | 213 | if test x"$set_bignum" = x; then |
1ba4a60a | 214 | set_bignum=no |
78cd96b1 CF |
215 | fi |
216 | else | |
217 | set_bignum=$req_bignum | |
218 | case $set_bignum in | |
219 | gmp) | |
220 | SECP_GMP_CHECK | |
1ba4a60a PW |
221 | if test x"$has_gmp" != x"yes"; then |
222 | AC_MSG_ERROR([gmp bignum explicitly requested but libgmp not available]) | |
223 | fi | |
78cd96b1 | 224 | ;; |
1ba4a60a | 225 | no) |
78cd96b1 CF |
226 | ;; |
227 | *) | |
228 | AC_MSG_ERROR([invalid bignum implementation selection]) | |
229 | ;; | |
230 | esac | |
231 | fi | |
232 | ||
1ba4a60a PW |
233 | # select assembly optimization |
234 | case $set_asm in | |
235 | x86_64) | |
236 | AC_DEFINE(USE_ASM_X86_64, 1, [Define this symbol to enable x86_64 assembly optimizations]) | |
237 | ;; | |
238 | no) | |
239 | ;; | |
240 | *) | |
241 | AC_MSG_ERROR([invalid assembly optimizations]) | |
242 | ;; | |
243 | esac | |
244 | ||
78cd96b1 CF |
245 | # select field implementation |
246 | case $set_field in | |
0e9baf6f | 247 | 64bit) |
78cd96b1 CF |
248 | AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation]) |
249 | ;; | |
0e9baf6f | 250 | 32bit) |
78cd96b1 CF |
251 | AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation]) |
252 | ;; | |
253 | *) | |
254 | AC_MSG_ERROR([invalid field implementation]) | |
255 | ;; | |
256 | esac | |
257 | ||
258 | # select bignum implementation | |
259 | case $set_bignum in | |
260 | gmp) | |
597128d3 PW |
261 | AC_DEFINE(HAVE_LIBGMP, 1, [Define this symbol if libgmp is installed]) |
262 | AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation for num]) | |
d1502eb4 PW |
263 | AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the num-based field inverse implementation]) |
264 | AC_DEFINE(USE_SCALAR_INV_NUM, 1, [Define this symbol to use the num-based scalar inverse implementation]) | |
78cd96b1 | 265 | ;; |
1ba4a60a | 266 | no) |
597128d3 PW |
267 | AC_DEFINE(USE_NUM_NONE, 1, [Define this symbol to use no num implementation]) |
268 | AC_DEFINE(USE_FIELD_INV_BUILTIN, 1, [Define this symbol to use the native field inverse implementation]) | |
269 | AC_DEFINE(USE_SCALAR_INV_BUILTIN, 1, [Define this symbol to use the native scalar inverse implementation]) | |
270 | ;; | |
78cd96b1 CF |
271 | *) |
272 | AC_MSG_ERROR([invalid bignum implementation]) | |
273 | ;; | |
274 | esac | |
275 | ||
1d52a8b1 PW |
276 | #select scalar implementation |
277 | case $set_scalar in | |
278 | 64bit) | |
279 | AC_DEFINE(USE_SCALAR_4X64, 1, [Define this symbol to use the 4x64 scalar implementation]) | |
280 | ;; | |
281 | 32bit) | |
282 | AC_DEFINE(USE_SCALAR_8X32, 1, [Define this symbol to use the 8x32 scalar implementation]) | |
283 | ;; | |
284 | *) | |
285 | AC_MSG_ERROR([invalid scalar implementation]) | |
286 | ;; | |
287 | esac | |
288 | ||
78cd96b1 CF |
289 | if test x"$use_tests" = x"yes"; then |
290 | SECP_OPENSSL_CHECK | |
28ade27d | 291 | if test x"$has_openssl_ec" = x"yes"; then |
78cd96b1 CF |
292 | AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available]) |
293 | SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS" | |
294 | SECP_TEST_LIBS="$CRYPTO_LIBS" | |
295 | ||
296 | case $host in | |
297 | *mingw*) | |
298 | SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32" | |
299 | ;; | |
300 | esac | |
301 | ||
302 | fi | |
303 | fi | |
304 | ||
7277fd76 | 305 | if test x"$set_bignum" = x"gmp"; then |
78cd96b1 | 306 | SECP_LIBS="$SECP_LIBS $GMP_LIBS" |
e2274c58 | 307 | SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS" |
78cd96b1 CF |
308 | fi |
309 | ||
310 | if test x"$use_endomorphism" = x"yes"; then | |
c35ff1ea | 311 | AC_DEFINE(USE_ENDOMORPHISM, 1, [Define this symbol to use endomorphism optimization]) |
78cd96b1 CF |
312 | fi |
313 | ||
fbecc38a TD |
314 | if test x"$use_ecmult_static_precomputation" = x"yes"; then |
315 | AC_DEFINE(USE_ECMULT_STATIC_PRECOMPUTATION, 1, [Define this symbol to use a statically generated ecmult table]) | |
316 | fi | |
317 | ||
ae55e850 PW |
318 | AC_C_BIGENDIAN() |
319 | ||
1ba4a60a | 320 | AC_MSG_NOTICE([Using assembly optimizations: $set_asm]) |
78cd96b1 CF |
321 | AC_MSG_NOTICE([Using field implementation: $set_field]) |
322 | AC_MSG_NOTICE([Using bignum implementation: $set_bignum]) | |
1d52a8b1 | 323 | AC_MSG_NOTICE([Using scalar implementation: $set_scalar]) |
1ba4a60a | 324 | AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism]) |
78cd96b1 CF |
325 | |
326 | AC_CONFIG_HEADERS([src/libsecp256k1-config.h]) | |
c7ee71f7 | 327 | AC_CONFIG_FILES([Makefile libsecp256k1.pc]) |
78cd96b1 CF |
328 | AC_SUBST(SECP_INCLUDES) |
329 | AC_SUBST(SECP_LIBS) | |
330 | AC_SUBST(SECP_TEST_LIBS) | |
331 | AC_SUBST(SECP_TEST_INCLUDES) | |
78cd96b1 | 332 | AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"]) |
8336040f | 333 | AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"]) |
fbecc38a | 334 | AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$use_ecmult_static_precomputation" = x"yes"]) |
e2274c58 CF |
335 | |
336 | dnl make sure nothing new is exported so that we don't break the cache | |
337 | PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH" | |
338 | unset PKG_CONFIG_PATH | |
339 | PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP" | |
340 | ||
78cd96b1 | 341 | AC_OUTPUT |