build(install.sh): made boost check more preformant

This commit is contained in:
2025-07-29 12:23:43 -04:00
parent 5181dda06e
commit 5d516c2544
3 changed files with 52 additions and 231 deletions

View File

@@ -1,226 +0,0 @@
#!/usr/bin/env bash
#
# install.sh - Interactive installation script for Boost.
#
# This script checks if Boost is installed (by looking for boost/version.hpp in common locations).
# If not found, it prompts the user to install Boost using the native package manager for:
# - FreeBSD, Ubuntu, Debian, Fedora, Arch, Mint, Manjaro, macOS, OpenSuse, and Nix.
#
# All output is colorized for clarity and logged to meson-log.txt.
set -e
# ANSI color codes.
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
BLUE="\033[0;34m"
NC="\033[0m" # No Color
# Log file.
LOGFILE="4DSSE-install-log.txt"
touch "$LOGFILE"
# Log function: prints to stdout and appends to logfile.
log() {
local message="$1"
# Print the colored message to stdout.
echo -e "$message"
# Strip ANSI escape sequences and append the cleaned message to the log file.
echo -e "$message" | sed -r 's/\x1B\[[0-9;]*[mK]//g' >> "$LOGFILE"
}
check_boost_installed() {
log "${BLUE}[Info] Checking for Boost::numeric and Boost::phoenix using Meson...${NC}"
local tmpDir
if [[ -d mesonTest ]]; then
rm -rf mesonTest
fi
tmpDir=$(mkdir mesonTest)
local sourceFile="mesonTest/test.cpp"
local mesonFile="mesonTest/meson.build"
# Write test.cpp
cat > "$sourceFile" <<EOF
#include <boost/numeric/ublas/vector.hpp>
#include <boost/phoenix/phoenix.hpp>
int main() {
boost::numeric::ublas::vector<double> v(3);
v[0] = 1.0;
return v[0];
}
EOF
# Write meson.build
cat > "$mesonFile" <<EOF
project('boost-check', 'cpp', default_options: ['cpp_std=c++17'])
boost_dep = dependency('boost', required: true)
executable('boostAvaliTest', 'test.cpp', dependencies: [boost_dep])
EOF
# Try configuring and compiling
if meson setup "mesonTest/build" "mesonTest" && \
meson compile -C "mesonTest/build"; then
log "${GREEN}[Success] Boost::numeric and Boost::phoenix are available.${NC}"
rm -rf "mesonTest"
return 0
else
log "${RED}[Error] Boost could not be found or required components are missing.${NC}"
rm -rf "mesonTest"
return 1
fi
}
# Prompt the user for a yes/no answer.
prompt_yes_no() {
local promptMsg="$1"
read -p "$(echo -e ${YELLOW}$promptMsg${NC}) " answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
return 0
else
return 1
fi
}
# Detect OS.
OS=$(uname -s)
DISTRO="unknown"
if [ -f /etc/os-release ]; then
# shellcheck disable=SC1091
. /etc/os-release
DISTRO=$ID
fi
if [[ "$OS" == "Darwin" ]]; then
OS="macOS"
fi
if [[ $OS == "macOS" ]]; then
log "${BLUE}[Info] Detected OS: ${OS}${NC}"
else
log "${BLUE}[Info] Detected OS: ${OS} Distribution: ${DISTRO}${NC}"
fi
# Check if Boost is already installed.
if check_boost_installed; then
log "${GREEN}[Success] Boost is already installed on your system.${NC}"
log "${GREEN}[Success] 4DSSE installation can now continue.${NC}"
exit 0
else
log "${YELLOW}[Info] Boost was not detected on your system.${NC}"
if prompt_yes_no "[Query] Would you like to install Boost now? (y/n): "; then
case "$OS" in
"macOS")
# On macOS, check if Homebrew is available.
if ! command -v brew &> /dev/null; then
log "${YELLOW}[Warning] Homebrew is not installed. It is recommended for installing Boost on macOS.${NC}"
if prompt_yes_no "[Query] Would you like to install Homebrew now? (y/n): "; then
log "${BLUE}[Info] Installing Homebrew...${NC}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | tee -a "$LOGFILE"
else
log "${RED}[Error] Homebrew is required for an easy Boost installation on macOS. Aborting.${NC}"
exit 1
fi
fi
log "${BLUE}[Info] Running: brew install boost${NC}"
brew install boost | tee -a "$LOGFILE"
;;
"Linux")
case "$DISTRO" in
"ubuntu"|"debian"|"linuxmint")
log "${BLUE}[Info] Running: sudo apt-get update && sudo apt-get install -y libboost-all-dev${NC}"
sudo apt-get update | tee -a "$LOGFILE"
sudo apt-get install -y libboost-all-dev | tee -a "$LOGFILE"
;;
"fedora")
log "${BLUE}[Info] Running: sudo dnf install boost-devel${NC}"
sudo dnf install -y boost-devel | tee -a "$LOGFILE"
;;
"arch"|"manjaro")
log "${BLUE}[Info] Running: sudo pacman -S boost${NC}"
sudo pacman -S --noconfirm boost | tee -a "$LOGFILE"
;;
"opensuse")
log "${BLUE}[Info] Running: sudo zypper install libboost-devel${NC}"
sudo zypper install -y libboost-devel | tee -a "$LOGFILE"
;;
"nixos"|"nix")
log "${BLUE}[Info] Running: nix-env -iA nixpkgs.boost${NC}"
nix-env -iA nixpkgs.boost | tee -a "$LOGFILE"
;;
*)
log "${RED}[Error] Your Linux distribution is not recognized. Please install Boost manually.${NC}"
exit 1
;;
esac
;;
"FreeBSD")
log "${BLUE}[Info] Running: sudo pkg install boost-all${NC}"
sudo pkg install -y boost-all | tee -a "$LOGFILE"
;;
*)
log "${RED}[Error] Automatic Boost installation is not supported on OS: ${OS}. Please install Boost manually.${NC}"
exit 1
;;
esac
# Verify Boost installation.
if check_boost_installed; then
log "${GREEN}[Success] Boost installation succeeded.${NC}"
else
log "${RED}[Error] Boost installation appears to have failed. Please install Boost manually.${NC}"
exit 1
fi
else
log "${RED}[Error] Boost is required. Please install it using the appropriate command for your system:${NC}"
case "$OS" in
"macOS")
log "${RED}[INFO] brew install boost (Install Homebrew from https://brew.sh if not present)${NC}"
;;
"Linux")
case "$DISTRO" in
"ubuntu"|"debian"|"linuxmint")
log "${RED}[INFO] sudo apt-get install libboost-all-dev${NC}"
;;
"fedora")
log "${RED}[INFO] sudo dnf install boost-devel${NC}"
;;
"arch"|"manjaro")
log "${RED}[INFO] sudo pacman -S boost${NC}"
;;
"opensuse")
log "${RED}[INFO] sudo zypper install libboost-devel${NC}"
;;
"nixos"|"nix")
log "${RED}[INFO] nix-env -iA nixpkgs.boost${NC}"
;;
*)
log "${RED}[INFO] Please consult your distribution's documentation for installing Boost.${NC}"
;;
esac
;;
"FreeBSD")
log "${RED}[INFO] sudo pkg install boost-all${NC}"
;;
*)
log "${RED}[INFO] Please consult your operating system's documentation for installing Boost.${NC}"
;;
esac
exit 1
fi
fi
check_boost_installed
log "${GREEN}[Success] Boost installed successfully!${NC}"
log "${GREEN}[Success] 4DSSE installation can now continue.${NC}"

View File

@@ -1,3 +1,3 @@
boost_dep = dependency('boost', version: '>=1.8.0', required: true) boost_dep = dependency('boost', version: '>=1.85.0', required: true)

View File

@@ -527,7 +527,9 @@ run_dependency_installer_tui() {
check_meson_python >/dev/null; DEP_STATUS[meson-python]=$? check_meson_python >/dev/null; DEP_STATUS[meson-python]=$?
check_cmake >/dev/null; DEP_STATUS[cmake]=$? check_cmake >/dev/null; DEP_STATUS[cmake]=$?
check_meson >/dev/null; DEP_STATUS[meson]=$? check_meson >/dev/null; DEP_STATUS[meson]=$?
check_boost >/dev/null; DEP_STATUS[boost]=$? if [[ $BOOST_OKAY = false ]]; then
DEP_STATUS[boost]=1 # Force boost to be "not okay" if previous check failed
fi
local choices local choices
choices=$(dialog --clear --backtitle "Project Dependency Installer" \ choices=$(dialog --clear --backtitle "Project Dependency Installer" \
@@ -612,6 +614,37 @@ run_python_bindings_tui() {
esac esac
} }
run_compiler_help_tui() {
local compiler_name="$1"
local req_ver=""
local help_text=""
if [[ "$compiler_name" == "g++" ]]; then
req_ver=$MIN_GCC_VER
help_text="The installer could not automatically install GCC >= ${req_ver}.\n\n"
help_text+="This can happen on older Linux distributions.\n\n"
help_text+="Recommended Solutions:\n"
help_text+="1. (Ubuntu/Debian) Add a PPA with newer compilers:\n"
help_text+=" sudo add-apt-repository ppa:ubuntu-toolchain-r/test\n"
help_text+=" sudo apt-get update\n"
help_text+=" sudo apt-get install g++-13\n\n"
help_text+="2. Download pre-built binaries from a trusted source.\n\n"
help_text+="3. Build GCC from source (advanced)."
elif [[ "$compiler_name" == "clang++" ]]; then
req_ver=$MIN_CLANG_VER
help_text="The installer could not automatically install Clang >= ${req_ver}.\n\n"
help_text+="This is common on systems like Ubuntu 22.04.\n\n"
help_text+="Recommended Solution (Ubuntu/Debian):\n"
help_text+="Use the official LLVM APT repository. Run this command in your terminal:\n\n"
help_text+=' bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"'
help_text+="\n\nThis script will set up the repository and install the latest version of Clang. After running it, re-run this installer."
fi
dialog --title "Compiler Installation Failed" --msgbox "$help_text" 25 78
}
run_compiler_selection_tui() { run_compiler_selection_tui() {
local gpp_ver; gpp_ver=$(g++ -dumpversion 2>/dev/null | grep -oE '[0-9]+(\.[0-9]+)*' | head -n1) local gpp_ver; gpp_ver=$(g++ -dumpversion 2>/dev/null | grep -oE '[0-9]+(\.[0-9]+)*' | head -n1)
local clang_ver; clang_ver=$(clang++ --version 2>/dev/null | head -n1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1) local clang_ver; clang_ver=$(clang++ --version 2>/dev/null | head -n1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)
@@ -631,20 +664,34 @@ run_compiler_selection_tui() {
for choice in $choices; do for choice in $choices; do
local compiler_to_install; compiler_to_install=$(echo "$choice" | tr -d '"') local compiler_to_install; compiler_to_install=$(echo "$choice" | tr -d '"')
local install_cmd; install_cmd=$(get_compiler_install_cmd "$compiler_to_install") local install_cmd; install_cmd=$(get_compiler_install_cmd "$compiler_to_install")
if [ -n "$install_cmd" ]; then eval "$install_cmd" 2>&1 | tee -a "$LOGFILE"; fi if [ -n "$install_cmd" ]; then
eval "$install_cmd" 2>&1 | tee -a "$LOGFILE"
# Post-install check
check_compiler
if ! check_command "${VALID_COMPILERS[g++*]}" && [[ "$compiler_to_install" == "g++" ]]; then run_compiler_help_tui "g++"; fi
if ! check_command "${VALID_COMPILERS[clang++*]}" && [[ "$compiler_to_install" == "clang++" ]]; then run_compiler_help_tui "clang++"; fi
fi
done done
fi fi
elif ! $gpp_ok && [[ -n "$gpp_ver" ]]; then elif ! $gpp_ok && [[ -n "$gpp_ver" ]]; then
# g++ found but too old # g++ found but too old
if dialog --title "Compiler Update" --yesno "Found g++ version ${gpp_ver}, but require >= ${MIN_GCC_VER}.\n\nAttempt to install a compatible version?" 10 70; then if dialog --title "Compiler Update" --yesno "Found g++ version ${gpp_ver}, but require >= ${MIN_GCC_VER}.\n\nAttempt to install a compatible version?" 10 70; then
local install_cmd; install_cmd=$(get_compiler_install_cmd "g++") local install_cmd; install_cmd=$(get_compiler_install_cmd "g++")
if [ -n "$install_cmd" ]; then eval "$install_cmd" 2>&1 | tee -a "$LOGFILE"; fi if [ -n "$install_cmd" ]; then
eval "$install_cmd" 2>&1 | tee -a "$LOGFILE"
check_compiler
if ! $gpp_ok; then run_compiler_help_tui "g++"; fi
fi
fi fi
elif ! $clang_ok && [[ -n "$clang_ver" ]]; then elif ! $clang_ok && [[ -n "$clang_ver" ]]; then
# clang++ found but too old # clang++ found but too old
if dialog --title "Compiler Update" --yesno "Found clang++ version ${clang_ver}, but require >= ${MIN_CLANG_VER}.\n\nAttempt to install a compatible version?" 10 70; then if dialog --title "Compiler Update" --yesno "Found clang++ version ${clang_ver}, but require >= ${MIN_CLANG_VER}.\n\nAttempt to install a compatible version?" 10 70; then
local install_cmd; install_cmd=$(get_compiler_install_cmd "clang++") local install_cmd; install_cmd=$(get_compiler_install_cmd "clang++")
if [ -n "$install_cmd" ]; then eval "$install_cmd" 2>&1 | tee -a "$LOGFILE"; fi if [ -n "$install_cmd" ]; then
eval "$install_cmd" 2>&1 | tee -a "$LOGFILE"
check_compiler
if ! $clang_ok; then run_compiler_help_tui "clang++"; fi
fi
fi fi
fi fi