]>
Commit | Line | Data |
---|---|---|
f0c89aad PW |
1 | #!/bin/sh |
2 | ||
3 | if test -f config.mk; then | |
4 | exit 0 | |
5 | fi | |
6 | ||
7 | if test -z "$CC"; then | |
8 | CC=cc | |
9 | fi | |
10 | ||
11 | if test -z "$YASM"; then | |
12 | YASM=yasm | |
13 | fi | |
14 | ||
15 | # test yasm | |
16 | $YASM -f elf64 -o /tmp/secp256k1-$$.o - <<EOF | |
17 | BITS 64 | |
18 | GLOBAL testyasm | |
19 | ALIGN 32 | |
20 | testyasm: | |
21 | xor r9,r9 | |
22 | EOF | |
23 | if [ "$?" = 0 ]; then | |
24 | $CC $CFLAGS -std=c99 -x c -c - -o /tmp/secp256k1-$$-2.o 2>/dev/null <<EOF | |
25 | void __attribute__ ((sysv_abi)) testyasm(void); | |
26 | int main() { | |
27 | testyasm(); | |
28 | return 0; | |
29 | } | |
30 | EOF | |
31 | $CC $CFLAGS -std=c99 /tmp/secp256k1-$$-2.o /tmp/secp256k1-$$.o -o /dev/null 2>/dev/null | |
32 | if [ "$?" = 0 ]; then | |
33 | HAVE_YASM=1 | |
34 | fi | |
35 | rm -rf /tmp/secp256k1-$$-2.o /tmp/secp256k1-$$.o | |
36 | fi | |
37 | ||
38 | # test openssl | |
39 | HAVE_OPENSSL=0 | |
40 | $CC $CFLAGS -std=c99 -x c - -o /dev/null -lcrypto 2>/dev/null <<EOF | |
41 | #include <openssl/bn.h> | |
42 | int main() { | |
43 | BN_CTX *ctx = BN_CTX_new(); | |
44 | BN_CTX_free(ctx); | |
45 | return 0; | |
46 | } | |
47 | EOF | |
48 | if [ "$?" = 0 ]; then | |
49 | HAVE_OPENSSL=1 | |
50 | fi | |
51 | ||
dd08f037 PW |
52 | # test openssl/EC |
53 | HAVE_OPENSSL_EC=0 | |
54 | if [ "$HAVE_OPENSSL" = "1" ]; then | |
7b03d836 | 55 | $CC $CFLAGS -std=c99 -x c - -o /dev/null -lcrypto 2>/dev/null <<EOF |
dd08f037 PW |
56 | #include <openssl/ec.h> |
57 | #include <openssl/ecdsa.h> | |
58 | #include <openssl/obj_mac.h> | |
59 | int main() { | |
60 | EC_KEY *eckey = EC_KEY_new_by_curve_name(NID_secp256k1); | |
61 | ECDSA_sign(0, NULL, 0, NULL, NULL, eckey); | |
62 | ECDSA_verify(0, NULL, 0, NULL, 0, eckey); | |
63 | EC_KEY_free(eckey); | |
64 | return 0; | |
65 | } | |
66 | EOF | |
67 | if [ "$?" = 0 ]; then | |
68 | HAVE_OPENSSL_EC=1 | |
69 | fi | |
70 | fi | |
71 | ||
f0c89aad PW |
72 | # test gmp |
73 | HAVE_GMP=0 | |
74 | $CC $CFLAGS -std=c99 -x c - -o /dev/null -lgmp 2>/dev/null <<EOF | |
75 | #include <gmp.h> | |
76 | int main() { | |
77 | mpz_t n; | |
78 | mpz_init(n); | |
79 | mpz_clear(n); | |
80 | return 0; | |
81 | } | |
82 | EOF | |
83 | if [ "$?" = 0 ]; then | |
84 | HAVE_GMP=1 | |
85 | fi | |
86 | ||
87 | # test __int128 | |
88 | HAVE_INT128=0 | |
89 | $CC $CFLAGS -std=c99 -x c - -o /dev/null 2>/dev/null <<EOF | |
90 | #include <stdint.h> | |
91 | int main() { | |
92 | __int128 x = 0; | |
93 | return 0; | |
94 | } | |
95 | EOF | |
96 | if [ "$?" = 0 ]; then | |
97 | HAVE_INT128=1 | |
98 | fi | |
99 | ||
dd804ade DH |
100 | #default limb size |
101 | HAVE_LIMB=52 | |
102 | ||
f0c89aad PW |
103 | for arg in "$@"; do |
104 | case "$arg" in | |
105 | --no-yasm) | |
106 | HAVE_YASM=0 | |
107 | ;; | |
108 | --no-gmp) | |
109 | HAVE_GMP=0 | |
110 | ;; | |
111 | --no-openssl) | |
112 | HAVE_OPENSSL=0 | |
dd804ade DH |
113 | ;; |
114 | --use-5x64) | |
115 | HAVE_LIMB=64 | |
f0c89aad PW |
116 | ;; |
117 | esac | |
118 | done | |
119 | ||
120 | LINK_OPENSSL=0 | |
121 | LINK_GMP=0 | |
122 | USE_ASM=0 | |
123 | ||
124 | # select field implementation | |
125 | if [ "$HAVE_YASM" = "1" ]; then | |
dd804ade | 126 | CFLAGS_FIELD="-DUSE_FIELD_5X$HAVE_LIMB -DUSE_FIELD_5X${HAVE_LIMB}_ASM" |
f0c89aad PW |
127 | USE_ASM=1 |
128 | elif [ "$HAVE_INT128" = "1" ]; then | |
dd804ade | 129 | CFLAGS_FIELD="-DUSE_FIELD_5X$HAVE_LIMB -DUSE_FIELD_5X${HAVE_LIMB}_INT128" |
f0c89aad PW |
130 | elif [ "$HAVE_GMP" = "1" ]; then |
131 | CFLAGS_FIELD="-DUSE_FIELD_GMP" | |
132 | LINK_GMP=1 | |
133 | else | |
134 | CFLAGS_FIELD="-DUSE_FIELD_10X26" | |
135 | fi | |
136 | ||
137 | # select num implementation | |
138 | if [ "$HAVE_GMP" = "1" ]; then | |
139 | CFLAGS_NUM="-DUSE_NUM_GMP -DUSE_FIELD_INV_NUM" | |
140 | LINK_GMP=1 | |
141 | elif [ "$HAVE_OPENSSL" = "1" ]; then | |
142 | CFLAGS_NUM="-DUSE_NUM_OPENSSL -DUSE_FIELD_INV_BUILTIN" | |
143 | LINK_OPENSSL=1 | |
144 | else | |
145 | echo "No usable num implementation found" >&2 | |
146 | exit 1 | |
147 | fi | |
148 | ||
149 | CFLAGS_EXTRA="$CFLAGS_FIELD $CFLAGS_NUM" | |
150 | LDFLAGS_EXTRA="" | |
151 | if [ "$LINK_GMP" = "1" ]; then | |
152 | LDFLAGS_EXTRA="-lgmp" | |
153 | fi | |
154 | if [ "$LINK_OPENSSL" = "1" ]; then | |
155 | LDFLAGS_EXTRA="-lcrypto" | |
dd08f037 PW |
156 | else |
157 | if [ "$HAVE_OPENSSL_EC" = "1" ]; then | |
158 | LDFLAGS_TEST_EXTRA="-lcrypto" | |
159 | fi | |
160 | fi | |
161 | ||
162 | CFLAGS_TEST_EXTRA="" | |
163 | if [ "$HAVE_OPENSSL_EC" = "1" ]; then | |
164 | CFLAGS_TEST_EXTRA="-DENABLE_OPENSSL_TESTS" | |
f0c89aad PW |
165 | fi |
166 | ||
167 | echo "CC=$CC" > config.mk | |
168 | echo "YASM=$YASM" >>config.mk | |
169 | echo "CFLAGS_EXTRA=$CFLAGS_EXTRA" >> config.mk | |
dd08f037 | 170 | echo "CFLAGS_TEST_EXTRA=$CFLAGS_TEST_EXTRA" >> config.mk |
f0c89aad | 171 | echo "LDFLAGS_EXTRA=$LDFLAGS_EXTRA" >> config.mk |
dd08f037 | 172 | echo "LDFLAGS_TEST_EXTRA=$LDFLAGS_TEST_EXTRA" >> config.mk |
f0c89aad | 173 | echo "USE_ASM=$USE_ASM" >>config.mk |
dd804ade | 174 | echo "HAVE_LIMB=$HAVE_LIMB" >>config.mk |
355b4192 | 175 | echo "OPTLEVEL=O2" >>config.mk |