Debian Codegraph @

contrib/make_libsecp256k1.sh

raw symbols SCIP
1 #!/bin/bash
2
3 # This script was tested on Linux and MacOS hosts, where it can be used
4 # to build native libsecp256k1 binaries.
5 #
6 # It can also be used to cross-compile to Windows:
7 # $ sudo apt-get install mingw-w64
8 # For a Windows x86 (32-bit) target, run:
9 # $ GCC_TRIPLET_HOST="i686-w64-mingw32" ./contrib/make_libsecp256k1.sh
10 # Or for a Windows x86_64 (64-bit) target, run:
11 # $ GCC_TRIPLET_HOST="x86_64-w64-mingw32" ./contrib/make_libsecp256k1.sh
12 #
13 # To cross-compile to Linux x86:
14 # sudo apt-get install gcc-multilib g++-multilib
15 # $ AUTOCONF_FLAGS="--host=i686-linux-gnu CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32" ./contrib/make_libsecp256k1.sh
16
17 LIBSECP_VERSION="1a53f4961f337b4d166c25fce72ef0dc88806618"
18 # ^ tag "v0.7.1"
19 # note: this version is duplicated in contrib/android/p4a_recipes/libsecp256k1/__init__.py
20 # (and also in electrum-ecc, for the "secp256k1" git submodule)
21
22 set -e
23
24 . "$(dirname "$0")/build_tools_util.sh" || (echo "Could not source build_tools_util.sh" && exit 1)
25
26 here="$(dirname "$(realpath "$0" 2> /dev/null || grealpath "$0")")"
27 CONTRIB="$here"
28 PROJECT_ROOT="$CONTRIB/.."
29
30 pkgname="secp256k1"
31 info "Building $pkgname..."
32
33 (
34 cd "$CONTRIB"
35 if [ ! -d secp256k1 ]; then
36 git clone https://github.com/bitcoin-core/secp256k1.git
37 fi
38 cd secp256k1
39 if ! $(git cat-file -e ${LIBSECP_VERSION}) ; then
40 info "Could not find requested version $LIBSECP_VERSION in local clone; fetching..."
41 git fetch --all
42 fi
43 git reset --hard
44 git clean -dfxq
45 git checkout "${LIBSECP_VERSION}^{commit}"
46
47 if ! [ -x configure ] ; then
48 echo "LDFLAGS = -no-undefined" >> Makefile.am
49 ./autogen.sh || fail "Could not run autogen for $pkgname. Please make sure you have automake and libtool installed, and try again."
50 fi
51 if ! [ -r config.status ] ; then
52 ./configure \
53 $AUTOCONF_FLAGS \
54 --prefix="$here/$pkgname/dist" \
55 --enable-module-recovery \
56 --enable-module-extrakeys \
57 --enable-module-schnorrsig \
58 --enable-experimental \
59 --enable-module-ecdh \
60 --disable-benchmark \
61 --disable-tests \
62 --disable-exhaustive-tests \
63 --disable-static \
64 --enable-shared || fail "Could not configure $pkgname. Please make sure you have a C compiler installed and try again."
65 fi
66 make "-j$CPU_COUNT" || fail "Could not build $pkgname"
67 make install || fail "Could not install $pkgname"
68 . "$here/$pkgname/dist/lib/libsecp256k1.la"
69 host_strip "$here/$pkgname/dist/lib/$dlname"
70 if [ -n "$DLL_TARGET_DIR" ] ; then
71 cp -fpv "$here/$pkgname/dist/lib/$dlname" "$DLL_TARGET_DIR/" || fail "Could not copy the $pkgname binary to DLL_TARGET_DIR"
72 else
73 cp -fpv "$here/$pkgname/dist/lib/$dlname" "$PROJECT_ROOT/electrum" || fail "Could not copy the $pkgname binary to its destination"
74 info "$dlname has been placed in the 'electrum' folder."
75 fi
76 )