-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
77 lines (65 loc) · 2.21 KB
/
Copy pathbuild.sh
File metadata and controls
77 lines (65 loc) · 2.21 KB
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
#!/usr/bin/env bash
set -euo pipefail
# HippoFrog build.sh — compile to ./bin/HippoFrog, fix mtimes, prefer clang++ + lld
# Usage:
# ./build.sh # portable build
# ./build.sh release # -march=native -flto
# ./build.sh strict # -Werror -pedantic
# ./build.sh asan # dev: Address/UB sanitizers
MODE="${1:-portable}"
echo "[1/6] Fixing file modification times..."
now_ts="$(date +%s)"
if touch -d "@${now_ts}" . 2>/dev/null; then
find . -type f -exec touch -d "@${now_ts}" {} +
else
find . -type f -exec touch {} +
fi
echo "[2/6] Selecting compiler and linker..."
if command -v clang++ >/dev/null 2>&1; then
export CXX=clang++
elif command -v g++ >/dev/null 2>&1; then
export CXX=g++
else
echo "No C++ compiler found (need clang++ or g++)." >&2; exit 1
fi
echo " CXX=${CXX}"
USE_LLD=0
if command -v ld.lld >/dev/null 2>&1 || command -v lld >/dev/null 2>&1; then
USE_LLD=1
fi
EXTRA_LDFLAGS=""
if [ "${USE_LLD}" -eq 1 ]; then
EXTRA_LDFLAGS+=" -fuse-ld=lld -Wl,-O2"
echo " Using lld"
else
echo " lld not found; using system linker"
fi
echo "[3/6] Detecting OpenSSL..."
OPENSSL_CFLAGS=""
OPENSSL_LIBS="-lssl -lcrypto"
if command -v pkg-config >/dev/null 2>&1 && pkg-config --exists openssl; then
OPENSSL_CFLAGS="$(pkg-config --cflags openssl)"
OPENSSL_LIBS="$(pkg-config --libs openssl)"
fi
echo " OPENSSL_CFLAGS=${OPENSSL_CFLAGS}"
echo " OPENSSL_LIBS=${OPENSSL_LIBS}"
echo "[4/6] Configuring flags..."
BASE_CXXFLAGS="${OPENSSL_CFLAGS}"
if [ "${MODE}" = "release" ]; then
BASE_CXXFLAGS+=" -march=native -mtune=native -flto"
elif [ "${MODE}" = "strict" ]; then
BASE_CXXFLAGS+=" -Werror -pedantic"
fi
if [ "${MODE}" = "asan" ]; then
BASE_CXXFLAGS+=" -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer"
fi
export CXXFLAGS="${CXXFLAGS:-} ${BASE_CXXFLAGS}"
export LDFLAGS="${EXTRA_LDFLAGS} ${LDFLAGS:-}"
export LDLIBS="${OPENSSL_LIBS}"
echo "[5/6] Building HippoFrog into ./bin/HippoFrog ..."
make clean >/dev/null 2>&1 || true
make -j"$(nproc || echo 1)"
echo "[6/6] Smoke tests..."
./bin/HippoFrog --generate-keys >/dev/null && echo "Keygen OK" || echo "Keygen FAILED"
./bin/HippoFrog --validate-keys >/dev/null && echo "Validate OK" || echo "Validate FAILED"
echo "Done. Binary at ./bin/HippoFrog"