]> Git Repo - secp256k1.git/blob - configure.ac
Merge pull request #120
[secp256k1.git] / configure.ac
1 AC_PREREQ([2.60])
2 AC_INIT([libsecp256k1],[0.1])
3 AC_CONFIG_AUX_DIR([build-aux])
4 AC_CONFIG_MACRO_DIR([build-aux/m4])
5 AC_CANONICAL_HOST
6 AH_TOP([#ifndef LIBSECP256K1_CONFIG_H])
7 AH_TOP([#define LIBSECP256K1_CONFIG_H])
8 AH_BOTTOM([#endif //LIBSECP256K1_CONFIG_H])
9 AM_INIT_AUTOMAKE([foreign])
10 LT_INIT
11
12 dnl make the compilation flags quiet unless V=1 is used
13 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
14
15 PKG_PROG_PKG_CONFIG
16
17 AC_PATH_TOOL(AR, ar)
18 AC_PATH_TOOL(RANLIB, ranlib)
19 AC_PATH_TOOL(STRIP, strip)
20
21 AC_PROG_CC_C99
22 if test x"$ac_cv_prog_cc_c99" == x"no"; then
23   AC_MSG_ERROR([c99 compiler support required])
24 fi
25
26 case $host in
27   *mingw*)
28      use_pkgconfig=no
29      ;;
30    *)
31      use_pkgconfig=yes
32      ;;
33 esac
34
35 case $host_os in
36   *darwin*)
37      if  test x$cross_compiling != xyes; then
38        AC_PATH_PROG([BREW],brew,)
39        if test x$BREW != x; then
40          dnl These Homebrew packages may be keg-only, meaning that they won't be found
41          dnl in expected paths because they may conflict with system files. Ask
42          dnl Homebrew where each one is located, then adjust paths accordingly.
43
44          openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
45          gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
46          if test x$openssl_prefix != x; then
47            PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
48            export PKG_CONFIG_PATH
49          fi
50          if test x$gmp_prefix != x; then
51            GMP_CPPFLAGS="-I$gmp_prefix/include"
52            GMP_LIBS="-L$gmp_prefix/lib"
53          fi
54        else
55          AC_PATH_PROG([PORT],port,)
56          dnl if homebrew isn't installed and macports is, add the macports default paths
57          dnl as a last resort.
58          if test x$PORT != x; then
59            CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
60            LDFLAGS="$LDFLAGS -L/opt/local/lib"
61          fi
62        fi
63      fi
64    ;;
65 esac
66
67 CFLAGS="$CFLAGS -W"
68
69 warn_CFLAGS="-Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function"
70 saved_CFLAGS="$CFLAGS"
71 CFLAGS="$CFLAGS $warn_CFLAGS"
72 AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
73 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
74     [ AC_MSG_RESULT([yes]) ],
75     [ AC_MSG_RESULT([no])
76       CFLAGS="$saved_CFLAGS"
77     ])
78
79
80 AC_ARG_ENABLE(benchmark,
81     AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is yes)]),
82     [use_benchmark=$enableval],
83     [use_benchmark=yes])
84
85 AC_ARG_ENABLE(tests,
86     AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
87     [use_tests=$enableval],
88     [use_tests=yes])
89
90 AC_ARG_ENABLE(endomorphism,
91     AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]),
92     [use_endomorphism=$enableval],
93     [use_endomorphism=no])
94
95 AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=gmp|64bit|64bit_asm|32bit|auto],
96 [Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
97
98 AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|auto],
99 [Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
100
101 AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
102 [Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
103
104 AC_CHECK_TYPES([__int128])
105
106 AC_CHECK_DECL(__builtin_expect,AC_DEFINE(HAVE_BUILTIN_EXPECT,1,[Define this symbol if __builtin_expect is available]),,)
107
108 if test x"$req_field" = x"auto"; then
109   SECP_64BIT_ASM_CHECK
110   if test x"$has_64bit_asm" = x"yes"; then
111     set_field=64bit_asm
112   fi
113
114   if test x"$set_field" = x; then
115     SECP_INT128_CHECK
116     if test x"$has_int128" = x"yes"; then
117       set_field=64bit
118     fi
119   fi
120
121   if test x"$set_field" = x; then
122     SECP_GMP_CHECK
123     if test x"$has_gmp" = x"yes"; then
124       set_field=gmp
125     fi
126   fi
127
128   if test x"$set_field" = x; then
129     set_field=32bit
130   fi
131 else
132   set_field=$req_field
133   case $set_field in
134   64bit_asm)
135     SECP_64BIT_ASM_CHECK
136     ;;
137   64bit)
138     SECP_INT128_CHECK
139     ;;
140   gmp)
141     SECP_GMP_CHECK
142     ;;
143   32bit)
144     ;;
145   *)
146     AC_MSG_ERROR([invalid field implementation selection])
147     ;;
148   esac
149 fi
150
151 if test x"$req_scalar" = x"auto"; then
152   if test x"$set_scalar" = x; then
153     SECP_INT128_CHECK
154     if test x"$has_int128" = x"yes"; then
155       set_scalar=64bit
156     fi
157   fi
158   if test x"$set_scalar" = x; then
159     set_scalar=32bit
160   fi
161 else
162   set_scalar=$req_scalar
163   case $set_scalar in
164   64bit)
165     SECP_INT128_CHECK
166     ;;
167   32bit)
168     ;;
169   *)
170     AC_MSG_ERROR([invalid scalar implementation selected])
171     ;;
172   esac
173 fi
174
175 if test x"$req_bignum" = x"auto"; then
176   SECP_GMP_CHECK
177   if test x"$has_gmp" = x"yes"; then
178     set_bignum=gmp
179   fi
180
181   if test x"$set_bignum" = x; then
182     AC_MSG_ERROR([no working bignum implementation found])
183   fi
184 else
185   set_bignum=$req_bignum
186   case $set_bignum in
187   gmp)
188     SECP_GMP_CHECK
189     ;;
190   openssl)
191     SECP_OPENSSL_CHECK
192     ;;
193   *)
194     AC_MSG_ERROR([invalid bignum implementation selection])
195     ;;
196   esac
197 fi
198
199 # select field implementation
200 case $set_field in
201 64bit_asm)
202   AC_DEFINE(USE_FIELD_5X52_ASM, 1, [Define this symbol to use the assembly version for the 5x52 field implementation])
203   AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
204   ;;
205 64bit)
206   AC_DEFINE(USE_FIELD_5X52_INT128, 1, [Define this symbol to use the __int128 version for the 5x52 field implementation])
207   AC_DEFINE(USE_FIELD_5X52, 1, [Define this symbol to use the FIELD_5X52 implementation])
208   ;;
209 gmp)
210   AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])
211   AC_DEFINE(USE_FIELD_GMP, 1, [Define this symbol to use the FIELD_GMP implementation])
212   ;;
213 32bit)
214   AC_DEFINE(USE_FIELD_10X26, 1, [Define this symbol to use the FIELD_10X26 implementation])
215   ;;
216 *)
217   AC_MSG_ERROR([invalid field implementation])
218   ;;
219 esac
220
221 # select bignum implementation
222 case $set_bignum in
223 gmp)
224   AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])
225   AC_DEFINE(USE_NUM_GMP, 1, [Define this symbol to use the gmp implementation])
226   AC_DEFINE(USE_FIELD_INV_NUM, 1, [Define this symbol to use the num-based field inverse implementation])
227   AC_DEFINE(USE_SCALAR_INV_NUM, 1, [Define this symbol to use the num-based scalar inverse implementation])
228   ;;
229 *)
230   AC_MSG_ERROR([invalid bignum implementation])
231   ;;
232 esac
233
234 #select scalar implementation
235 case $set_scalar in
236 64bit)
237   AC_DEFINE(USE_SCALAR_4X64, 1, [Define this symbol to use the 4x64 scalar implementation])
238   ;;
239 32bit)
240   AC_DEFINE(USE_SCALAR_8X32, 1, [Define this symbol to use the 8x32 scalar implementation])
241   ;;
242 *)
243   AC_MSG_ERROR([invalid scalar implementation])
244   ;;
245 esac
246
247 if test x"$use_tests" = x"yes"; then
248   SECP_OPENSSL_CHECK
249   if test x"$has_openssl_ec" == x"yes"; then
250     AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
251     SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS"
252     SECP_TEST_LIBS="$CRYPTO_LIBS"
253
254     case $host in
255     *mingw*)
256       SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
257       ;;
258     esac
259
260   fi
261 fi
262
263 if test x"$set_field" = x"gmp" || test x"$set_bignum" = x"gmp"; then
264   SECP_LIBS="$SECP_LIBS $GMP_LIBS"
265   SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS"
266 fi
267
268 if test x"$use_endomorphism" = x"yes"; then
269   AC_DEFINE(USE_ENDOMORPHISM, 1, [Define this symbol to use endomorphism])
270 fi
271
272 AC_MSG_NOTICE([Using field implementation: $set_field])
273 AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
274 AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
275
276 AC_CONFIG_HEADERS([src/libsecp256k1-config.h])
277 AC_CONFIG_FILES([Makefile libsecp256k1.pc])
278 AC_SUBST(SECP_INCLUDES)
279 AC_SUBST(SECP_LIBS)
280 AC_SUBST(SECP_TEST_LIBS)
281 AC_SUBST(SECP_TEST_INCLUDES)
282 AC_SUBST(YASM_BINFMT)
283 AM_CONDITIONAL([USE_ASM], [test x"$set_field" == x"64bit_asm"])
284 AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
285 AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" != x"no"])
286
287 dnl make sure nothing new is exported so that we don't break the cache
288 PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
289 unset PKG_CONFIG_PATH
290 PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
291
292 AC_OUTPUT
This page took 0.037838 seconds and 4 git commands to generate.