Repository navigation
Expand file tree
/
Copy pathsetup_linux_build_env.sh
More file actions
executable file
·629 lines (554 loc) · 22.9 KB
/
Copy pathsetup_linux_build_env.sh
File metadata and controls
executable file
·629 lines (554 loc) · 22.9 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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
#!/bin/bash -l
#
# FrankyCPP
# Copyright (c) 2018-2026 Frank Kopp
#
# MIT License
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
set -e # Exit on error
# Source bashrc to load environment variables like VCPKG_ROOT
if [ -f ~/.bashrc ]; then
source ~/.bashrc 2>/dev/null || true
fi
# Fallback: if VCPKG_ROOT is still not set, try common locations
if [ -z "$VCPKG_ROOT" ]; then
if [ -d "$HOME/vcpkg" ]; then
export VCPKG_ROOT="$HOME/vcpkg"
elif [ -d "$HOME/.vcpkg-clion/vcpkg" ]; then
export VCPKG_ROOT="$HOME/.vcpkg-clion/vcpkg"
elif [ -d "/opt/vcpkg" ]; then
export VCPKG_ROOT="/opt/vcpkg"
fi
fi
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Parse command line arguments
MODE="validate" # Default: validate only (safe, no system modifications)
SET_ENV=false
if [ "$1" = "--install" ] || [ "$1" = "-i" ]; then
MODE="install"
elif [ "$1" = "--set-env" ] || [ "$1" = "-e" ]; then
MODE="validate"
SET_ENV=true
elif [ "$1" = "--validate" ] || [ "$1" = "-v" ]; then
MODE="validate"
elif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "FrankyCPP Linux Build Environment Setup"
echo ""
echo "Usage:"
echo " $0 Validate environment (safe, no modifications)"
echo " $0 --install Install dependencies and validate"
echo " $0 --set-env Set VCPKG_ROOT in ~/.bashrc for detected vcpkg"
echo " $0 --validate Validate environment only (same as default)"
echo " $0 --help Show this help message"
echo ""
echo "SAFETY NOTE:"
echo " Default behavior is validate-only to avoid unintended system modifications."
echo " Use --install explicitly when you want to install packages."
echo " Use --set-env to add VCPKG_ROOT to ~/.bashrc if vcpkg is detected."
echo ""
exit 0
fi
# =============================================================================
# INSTALLATION
# =============================================================================
install_dependencies() {
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Installing Dependencies${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Detect if running in CI
if [ -n "$CI" ] || [ -n "$GITHUB_ACTIONS" ]; then
echo -e "${YELLOW}Running in CI/CD environment${NC}"
IS_CI=true
else
echo -e "${GREEN}Running in local environment${NC}"
IS_CI=false
fi
# Check if running as root or with sudo
if [ "$EUID" -eq 0 ]; then
SUDO=""
echo -e "${YELLOW}Running as root${NC}"
else
SUDO="sudo"
echo -e "${GREEN}Using sudo for package installation${NC}"
fi
echo ""
# Update package lists
echo -e "${BLUE}Updating package lists...${NC}"
$SUDO apt-get update -qq
echo -e "${GREEN}✓ Package lists updated${NC}"
echo ""
# Install essential build tools
echo -e "${BLUE}Installing essential build tools...${NC}"
$SUDO apt-get install -y -qq \
build-essential \
cmake \
ninja-build \
git \
pkg-config \
curl \
zip \
unzip \
tar \
ca-certificates
echo -e "${GREEN}✓ Essential build tools installed${NC}"
echo ""
# Install GCC 13 for std::format support (C++20 feature, requires GCC 13+)
echo -e "${BLUE}Installing GCC 13 for full C++20 support (std::format)...${NC}"
# Add Ubuntu Toolchain PPA if not already added
if ! grep -q "ubuntu-toolchain-r/test" /etc/apt/sources.list /etc/apt/sources.list.d/* 2>/dev/null; then
echo -e " Adding Ubuntu Toolchain PPA..."
$SUDO add-apt-repository ppa:ubuntu-toolchain-r/test -y
$SUDO apt-get update -qq
echo -e " ${GREEN}✓ Toolchain PPA added${NC}"
else
echo -e " ${GREEN}✓ Toolchain PPA already present${NC}"
fi
# Install GCC 13
$SUDO apt-get install -y -qq gcc-13 g++-13
echo -e "${GREEN}✓ GCC 13 installed${NC}"
# Set GCC 13 as default using update-alternatives
echo -e " Setting GCC 13 as default compiler..."
$SUDO update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 130 --slave /usr/bin/g++ g++ /usr/bin/g++-13 2>/dev/null || true
$SUDO update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110 --slave /usr/bin/g++ g++ /usr/bin/g++-11 2>/dev/null || true
$SUDO update-alternatives --set gcc /usr/bin/gcc-13 2>/dev/null || true
echo -e "${GREEN}✓ GCC 13 set as default${NC}"
echo ""
# Install Clang 18 for cross-compiler testing
echo -e "${BLUE}Installing Clang 18 for cross-compiler testing...${NC}"
# Add LLVM apt repository for Clang 18
if ! grep -q "llvm-toolchain" /etc/apt/sources.list.d/* 2>/dev/null; then
echo -e " Adding LLVM repository..."
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | $SUDO tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc > /dev/null
$SUDO add-apt-repository -y "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-18 main"
$SUDO apt-get update -qq
fi
$SUDO apt-get install -y -qq clang-18 || {
echo -e "${YELLOW}! Clang 18 not available, trying clang-17...${NC}"
$SUDO apt-get install -y -qq clang-17 || {
echo -e "${YELLOW}! Clang 17 not available, trying default clang...${NC}"
$SUDO apt-get install -y -qq clang
}
}
echo -e "${GREEN}✓ Clang installed${NC}"
echo ""
# Install optional but recommended tools (for vcpkg packages)
echo -e "${BLUE}Installing optional tools for vcpkg...${NC}"
$SUDO apt-get install -y -qq \
autoconf \
automake \
libtool \
python3 \
python3-pip
echo -e "${GREEN}✓ Optional tools installed${NC}"
echo ""
# Check compiler versions
echo -e "${BLUE}Verifying installed tools...${NC}"
# GCC
GCC_VERSION=$(gcc --version | head -n 1)
echo -e " GCC: ${GCC_VERSION}"
GCC_MAJOR=$(gcc -dumpversion | cut -d. -f1)
if [ "$GCC_MAJOR" -ge 13 ]; then
echo -e " ${GREEN}✓ GCC $GCC_MAJOR supports full C++20 (including std::format)${NC}"
elif [ "$GCC_MAJOR" -ge 10 ]; then
echo -e " ${YELLOW}! GCC $GCC_MAJOR supports C++20 but NOT std::format (need >= 13)${NC}"
else
echo -e " ${RED}✗ GCC version too old for C++20 (need >= 10)${NC}"
return 1
fi
# CMake
CMAKE_VERSION=$(cmake --version | head -n 1 | grep -oP '\d+\.\d+\.\d+')
echo -e " CMake: ${CMAKE_VERSION}"
CMAKE_MAJOR=$(echo $CMAKE_VERSION | cut -d. -f1)
CMAKE_MINOR=$(echo $CMAKE_VERSION | cut -d. -f2)
if [ "$CMAKE_MAJOR" -gt 3 ] || ([ "$CMAKE_MAJOR" -eq 3 ] && [ "$CMAKE_MINOR" -ge 16 ]); then
echo -e " ${GREEN}✓ CMake version sufficient (>= 3.16)${NC}"
else
echo -e " ${RED}✗ CMake version too old (need >= 3.16)${NC}"
return 1
fi
# Ninja
NINJA_VERSION=$(ninja --version)
echo -e " Ninja: ${NINJA_VERSION}"
echo -e " ${GREEN}✓ Ninja found${NC}"
# Git
GIT_VERSION=$(git --version)
echo -e " Git: ${GIT_VERSION}"
echo -e " ${GREEN}✓ Git found${NC}"
echo ""
echo -e "${GREEN}✓ All tools verified${NC}"
echo ""
# Install/setup vcpkg
echo -e "${BLUE}Setting up vcpkg...${NC}"
# Determine vcpkg location
if [ "$IS_CI" = true ]; then
# In CI, use a specific location
VCPKG_ROOT="${VCPKG_ROOT:-/opt/vcpkg}"
echo -e " CI mode: Installing vcpkg to ${VCPKG_ROOT}"
else
# Locally, use home directory
VCPKG_ROOT="${VCPKG_ROOT:-$HOME/vcpkg}"
echo -e " Local mode: Installing vcpkg to ${VCPKG_ROOT}"
fi
# Clone vcpkg if it doesn't exist
if [ ! -d "$VCPKG_ROOT" ]; then
echo -e " Cloning vcpkg repository..."
$SUDO git clone https://github.com/microsoft/vcpkg.git "$VCPKG_ROOT"
echo -e " ${GREEN}✓ vcpkg cloned${NC}"
else
echo -e " ${GREEN}✓ vcpkg directory exists${NC}"
# Update vcpkg if in CI (always use latest in CI)
if [ "$IS_CI" = true ]; then
echo -e " Updating vcpkg..."
cd "$VCPKG_ROOT"
$SUDO git pull --quiet
echo -e " ${GREEN}✓ vcpkg updated${NC}"
fi
fi
# Bootstrap vcpkg if needed
if [ ! -f "$VCPKG_ROOT/vcpkg" ]; then
echo -e " Bootstrapping vcpkg..."
cd "$VCPKG_ROOT"
$SUDO ./bootstrap-vcpkg.sh -disableMetrics
echo -e " ${GREEN}✓ vcpkg bootstrapped${NC}"
else
echo -e " ${GREEN}✓ vcpkg already bootstrapped${NC}"
fi
# Set environment variable for current session
export VCPKG_ROOT
# Add to bashrc if not in CI and not already present
if [ "$IS_CI" = false ]; then
if ! grep -q "VCPKG_ROOT" "$HOME/.bashrc"; then
echo "" >> "$HOME/.bashrc"
echo "# vcpkg root (added by FrankyCPP setup script)" >> "$HOME/.bashrc"
echo "export VCPKG_ROOT=\"$VCPKG_ROOT\"" >> "$HOME/.bashrc"
echo -e " ${GREEN}✓ VCPKG_ROOT added to ~/.bashrc${NC}"
else
echo -e " ${GREEN}✓ VCPKG_ROOT already in ~/.bashrc${NC}"
fi
fi
echo -e "${GREEN}✓ vcpkg setup complete${NC}"
echo ""
# Display vcpkg version
VCPKG_VERSION=$($VCPKG_ROOT/vcpkg version | head -n 1)
echo -e " vcpkg version: ${VCPKG_VERSION}"
echo ""
}
# =============================================================================
# VALIDATION
# =============================================================================
validate_environment() {
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Validating Build Environment${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# Detect if running in CI
if [ -n "$CI" ] || [ -n "$GITHUB_ACTIONS" ]; then
IS_CI=true
else
IS_CI=false
fi
ERRORS=0
WARNINGS=0
# Function to check if a command exists
check_command() {
local cmd=$1
local required=$2
local package_hint=$3
if command -v "$cmd" &> /dev/null; then
local version=$($cmd --version 2>&1 | head -n 1)
echo -e "${GREEN}✓${NC} $cmd found: $version"
return 0
else
if [ "$required" = "required" ]; then
echo -e "${RED}✗${NC} $cmd not found (REQUIRED)"
if [ -n "$package_hint" ]; then
echo -e " Install: ${YELLOW}$package_hint${NC}"
fi
ERRORS=$((ERRORS + 1))
else
echo -e "${YELLOW}!${NC} $cmd not found (optional)"
if [ -n "$package_hint" ]; then
echo -e " Install: ${YELLOW}$package_hint${NC}"
fi
WARNINGS=$((WARNINGS + 1))
fi
return 1
fi
}
# Check compilers
echo -e "${BLUE}Checking compilers...${NC}"
check_command "gcc" "required" "sudo apt install build-essential"
check_command "g++" "required" "sudo apt install build-essential"
# Check for Clang 18 or 17 (preferred versions)
if command -v clang-18 &> /dev/null; then
CLANG_VERSION=$(clang-18 --version | head -n 1)
echo -e "${GREEN}✓${NC} clang-18 found: $CLANG_VERSION"
elif command -v clang-17 &> /dev/null; then
CLANG_VERSION=$(clang-17 --version | head -n 1)
echo -e "${GREEN}✓${NC} clang-17 found: $CLANG_VERSION"
elif command -v clang &> /dev/null; then
CLANG_VERSION=$(clang --version | head -n 1)
echo -e "${YELLOW}!${NC} clang found: $CLANG_VERSION"
echo -e " ${YELLOW}Clang 18+ recommended for full C++20 support${NC}"
echo -e " ${YELLOW}Run: ./setup_linux_build_env.sh --install (to install Clang 18)${NC}"
WARNINGS=$((WARNINGS + 1))
else
echo -e "${YELLOW}!${NC} clang not found (optional)"
echo -e " Install: ${YELLOW}sudo apt install clang${NC}"
WARNINGS=$((WARNINGS + 1))
fi
# Check GCC version for C++20 support
if command -v gcc &> /dev/null; then
GCC_VERSION=$(gcc -dumpversion)
GCC_MAJOR=$(echo $GCC_VERSION | cut -d. -f1)
if [ "$GCC_MAJOR" -ge 13 ]; then
echo -e "${GREEN}✓${NC} GCC $GCC_VERSION supports full C++20 (including std::format)"
elif [ "$GCC_MAJOR" -ge 10 ]; then
echo -e "${YELLOW}!${NC} GCC $GCC_VERSION supports C++20 but NOT std::format (need >= 13)"
echo -e " ${YELLOW}Run: ./setup_linux_build_env.sh --install (to upgrade to GCC 13)${NC}"
WARNINGS=$((WARNINGS + 1))
else
echo -e "${RED}✗${NC} GCC $GCC_VERSION does not fully support C++20 (need >= 10.0)"
ERRORS=$((ERRORS + 1))
fi
fi
echo ""
# Check build tools
echo -e "${BLUE}Checking build tools...${NC}"
check_command "cmake" "required" "sudo apt install cmake"
check_command "ninja" "required" "sudo apt install ninja-build"
check_command "make" "optional" "sudo apt install make"
# Check CMake version
if command -v cmake &> /dev/null; then
CMAKE_VERSION=$(cmake --version | head -n 1 | grep -oP '\d+\.\d+\.\d+')
CMAKE_MAJOR=$(echo $CMAKE_VERSION | cut -d. -f1)
CMAKE_MINOR=$(echo $CMAKE_VERSION | cut -d. -f2)
if [ "$CMAKE_MAJOR" -gt 3 ] || ([ "$CMAKE_MAJOR" -eq 3 ] && [ "$CMAKE_MINOR" -ge 16 ]); then
echo -e "${GREEN}✓${NC} CMake $CMAKE_VERSION meets requirement (>= 3.16)"
else
echo -e "${RED}✗${NC} CMake $CMAKE_VERSION is too old (need >= 3.16)"
ERRORS=$((ERRORS + 1))
fi
fi
echo ""
# Check utilities
echo -e "${BLUE}Checking utilities...${NC}"
check_command "git" "required" "sudo apt install git"
check_command "pkg-config" "required" "sudo apt install pkg-config"
check_command "curl" "required" "sudo apt install curl"
check_command "tar" "required" "sudo apt install tar"
check_command "unzip" "required" "sudo apt install unzip"
check_command "zip" "optional" "sudo apt install zip"
check_command "autoconf" "optional" "sudo apt install autoconf"
check_command "automake" "optional" "sudo apt install automake"
check_command "libtoolize" "optional" "sudo apt install libtool"
echo ""
# Check vcpkg
echo -e "${BLUE}Checking vcpkg...${NC}"
if [ -n "$VCPKG_ROOT" ]; then
echo -e "${GREEN}✓${NC} VCPKG_ROOT is set: $VCPKG_ROOT"
if [ -d "$VCPKG_ROOT" ]; then
echo -e "${GREEN}✓${NC} VCPKG_ROOT directory exists"
if [ -f "$VCPKG_ROOT/vcpkg" ]; then
echo -e "${GREEN}✓${NC} vcpkg executable found"
VCPKG_VERSION=$($VCPKG_ROOT/vcpkg version | head -n 1)
echo -e " Version: $VCPKG_VERSION"
else
echo -e "${RED}✗${NC} vcpkg executable not found in $VCPKG_ROOT"
echo -e " Run: cd $VCPKG_ROOT && ./bootstrap-vcpkg.sh"
ERRORS=$((ERRORS + 1))
fi
else
echo -e "${RED}✗${NC} VCPKG_ROOT directory does not exist: $VCPKG_ROOT"
ERRORS=$((ERRORS + 1))
fi
else
echo -e "${RED}✗${NC} VCPKG_ROOT environment variable not set"
echo -e " Run this script with --install to set up vcpkg"
ERRORS=$((ERRORS + 1))
fi
echo ""
# Check CPU features
echo -e "${BLUE}Checking CPU features...${NC}"
if [ -f /proc/cpuinfo ]; then
if grep -q "avx2" /proc/cpuinfo; then
echo -e "${GREEN}✓${NC} AVX2 supported"
else
echo -e "${YELLOW}!${NC} AVX2 not detected"
WARNINGS=$((WARNINGS + 1))
fi
if grep -q "bmi2" /proc/cpuinfo; then
echo -e "${GREEN}✓${NC} BMI2 (PEXT) supported"
else
echo -e "${YELLOW}!${NC} BMI2 not detected - will need to disable PEXT optimizations"
WARNINGS=$((WARNINGS + 1))
fi
if grep -q "popcnt" /proc/cpuinfo; then
echo -e "${GREEN}✓${NC} POPCNT supported"
else
echo -e "${YELLOW}!${NC} POPCNT not detected"
WARNINGS=$((WARNINGS + 1))
fi
else
echo -e "${YELLOW}!${NC} Cannot detect CPU features (/proc/cpuinfo not found)"
WARNINGS=$((WARNINGS + 1))
fi
echo ""
# Check project structure (only warnings, not fatal in CI)
echo -e "${BLUE}Checking project structure...${NC}"
if [ -f "CMakeLists.txt" ]; then
echo -e "${GREEN}✓${NC} CMakeLists.txt found"
else
if [ "$IS_CI" = true ]; then
echo -e "${YELLOW}!${NC} CMakeLists.txt not found (working directory: $(pwd))"
WARNINGS=$((WARNINGS + 1))
else
echo -e "${RED}✗${NC} CMakeLists.txt not found (run from project root)"
ERRORS=$((ERRORS + 1))
fi
fi
if [ -f "vcpkg.json" ]; then
echo -e "${GREEN}✓${NC} vcpkg.json found (manifest mode)"
else
if [ "$IS_CI" = true ]; then
echo -e "${YELLOW}!${NC} vcpkg.json not found (working directory: $(pwd))"
WARNINGS=$((WARNINGS + 1))
else
echo -e "${RED}✗${NC} vcpkg.json not found"
ERRORS=$((ERRORS + 1))
fi
fi
if [ -f "build_wsl.sh" ]; then
echo -e "${GREEN}✓${NC} build_wsl.sh found"
if [ -x "build_wsl.sh" ]; then
echo -e "${GREEN}✓${NC} build_wsl.sh is executable"
else
echo -e "${YELLOW}!${NC} build_wsl.sh is not executable (run: chmod +x build_wsl.sh)"
WARNINGS=$((WARNINGS + 1))
fi
else
echo -e "${YELLOW}!${NC} build_wsl.sh not found"
WARNINGS=$((WARNINGS + 1))
fi
echo ""
# Summary
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Validation Summary${NC}"
echo -e "${BLUE}========================================${NC}"
if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then
echo -e "${GREEN}✓ All checks passed!${NC}"
echo -e "${GREEN}Your build environment is ready.${NC}"
return 0
elif [ $ERRORS -eq 0 ]; then
echo -e "${YELLOW}! $WARNINGS warning(s) found${NC}"
echo -e "${GREEN}Build should work, but some features may be unavailable.${NC}"
return 0
else
echo -e "${RED}✗ $ERRORS error(s) found${NC}"
if [ $WARNINGS -gt 0 ]; then
echo -e "${YELLOW}! $WARNINGS warning(s) found${NC}"
fi
echo -e "${RED}Please fix the errors above before building.${NC}"
return 1
fi
}
# =============================================================================
# MAIN
# =============================================================================
main() {
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}FrankyCPP Linux Build Environment Setup${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
case "$MODE" in
install)
echo -e "${YELLOW}INSTALLING dependencies (requires sudo)${NC}"
echo ""
install_dependencies
echo ""
validate_environment
;;
validate)
if [ "$SET_ENV" = true ]; then
echo -e "${YELLOW}SETTING VCPKG_ROOT environment variable${NC}"
echo ""
# Check if VCPKG_ROOT is already set
if [ -n "$VCPKG_ROOT" ]; then
echo -e "${GREEN}✓ VCPKG_ROOT already set: $VCPKG_ROOT${NC}"
# Check if it's in bashrc
if grep -q "VCPKG_ROOT" "$HOME/.bashrc"; then
echo -e "${GREEN}✓ VCPKG_ROOT already in ~/.bashrc${NC}"
else
echo -e "Adding VCPKG_ROOT to ~/.bashrc..."
echo "" >> "$HOME/.bashrc"
echo "# vcpkg root (added by FrankyCPP setup script)" >> "$HOME/.bashrc"
echo "export VCPKG_ROOT=\"$VCPKG_ROOT\"" >> "$HOME/.bashrc"
echo -e "${GREEN}✓ VCPKG_ROOT added to ~/.bashrc${NC}"
echo -e "${YELLOW}! Run 'source ~/.bashrc' or restart your terminal${NC}"
fi
else
echo -e "${RED}✗ VCPKG_ROOT not set and no vcpkg detected${NC}"
echo -e "${YELLOW}Run '$0 --install' to install vcpkg first${NC}"
fi
echo ""
else
echo -e "${GREEN}VALIDATING environment (safe, no modifications)${NC}"
echo ""
fi
validate_environment
;;
esac
local exit_code=$?
echo ""
echo -e "${BLUE}========================================${NC}"
if [ $exit_code -eq 0 ]; then
echo -e "${GREEN}Setup complete!${NC}"
if [ "$MODE" = "install" ]; then
if [ -n "$CI" ] || [ -n "$GITHUB_ACTIONS" ]; then
echo -e "${GREEN}Ready for CI/CD build${NC}"
else
echo -e "${YELLOW}Next steps:${NC}"
echo -e " 1. Run: ${GREEN}source ~/.bashrc${NC} (to load VCPKG_ROOT)"
echo -e " 2. Configure: ${GREEN}cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release${NC}"
echo -e " 3. Build: ${GREEN}cmake --build build${NC}"
fi
elif [ "$MODE" = "validate" ]; then
# Check if there were errors during validation
if grep -q "error(s) found" <<< "$validation_output" 2>/dev/null || [ $exit_code -ne 0 ]; then
echo -e "${YELLOW}To install missing dependencies, run:${NC}"
echo -e " ${GREEN}$0 --install${NC}"
fi
fi
else
echo -e "${RED}Setup encountered errors${NC}"
if [ "$MODE" = "validate" ]; then
echo -e "${YELLOW}To install missing dependencies, run:${NC}"
echo -e " ${GREEN}$0 --install${NC}"
fi
fi
echo -e "${BLUE}========================================${NC}"
return $exit_code
}
# Run main function
main
exit $?