#!/bin/bash

# Path: scripts/cpp.sh

set -e

BLUE='\033[1;34m'
YELLOW='\033[1;33m'
GREEN='\033[1;32m'
NC='\033[0m'

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$SCRIPT_DIR/lib/distro.sh"

echo -e "${BLUE}    LOG:${YELLOW} Setting up C++ Tooling (LLVM/Clang)...${NC}"

if is_arch_family; then
    CPP_PACKAGES=(clang cmake ninja lldb gdb)
elif is_debian_family || is_fedora_family; then
    CPP_PACKAGES=(clang cmake ninja-build lldb gdb)
else
    echo -e "${RED}    ERROR:${NC} Unsupported OS: $OS"
    exit 1
fi

install_status=0
install_packages "${CPP_PACKAGES[@]}" || install_status=$?

if [ "$install_status" -eq 42 ]; then
    exit 0
elif [ "$install_status" -ne 0 ]; then
    exit "$install_status"
fi

echo -e "${GREEN}    SUCCESS:${NC} C++ Environment Ready."
echo -e "    - Compiler: $(clang --version | head -n 1)"
echo -e "    - Builder:  $(cmake --version | head -n 1)"
echo -e "    - Debugger: $(lldb --version | head -n 1)"
