-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild-librandomx.sh
executable file
·77 lines (71 loc) · 1.65 KB
/
build-librandomx.sh
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
#!/bin/bash
set -e
if [[ "$CI" = "true" ]]; then
set -vx
fi
if ! command -v git > /dev/null; then
echo "No git in the system; install git first." > /dev/stderr
exit 1
fi
randomx_version=v1.1.9
if [[ "$1" != "" ]]; then
randomx_version="$1"
fi
case "$(uname -s)" in
Darwin)
lib_filename=librandomx.dylib
;;
*)
lib_filename=librandomx.so
;;
esac
destination="$(dirname "$0")/native/$lib_filename"
if [[ -f "$destination" && "$CI" != "true" ]]; then
echo "$destination already exists; this script will do nothing." > /dev/stderr
exit 0
fi
if [[ ! -d "$(dirname "$0")/native" ]]; then
mkdir -p "$(dirname "$0")/native"
fi
tmpdir="$(mktemp -d)"
cleanup_tmpdir() {
rm -rf "$tmpdir"
}
trap cleanup_tmpdir EXIT
git clone \
--depth=1 \
--branch "$randomx_version" \
git://github.com/tevador/RandomX.git \
"$tmpdir"
pushd "$tmpdir"
if [[ "$(uname -s)" = Linux ]] && command -v gcc > /dev/null; then
export CC=gcc
export CXX=g++
elif [[ "$(uname -s)" = Darwin ]] && command -v clang > /dev/null; then
export CC=clang
export CXX=clang++
fi
if [[ "$BUILD_STATIC_LIBS" != "" ]]; then
cmake \
-DARCH=native \
-DCMAKE_C_FLAGS="-static -no-pie -static-libgcc" \
-DCMAKE_CXX_FLAGS="-static -no-pie -static-libgcc -static-libstdc++ -fno-rtti"
make
gcc \
-o librandomx.so \
-shared \
-fno-rtti \
-Wl,--whole-archive \
"$(gcc --print-file-name=libc.a)" \
librandomx.a \
-static-libgcc \
-static-libstdc++ \
-lstdc++ \
-Wl,--no-whole-archive
else
cmake -DARCH=native -DBUILD_SHARED_LIBS=ON
make
fi
popd
cp "$tmpdir/$lib_filename" "$destination"
echo "$destination has been made; check it out!" > /dev/stderr