forked from steemit/steem
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild-mac.sh
More file actions
240 lines (205 loc) · 6.49 KB
/
build-mac.sh
File metadata and controls
240 lines (205 loc) · 6.49 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env bash
# ============================================================================
# VIZ macOS Build Script
#
# Prerequisites:
# - macOS 12 (Monterey) or later
# - Xcode Command Line Tools (xcode-select --install)
# - Homebrew (https://brew.sh)
# - Boost 1.71+ (via Homebrew or built from source)
# - Git
#
# Usage:
# ./build-mac.sh [options]
#
# Options:
# -t, --type TYPE Build type: Release or Debug (default: Release)
# -n, --testnet Build for testnet (BUILD_TESTNET=ON)
# -s, --static Build shared libraries OFF (static linking)
# --no-lock-check Disable chainbase lock checking
# --skip-deps Skip dependency installation
# --install Run make install after build
# -j, --jobs N Number of parallel jobs (default: hw.logicalcpu)
# --boost-root PATH Custom Boost installation path
# --openssl-root PATH Custom OpenSSL installation path
# -h, --help Show this help message
# ============================================================================
set -euo pipefail
# --- Defaults ---
BUILD_TYPE="Release"
BUILD_TESTNET="OFF"
SHARED_LIBS="ON"
CHAINBASE_LOCK="ON"
SKIP_DEPS="false"
DO_INSTALL="false"
JOBS=""
BOOST_ROOT_ARG=""
OPENSSL_ROOT_ARG=""
# --- Colors ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; }
# --- Parse arguments ---
show_help() {
sed -n '2,/^# =====/s/^# //p' "$0"
exit 0
}
while [[ $# -gt 0 ]]; do
case $1 in
-t|--type)
BUILD_TYPE="$2"; shift 2 ;;
-n|--testnet)
BUILD_TESTNET="ON"; shift ;;
-s|--static)
SHARED_LIBS="OFF"; shift ;;
--no-lock-check)
CHAINBASE_LOCK="OFF"; shift ;;
--skip-deps)
SKIP_DEPS="true"; shift ;;
--install)
DO_INSTALL="true"; shift ;;
-j|--jobs)
JOBS="$2"; shift 2 ;;
--boost-root)
BOOST_ROOT_ARG="-DBOOST_ROOT=$2"; shift 2 ;;
--openssl-root)
OPENSSL_ROOT_ARG="-DOPENSSL_ROOT_DIR=$2"; shift 2 ;;
-h|--help)
show_help ;;
*)
error "Unknown option: $1. Use -h for help." ;;
esac
done
# --- Detect number of jobs ---
if [[ -z "$JOBS" ]]; then
JOBS=$(sysctl -n hw.logicalcpu 2>/dev/null || echo 2)
fi
# --- Determine source directory ---
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_DIR="$SCRIPT_DIR"
# --- Check we're in the right directory ---
if [[ ! -f "$SOURCE_DIR/CMakeLists.txt" ]]; then
error "CMakeLists.txt not found in $SOURCE_DIR. Run this script from the viz-cpp-node root."
fi
# --- Verify macOS ---
if [[ "$(uname)" != "Darwin" ]]; then
error "This script is for macOS only. Use build-linux.sh for Linux builds."
fi
# --- Check Xcode Command Line Tools ---
check_xcode() {
if ! xcode-select -p &>/dev/null; then
warn "Xcode Command Line Tools not found. Installing..."
xcode-select --install
error "Please re-run this script after Xcode Command Line Tools installation completes."
fi
info "Xcode Command Line Tools: $(xcode-select -p)"
}
# --- Check Homebrew ---
check_homebrew() {
if ! command -v brew &>/dev/null; then
error "Homebrew not found. Install it from https://brew.sh/ and re-run."
fi
info "Homebrew: $(brew --prefix)"
}
# --- Install dependencies via Homebrew ---
install_deps() {
info "Installing build dependencies via Homebrew..."
brew install \
autoconf \
automake \
boost \
cmake \
git \
libtool \
openssl \
python3 \
readline
# Optional: TCMalloc for LevelDB
# brew install google-perftools
info "Dependencies installed."
}
# --- Set OpenSSL path ---
detect_openssl() {
if [[ -z "$OPENSSL_ROOT_ARG" ]]; then
local openssl_prefix
openssl_prefix=$(brew --prefix openssl 2>/dev/null || true)
if [[ -n "$openssl_prefix" && -d "$openssl_prefix" ]]; then
export OPENSSL_ROOT_DIR="$openssl_prefix"
OPENSSL_ROOT_ARG="-DOPENSSL_ROOT_DIR=$openssl_prefix"
info "Using Homebrew OpenSSL: $openssl_prefix"
else
warn "Could not detect Homebrew OpenSSL. Set --openssl-root or OPENSSL_ROOT_DIR manually."
fi
fi
}
# --- Setup environment ---
setup_env() {
check_xcode
check_homebrew
if [[ "$SKIP_DEPS" == "false" ]]; then
install_deps
fi
detect_openssl
}
setup_env
# --- Initialize submodules ---
if [[ -d "$SOURCE_DIR/.git" ]]; then
info "Initializing git submodules..."
git -C "$SOURCE_DIR" submodule update --init --recursive -f
fi
# --- Create build directory ---
BUILD_DIR="$SOURCE_DIR/build"
mkdir -p "$BUILD_DIR"
# --- Display configuration ---
echo ""
echo "============================================"
echo " VIZ macOS Build"
echo "============================================"
echo " Build Type: $BUILD_TYPE"
echo " Build Testnet: $BUILD_TESTNET"
echo " Shared Libs: $SHARED_LIBS"
echo " Chainbase Locks: $CHAINBASE_LOCK"
echo " Parallel Jobs: $JOBS"
echo " Source Dir: $SOURCE_DIR"
echo " Build Dir: $BUILD_DIR"
if [[ -n "$BOOST_ROOT_ARG" ]]; then
echo " Boost: $BOOST_ROOT_ARG"
else
echo " Boost: (Homebrew default)"
fi
if [[ -n "$OPENSSL_ROOT_ARG" ]]; then
echo " OpenSSL: $OPENSSL_ROOT_ARG"
fi
echo "============================================"
echo ""
# --- Configure ---
info "[1/3] Configuring with CMake..."
cmake -S "$SOURCE_DIR" -B "$BUILD_DIR" \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DBUILD_SHARED_LIBRARIES="$SHARED_LIBS" \
-DBUILD_TESTNET="$BUILD_TESTNET" \
-DCHAINBASE_CHECK_LOCKING="$CHAINBASE_LOCK" \
$BOOST_ROOT_ARG \
$OPENSSL_ROOT_ARG
info "CMake configuration complete."
# --- Build ---
info "[2/3] Building with $JOBS parallel jobs..."
cmake --build "$BUILD_DIR" -j"$JOBS"
info "Build complete."
# --- Install ---
if [[ "$DO_INSTALL" == "true" ]]; then
info "[3/3] Installing..."
sudo cmake --install "$BUILD_DIR"
info "Installation complete."
else
info "[3/3] Skipping install (use --install to install)."
fi
echo ""
echo "============================================"
echo -e " ${GREEN}Build completed successfully!${NC}"
echo " Output directory: $BUILD_DIR"
echo "============================================"