256 lines
7.1 KiB
Bash
Executable file
256 lines
7.1 KiB
Bash
Executable file
#!/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 "$@"
|