diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..10ce3d2 --- /dev/null +++ b/build.bat @@ -0,0 +1,333 @@ +@echo off +setlocal enabledelayedexpansion + +REM Build script for "Observations on the Sublime Dynamics of Eroding Matter" +REM A C++ project using SDL2 + +set "SCRIPT_NAME=%~n0" +set "PROJECT_NAME=observations-on-the-sublime-dynamics-of-eroding-matter" + +REM Colors for output (Windows 10+) +set "RED=[91m" +set "GREEN=[92m" +set "YELLOW=[93m" +set "BLUE=[94m" +set "NC=[0m" + +REM Function to print colored output +:print_status +echo %BLUE%[INFO]%NC% %~1 +goto :eof + +:print_success +echo %GREEN%[SUCCESS]%NC% %~1 +goto :eof + +:print_warning +echo %YELLOW%[WARNING]%NC% %~1 +goto :eof + +:print_error +echo %RED%[ERROR]%NC% %~1 +goto :eof + +REM Function to check if command exists +:command_exists +where %1 >nul 2>&1 +if %errorlevel% equ 0 ( + set "COMMAND_EXISTS=true" +) else ( + set "COMMAND_EXISTS=false" +) +goto :eof + +REM Function to check SDL2 installation +:check_sdl2 +call :print_status "Checking SDL2 installation..." + +REM Check if SDL2 is available via vcpkg or system +set "SDL2_FOUND=false" + +REM Check if SDL2 is in PATH +where sdl2-config >nul 2>&1 +if %errorlevel% equ 0 ( + call :print_success "SDL2 found in PATH" + set "SDL2_FOUND=true" + goto :sdl2_check_end +) + +REM Check if vcpkg is available and SDL2 is installed +where vcpkg >nul 2>&1 +if %errorlevel% equ 0 ( + vcpkg list | findstr sdl2 >nul 2>&1 + if %errorlevel% equ 0 ( + call :print_success "SDL2 found via vcpkg" + set "SDL2_FOUND=true" + goto :sdl2_check_end + ) +) + +REM Check if SDL2 headers exist in common locations +if exist "C:\SDL2\include\SDL2\SDL.h" ( + call :print_success "SDL2 found in C:\SDL2" + set "SDL2_FOUND=true" + goto :sdl2_check_end +) + +if exist "%ProgramFiles%\SDL2\include\SDL2\SDL.h" ( + call :print_success "SDL2 found in %ProgramFiles%\SDL2" + set "SDL2_FOUND=true" + goto :sdl2_check_end +) + +if exist "%ProgramFiles(x86)%\SDL2\include\SDL2\SDL.h" ( + call :print_success "SDL2 found in %ProgramFiles(x86)%\SDL2" + set "SDL2_FOUND=true" + goto :sdl2_check_end +) + +:sdl2_check_end +if "%SDL2_FOUND%"=="false" ( + call :print_warning "SDL2 not found. Please install SDL2:" + call :print_status " 1. Download from: https://www.libsdl.org/download-2.0.php" + call :print_status " 2. Or use vcpkg: vcpkg install sdl2" + call :print_status " 3. Or use MSYS2: pacman -S mingw-w64-x86_64-SDL2" + exit /b 1 +) + +goto :eof + +REM Function to check CMake +:check_cmake +call :print_status "Checking CMake installation..." + +call :command_exists cmake +if "%COMMAND_EXISTS%"=="false" ( + call :print_error "CMake not found. Please install CMake first:" + call :print_status " Download from: https://cmake.org/download/" + call :print_status " Or use chocolatey: choco install cmake" + call :print_status " Or use winget: winget install Kitware.CMake" + exit /b 1 +) + +for /f "tokens=3" %%i in ('cmake --version 2^>nul') do ( + set "CMAKE_VERSION=%%i" + goto :cmake_version_found +) + +:cmake_version_found +call :print_success "CMake found: version %CMAKE_VERSION%" + +REM Check minimum version requirement (simplified check) +REM This is a basic check - you might want to implement proper version comparison +call :print_success "CMake version check passed" +goto :eof + +REM Function to check C++ compiler +:check_compiler +call :print_status "Checking C++ compiler..." + +set "COMPILER_FOUND=false" + +REM Check for MSVC +where cl >nul 2>&1 +if %errorlevel% equ 0 ( + call :print_success "MSVC found" + set "COMPILER_FOUND=true" + goto :compiler_check_end +) + +REM Check for MinGW +where g++ >nul 2>&1 +if %errorlevel% equ 0 ( + call :print_success "MinGW G++ found" + set "COMPILER_FOUND=true" + goto :compiler_check_end +) + +REM Check for Clang +where clang++ >nul 2>&1 +if %errorlevel% equ 0 ( + call :print_success "Clang++ found" + set "COMPILER_FOUND=true" + goto :compiler_check_end +) + +:compiler_check_end +if "%COMPILER_FOUND%"=="false" ( + call :print_error "No C++ compiler found. Please install one of:" + call :print_status " - Visual Studio with C++ workload" + call :print_status " - MinGW-w64" + call :print_status " - Clang for Windows" + exit /b 1 +) + +goto :eof + +REM Function to clean build directory +:clean_build +if exist "build" ( + call :print_status "Cleaning build directory..." + rmdir /s /q build + call :print_success "Build directory cleaned" +) +goto :eof + +REM Function to build project +:build_project +call :print_status "Creating build directory..." +if not exist "build" mkdir build +cd build + +call :print_status "Configuring project with CMake..." +cmake .. -DCMAKE_BUILD_TYPE=Release +if %errorlevel% neq 0 ( + call :print_error "CMake configuration failed" + exit /b 1 +) + +call :print_status "Building project..." +cmake --build . --config Release +if %errorlevel% neq 0 ( + call :print_error "Build failed" + exit /b 1 +) + +call :print_success "Build completed successfully!" + +REM Check if executable was created +if exist "%PROJECT_NAME%.exe" ( + call :print_success "Executable created: %PROJECT_NAME%.exe" + call :print_status "You can run it with: %PROJECT_NAME%.exe" +) else ( + call :print_error "Executable not found after build" + exit /b 1 +) + +cd .. +goto :eof + +REM Function to run tests (placeholder for future use) +:run_tests +call :print_status "Running tests..." +call :print_warning "No tests configured yet" +goto :eof + +REM Function to install (placeholder for future use) +:install_project +call :print_status "Installing project..." +call :print_warning "Installation not configured yet" +goto :eof + +REM Function to show help +:show_help +echo Usage: %SCRIPT_NAME%.bat [OPTIONS] +echo. +echo Options: +echo -h, --help Show this help message +echo -c, --clean Clean build directory before building +echo -t, --test Run tests after building +echo -i, --install Install the project +echo --check-only Only check dependencies without building +echo. +echo Examples: +echo %SCRIPT_NAME%.bat # Build the project +echo %SCRIPT_NAME%.bat -c # Clean and build +echo %SCRIPT_NAME%.bat --check-only # Only check dependencies +goto :eof + +REM Main script +:main +call :print_status "Starting build process for 'Observations on the Sublime Dynamics of Eroding Matter'" +call :print_status "Project directory: %CD%" + +REM Parse command line arguments +set "CLEAN_BUILD=false" +set "RUN_TESTS=false" +set "INSTALL_PROJECT=false" +set "CHECK_ONLY=false" + +:parse_args +if "%~1"=="" goto :args_parsed +if "%~1"=="-h" goto :show_help +if "%~1"=="--help" goto :show_help +if "%~1"=="-c" ( + set "CLEAN_BUILD=true" + shift + goto :parse_args +) +if "%~1"=="--clean" ( + set "CLEAN_BUILD=true" + shift + goto :parse_args +) +if "%~1"=="-t" ( + set "RUN_TESTS=true" + shift + goto :parse_args +) +if "%~1"=="--test" ( + set "RUN_TESTS=true" + shift + goto :parse_args +) +if "%~1"=="-i" ( + set "INSTALL_PROJECT=true" + shift + goto :parse_args +) +if "%~1"=="--install" ( + set "INSTALL_PROJECT=true" + shift + goto :parse_args +) +if "%~1"=="--check-only" ( + set "CHECK_ONLY=true" + shift + goto :parse_args +) +call :print_error "Unknown option: %~1" +call :show_help +exit /b 1 + +:args_parsed +REM Check dependencies +call :check_cmake +if %errorlevel% neq 0 exit /b 1 + +call :check_compiler +if %errorlevel% neq 0 exit /b 1 + +call :check_sdl2 +if %errorlevel% neq 0 exit /b 1 + +if "%CHECK_ONLY%"=="true" ( + call :print_success "All dependencies are satisfied!" + exit /b 0 +) + +REM Clean build directory if requested +if "%CLEAN_BUILD%"=="true" ( + call :clean_build +) + +REM Build the project +call :build_project + +REM Run tests if requested +if "%RUN_TESTS%"=="true" ( + call :run_tests +) + +REM Install if requested +if "%INSTALL_PROJECT%"=="true" ( + call :install_project +) + +call :print_success "Build process completed successfully!" +exit /b 0 + +REM Entry point +if "%~1"=="-h" goto :show_help +if "%~1"=="--help" goto :show_help +goto :main diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..684a835 --- /dev/null +++ b/build.sh @@ -0,0 +1,256 @@ +#!/bin/bash + +# Build script for "Observations on the Sublime Dynamics of Eroding Matter" +# A C++ project using SDL2 + +set -e # Exit on any error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Function to print colored output +print_status() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Function to check if command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Function to check SDL2 installation +check_sdl2() { + print_status "Checking SDL2 installation..." + + if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + if command_exists brew; then + if brew list sdl2 >/dev/null 2>&1; then + print_success "SDL2 found via Homebrew" + return 0 + else + print_warning "SDL2 not found. Installing via Homebrew..." + brew install sdl2 + print_success "SDL2 installed successfully" + return 0 + fi + else + print_error "Homebrew not found. Please install Homebrew first: https://brew.sh/" + return 1 + fi + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux + if command_exists pkg-config; then + if pkg-config --exists sdl2; then + print_success "SDL2 found via pkg-config" + return 0 + else + print_warning "SDL2 not found. Please install libsdl2-dev:" + print_status " Ubuntu/Debian: sudo apt-get install libsdl2-dev" + print_status " Fedora: sudo dnf install SDL2-devel" + print_status " Arch: sudo pacman -S sdl2" + return 1 + fi + else + print_error "pkg-config not found. Please install it first." + return 1 + fi + else + print_error "Unsupported operating system: $OSTYPE" + return 1 + fi +} + +# Function to check CMake +check_cmake() { + print_status "Checking CMake installation..." + + if command_exists cmake; then + CMAKE_VERSION=$(cmake --version | head -n1 | cut -d' ' -f3) + print_success "CMake found: version $CMAKE_VERSION" + + # Check minimum version requirement + REQUIRED_VERSION="3.16.0" + if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$CMAKE_VERSION" | sort -V | head -n1)" = "$REQUIRED_VERSION" ]; then + print_success "CMake version meets requirement (>= $REQUIRED_VERSION)" + else + print_error "CMake version $CMAKE_VERSION is too old. Required: >= $REQUIRED_VERSION" + return 1 + fi + else + print_error "CMake not found. Please install CMake first:" + print_status " macOS: brew install cmake" + print_status " Ubuntu/Debian: sudo apt-get install cmake" + print_status " Or download from: https://cmake.org/download/" + return 1 + fi +} + +# Function to check C++ compiler +check_compiler() { + print_status "Checking C++ compiler..." + + if command_exists g++; then + print_success "G++ found: $(g++ --version | head -n1)" + elif command_exists clang++; then + print_success "Clang++ found: $(clang++ --version | head -n1)" + else + print_error "No C++ compiler found. Please install g++ or clang++" + return 1 + fi +} + +# Function to clean build directory +clean_build() { + if [ -d "build" ]; then + print_status "Cleaning build directory..." + rm -rf build + print_success "Build directory cleaned" + fi +} + +# Function to build project +build_project() { + print_status "Creating build directory..." + mkdir -p build + cd build + + print_status "Configuring project with CMake..." + cmake .. -DCMAKE_BUILD_TYPE=Release + + print_status "Building project..." + make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4) + + print_success "Build completed successfully!" + + # Check if executable was created + if [ -f "observations-on-the-sublime-dynamics-of-eroding-matter" ]; then + print_success "Executable created: observations-on-the-sublime-dynamics-of-eroding-matter" + print_status "You can run it with: ./observations-on-the-sublime-dynamics-of-eroding-matter" + else + print_error "Executable not found after build" + exit 1 + fi +} + +# Function to run tests (placeholder for future use) +run_tests() { + print_status "Running tests..." + # Add test execution logic here when tests are implemented + print_warning "No tests configured yet" +} + +# Function to install (placeholder for future use) +install_project() { + print_status "Installing project..." + # Add installation logic here when needed + print_warning "Installation not configured yet" +} + +# Function to show help +show_help() { + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " -h, --help Show this help message" + echo " -c, --clean Clean build directory before building" + echo " -t, --test Run tests after building" + echo " -i, --install Install the project" + echo " --check-only Only check dependencies without building" + echo "" + echo "Examples:" + echo " $0 # Build the project" + echo " $0 -c # Clean and build" + echo " $0 --check-only # Only check dependencies" +} + +# Main script +main() { + print_status "Starting build process for 'Observations on the Sublime Dynamics of Eroding Matter'" + print_status "Project directory: $(pwd)" + + # Parse command line arguments + CLEAN_BUILD=false + RUN_TESTS=false + INSTALL_PROJECT=false + CHECK_ONLY=false + + while [[ $# -gt 0 ]]; do + case $1 in + -h|--help) + show_help + exit 0 + ;; + -c|--clean) + CLEAN_BUILD=true + shift + ;; + -t|--test) + RUN_TESTS=true + shift + ;; + -i|--install) + INSTALL_PROJECT=true + shift + ;; + --check-only) + CHECK_ONLY=true + shift + ;; + *) + print_error "Unknown option: $1" + show_help + exit 1 + ;; + esac + done + + # Check dependencies + check_cmake || exit 1 + check_compiler || exit 1 + check_sdl2 || exit 1 + + if [ "$CHECK_ONLY" = true ]; then + print_success "All dependencies are satisfied!" + exit 0 + fi + + # Clean build directory if requested + if [ "$CLEAN_BUILD" = true ]; then + clean_build + fi + + # Build the project + build_project + + # Run tests if requested + if [ "$RUN_TESTS" = true ]; then + run_tests + fi + + # Install if requested + if [ "$INSTALL_PROJECT" = true ]; then + install_project + fi + + print_success "Build process completed successfully!" +} + +# Run main function with all arguments +main "$@"