forked from gridcoin-community/Gridcoin-Research
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_dependencies.sh
More file actions
executable file
·390 lines (326 loc) · 15.8 KB
/
install_dependencies.sh
File metadata and controls
executable file
·390 lines (326 loc) · 15.8 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#!/usr/bin/env bash
export LC_ALL=C
# ==============================================================================
# HELPER: DETECT WSL
# ==============================================================================
check_is_wsl() {
if grep -qE "(Microsoft|WSL)" /proc/version &> /dev/null; then
return 0 # True (Is WSL)
else
return 1 # False (Is Native Linux)
fi
}
install_deps() {
local TARGET="$1"
local USE_QT6="$2"
local WITH_GUI="$3"
# Detect OS Type first
OS_TYPE=$(uname -s)
if [[ "$OS_TYPE" == "Darwin" ]]; then
OS="macos"
echo "Detected OS: macOS (Darwin)"
elif [ -f /etc/os-release ]; then
# The next line prevents the linter from looking into os-release and complaining about unused variables.
# shellcheck source=/dev/null
. /etc/os-release
OS=$ID
else
echo "Error: Cannot detect OS distribution."
return 1
fi
# Detect WSL Status (Only relevant for Linux)
IS_WSL="false"
if [[ "$OS" != "macos" ]]; then
if check_is_wsl; then
IS_WSL="true"
echo "Detected Environment: WSL (Windows Subsystem for Linux)"
else
echo "Detected Environment: Native Linux"
fi
fi
echo "Installing dependencies for Target: $TARGET, Qt6: $USE_QT6, GUI: $WITH_GUI"
# --- Package Groups Definition ---
PKGS_BASE=""
PKGS_QT=""
PKGS_MINGW=""
PKGS_WINE=""
append_base() { PKGS_BASE="$PKGS_BASE $*"; }
append_qt() { PKGS_QT="$PKGS_QT $*"; }
append_mingw() { PKGS_MINGW="$PKGS_MINGW $*"; }
# Conditional Wine Append
# We only install Wine if the target is win64 AND we are NOT on WSL.
# On WSL, we can run Windows binaries natively.
append_wine() {
if [[ "$IS_WSL" == "false" ]]; then
PKGS_WINE="$PKGS_WINE $*"
fi
}
# --- Define Packages per OS ---
case $OS in
macos)
# Homebrew Logic
if ! command -v brew &> /dev/null; then
echo "Error: Homebrew not found. Please install it from https://brew.sh"
return 1
fi
# Base Tools
append_base cmake ccache libtool automake autoconf pkg-config
# Libraries
append_base boost openssl libevent miniupnpc qrencode libzip
# Qt Logic for macOS Homebrew (Only if GUI is requested)
if [[ "$WITH_GUI" == "true" ]]; then
if [[ "$USE_QT6" == "true" ]]; then
append_qt qt
else
# Install Qt5 specific formula for legacy support
append_qt qt@5
fi
fi
;;
debian|ubuntu|linuxmint)
# Base Build Tools
append_base build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 cmake git curl ccache doxygen graphviz bison xxd libxkbcommon-dev
# Libraries for Native Build
append_base libssl-dev libevent-dev libboost-all-dev libminiupnpc-dev libqrencode-dev libzip-dev libcurl4-openssl-dev zipcmp zipmerge ziptool
# Qt6 Packages (Qt5 names are not defined here as most are EOL)
append_qt qt6-base-dev qt6-tools-dev qt6-l10n-tools qt6-tools-dev-tools libqt6charts6-dev libqt6svg6-dev libqt6core5compat6-dev
# Windows Cross-Compile Tools
# NOTE: We only append NSIS here. The MinGW compiler (g++-mingw-w64-x86-64)
# is handled conditionally below to support manual installs on Ubuntu 22.04.
append_mingw nsis
# Wine (Emulator for Native Linux only)
append_wine wine wine64
# Smart Check for MinGW Headers on Ubuntu 22.04
if [[ "$TARGET" == "win64" || "$TARGET" == "all" ]]; then
SHOULD_INSTALL_MINGW="true"
if grep -q "22.04" /etc/os-release; then
# 1. Check if binary exists
MINGW_BIN="x86_64-w64-mingw32-g++"
if command -v "$MINGW_BIN" &> /dev/null; then
# 2. Check HEADER version directly using the preprocessor
# We look for __MINGW64_VERSION_MAJOR in _mingw.h
MINGW_HEADER_VER=$(echo "#include <_mingw.h>" | "$MINGW_BIN" -E -dM - 2>/dev/null | grep "^#define __MINGW64_VERSION_MAJOR " | awk '{print $3}')
# Default to 0 if grep failed
if [ -z "$MINGW_HEADER_VER" ]; then MINGW_HEADER_VER=0; fi
# 3. Logic Gate: We need headers >= 9 for D3D12/Qt6 support
if [[ "$MINGW_HEADER_VER" -ge 9 ]]; then
echo "Detected manual MinGW install (Header Version $MINGW_HEADER_VER). Skipping repo package."
SHOULD_INSTALL_MINGW="false"
else
echo "Error: Detected MinGW header version $MINGW_HEADER_VER is too old (Need >= 9)."
# We must force 'false' here so we fall through to the fatal error block below
# We cannot simply install the repo package to fix this, as the repo package IS the problem.
SHOULD_INSTALL_MINGW="false"
FORCE_FAIL_2204="true"
fi
else
# Binary missing entirely
echo "Error: MinGW compiler not found."
SHOULD_INSTALL_MINGW="false" # Do not try to install repo package
FORCE_FAIL_2204="true"
fi
# Fatal Error Block for 22.04
if [[ "$FORCE_FAIL_2204" == "true" ]]; then
echo "----------------------------------------------------------------"
echo "CRITICAL: Windows Cross-Compilation on Ubuntu 22.04 requires manual setup."
echo " The standard repository packages are too old (Headers < 9.0)."
echo ""
echo " You must manually install a newer MinGW toolchain (v9+)"
echo " OR upgrade to Ubuntu 24.04+."
echo "----------------------------------------------------------------"
exit 1
fi
fi
# If logic allows, append the compiler package (Standard path for non-22.04)
if [[ "$SHOULD_INSTALL_MINGW" == "true" ]]; then
append_mingw g++-mingw-w64-x86-64
fi
fi
;;
fedora|rhel)
append_base libstdc++-static gcc-c++ libtool automake autoconf pkgconf-pkg-config python3 cmake git curl patch perl-FindBin bison flex ccache doxygen graphviz
append_base openssl-devel libevent-devel boost-devel miniupnpc-devel qrencode-devel libzip-devel libcurl-devel libzip-tools
append_qt qt6-qtbase-devel qt6-qttools-devel qt6-qtcharts-devel qt6-qtsvg-devel qt6-qt5compat-devel
append_mingw mingw64-gcc-c++ mingw64-nsis xxd
# Fedora Wine
append_wine wine
;;
opensuse*|sles)
# Detect Tumbleweed vs Leap
if [[ "$ID" == "sles" ]]; then
echo "Error: SLES not supported automatically."
return 1
fi
IS_TUMBLEWEED="false"
if [[ "$PRETTY_NAME" == *"Tumbleweed"* ]]; then
DISTRO_PATH="openSUSE_Tumbleweed"
IS_TUMBLEWEED="true"
elif [[ "$PRETTY_NAME" == *"Leap"* ]]; then
DISTRO_PATH="15.6"
else
echo "Error: Unknown openSUSE version."
return 1
fi
# Repo Logic for openSUSE
if [[ "$TARGET" == "all" || "$TARGET" == "win64" ]]; then
REPO_64_URL="https://download.opensuse.org/repositories/windows:/mingw:/win64/$DISTRO_PATH/"
REPO_64_NAME="windows_mingw_win64"
REPO_32_URL="https://download.opensuse.org/repositories/windows:/mingw:/win32/$DISTRO_PATH/"
REPO_32_NAME="windows_mingw_win32"
add_repo_if_missing() {
local url="$1"
local name="$2"
local desc="$3"
if sudo zypper lr -u | grep -Fq "$url"; then
echo "Repository for $desc already exists (URL match)."
else
if sudo zypper lr | grep -q "$name"; then
echo "Warning: Repository alias '$name' exists but URL mismatch."
else
echo "Adding $desc repository: $url"
sudo zypper ar -f "$url" "$name"
fi
fi
}
add_repo_if_missing "$REPO_64_URL" "$REPO_64_NAME" "MinGW Win64"
add_repo_if_missing "$REPO_32_URL" "$REPO_32_NAME" "MinGW Win32"
sudo zypper --gpg-auto-import-keys refresh
fi
# Pattern Install
echo "Installing devel_basis pattern..."
sudo zypper install -y -t pattern devel_basis
# Base common packages
append_base libtool automake autoconf pkg-config python3 cmake git curl ccache doxygen graphviz libzstd-devel
append_base libopenssl-devel libevent-devel qrencode-devel libzip-devel libcurl-devel libzip-tools
append_base miniupnpc libminiupnpc-devel
# Boost Packages
append_base libboost_headers-devel libboost_filesystem-devel libboost_thread-devel libboost_date_time-devel libboost_iostreams-devel libboost_serialization-devel libboost_test-devel libboost_atomic-devel libboost_regex-devel
# Boost System Logic:
# Use 'zypper info' to check which version of headers is (or will be) installed.
# This handles both Clean Install and Upgrade scenarios correctly.
INSTALL_BOOST_SYSTEM="true"
# Get the version string from the repository metadata
# Output format example: "Version : 1.89.0-..."
BOOST_VER_STRING=$(zypper info libboost_headers-devel | grep -i "Version" | head -n 1 | awk '{print $3}')
if [ -n "$BOOST_VER_STRING" ]; then
# Extract Major.Minor
IFS='.' read -r -a VER_PARTS <<< "$BOOST_VER_STRING"
MAJOR=${VER_PARTS[0]}
MINOR=${VER_PARTS[1]}
# Check if >= 1.69 (Boost System became header-only)
if [[ "$MAJOR" -ge 1 ]] && [[ "$MINOR" -ge 69 ]]; then
INSTALL_BOOST_SYSTEM="false"
echo "Detected Boost >= 1.69 ($BOOST_VER_STRING) in repo. Skipping libboost_system-devel."
fi
fi
if [[ "$IS_TUMBLEWEED" == "false" ]]; then
append_base gcc13 gcc13-c++
fi
if [[ "$INSTALL_BOOST_SYSTEM" == "true" ]]; then
append_base libboost_system-devel
fi
append_qt qt6-base-devel qt6-tools-devel qt6-charts-devel qt6-svg-devel qt6-qt5compat-devel qt6-linguist-devel
append_mingw mingw64-cross-gcc-c++ nsis
# OpenSUSE Wine
append_wine wine
;;
arch|manjaro)
sudo pacman -Syu --noconfirm
append_base base-devel python cmake git ccache doxygen graphviz
append_base boost libevent miniupnpc libzip qrencode curl icu
append_qt qt6-base qt6-tools qt6-charts qt6-svg qt6-5compat
append_mingw mingw-w64-gcc nsis
# Arch Wine
append_wine wine
;;
alpine)
# Base Build Tools
# 'build-base' is Alpine's build-essential.
# 'linux-headers' often needed. 'bash' is needed for these scripts.
# 'libexecinfo-dev' is sometimes needed for backtraces on musl.
append_base build-base cmake git curl ccache doxygen graphviz bison linux-headers xxd bash autoconf automake libtool perl
# Libraries
append_base boost-dev openssl-dev libevent-dev miniupnpc-dev libqrencode-dev libzip-dev curl-dev
# Qt6 Packages
append_qt qt6-qtbase-dev qt6-qttools-dev qt6-qtcharts-dev qt6-qtsvg-dev qt6-qt5compat-dev
;;
*)
echo "Error: Unsupported distribution '$OS'."
return 1
;;
esac
# --- Determine Final Package List to Install ---
PKGS_TO_INSTALL=""
# FIX: Base packages are always required.
PKGS_TO_INSTALL="$PKGS_TO_INSTALL $PKGS_BASE"
# --- Qt Package Logic ---
if [[ "$WITH_GUI" == "true" ]]; then
if [[ "$OS" == "macos" ]]; then
# macOS: PKGS_QT was already populated conditionally inside the case statement
PKGS_TO_INSTALL="$PKGS_TO_INSTALL $PKGS_QT"
else
# Linux: PKGS_QT is populated unconditionally in the distro blocks with Qt6 packages.
# We must handle the logic here to ensure we don't install Qt6 when Qt5 is requested.
if [[ "$USE_QT6" == "true" ]]; then
if [[ "$TARGET" == "all" || "$TARGET" == "native" ]]; then
PKGS_TO_INSTALL="$PKGS_TO_INSTALL $PKGS_QT"
fi
else
# Case: Linux + Qt5.
# We do not list Qt5 packages for Linux as distro support is spotty/EOL.
echo "----------------------------------------------------------------"
echo "WARNING: Qt5 requested on Linux (WITH_GUI=true, USE_QT6=false)."
echo " This script only defines Qt6 packages for Linux."
echo " You must install the appropriate Qt5 packages manually."
echo "----------------------------------------------------------------"
fi
fi
fi
if [[ "$TARGET" == "all" || "$TARGET" == "win64" ]]; then
PKGS_TO_INSTALL="$PKGS_TO_INSTALL $PKGS_MINGW"
# Only adds wine if !WSL
PKGS_TO_INSTALL="$PKGS_TO_INSTALL $PKGS_WINE"
fi
# Clean up leading whitespace
PKGS_TO_INSTALL=$(echo "$PKGS_TO_INSTALL" | xargs)
if [ -z "$PKGS_TO_INSTALL" ]; then
echo "No packages selected for installation."
return 0
fi
# --- Execute Install Command ---
echo "Installing Packages: $PKGS_TO_INSTALL"
case $OS in
macos)
# macOS uses Homebrew, usually doesn't need sudo if user owns prefix
brew install $PKGS_TO_INSTALL
;;
debian|ubuntu|linuxmint)
sudo apt-get update
sudo apt-get install -y --no-install-recommends $PKGS_TO_INSTALL
# MinGW Threading Fix (Linux Only)
if [[ "$TARGET" == "all" || "$TARGET" == "win64" ]]; then
echo "Configuring MinGW-w64 threading model to POSIX..."
if [ -f /usr/bin/x86_64-w64-mingw32-g++-posix ]; then
sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
echo "MinGW-w64 threading model set to POSIX."
else
echo "Warning: MinGW POSIX alternative not found. Skipping threading configuration."
fi
fi
;;
fedora|rhel)
sudo dnf install -y $PKGS_TO_INSTALL
;;
opensuse*|sles)
sudo zypper install -y $PKGS_TO_INSTALL
;;
arch|manjaro)
sudo pacman -S --noconfirm $PKGS_TO_INSTALL
;;
alpine)
sudo apk update
sudo apk add $PKGS_TO_INSTALL
;;
esac
}