#!/bin/bash set -e # Build maxcso from source # High-performance PSP ISO compression tool SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" MAXCSO_DIR="$SCRIPT_DIR/src" BUILD_DIR="$SCRIPT_DIR/build" BIN_DIR="$SCRIPT_DIR/../bin" echo "╔════════════════════════════════════════════════════════════════╗" echo "║ Build maxcso (PSP) ║" echo "╚════════════════════════════════════════════════════════════════╝" echo "" # Check if source exists if [ ! -d "$MAXCSO_DIR" ]; then echo "❌ maxcso source not found!" echo " Please run ./clone.sh first to download the source." exit 1 fi cd "$MAXCSO_DIR" # Show version info if [ -f "$SCRIPT_DIR/VERSION.txt" ]; then echo "📝 Building from:" grep -E "^(Short|Tag|Date):" "$SCRIPT_DIR/VERSION.txt" | sed 's/^/ /' echo "" fi # Check dependencies echo "🔍 Checking build dependencies..." echo "" MISSING_DEPS=() # Check for make if ! command -v make &> /dev/null; then MISSING_DEPS+=("make") fi # Check for g++ or clang++ if ! command -v g++ &> /dev/null && ! command -v clang++ &> /dev/null; then MISSING_DEPS+=("g++ or clang++") fi # Check for libuv (optional but recommended) if ! pkg-config --exists libuv 2>/dev/null; then echo "⚠️ libuv not found - will use bundled version" fi # Check for lz4 (optional but recommended) if ! pkg-config --exists liblz4 2>/dev/null; then echo "⚠️ liblz4 not found - will use bundled version" fi # Check for zlib if ! pkg-config --exists zlib 2>/dev/null; then echo "⚠️ zlib not found - some features may be disabled" fi if [ ${#MISSING_DEPS[@]} -gt 0 ]; then echo "" echo "⚠️ Missing dependencies: ${MISSING_DEPS[*]}" echo "" echo "Install with:" echo " sudo apt-get install build-essential libuv1-dev liblz4-dev zlib1g-dev" echo "" read -p "🤔 Try to continue anyway? (y/N) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi # Build configuration echo "" echo "🔧 Build configuration:" echo " Makefile build system" echo " Optimized build (-O2)" echo "" # Detect CPU cores for parallel build CORES=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4) echo " Using $CORES parallel jobs" echo "" # Clean old build (optional) if [ -f "maxcso" ]; then echo "" read -p "🧹 Clean previous build? (Y/n) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Nn]$ ]]; then echo "🧹 Cleaning previous build..." make clean 2>/dev/null || true fi fi echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🔨 Starting build..." echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "⏱️ This should take 10-30 seconds..." echo "" START_TIME=$(date +%s) # Run the build with parallel jobs if make -j"$CORES"; then END_TIME=$(date +%s) DURATION=$((END_TIME - START_TIME)) echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "✅ Build completed successfully in ${DURATION}s!" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" # Find the built binary MAXCSO_BIN="" if [ -f "maxcso" ]; then MAXCSO_BIN="$MAXCSO_DIR/maxcso" else echo "⚠️ Could not find built maxcso binary!" echo " Searching for it..." find . -name "maxcso" -type f 2>/dev/null exit 1 fi # Create build directory and copy binary mkdir -p "$BUILD_DIR" cp "$MAXCSO_BIN" "$BUILD_DIR/maxcso" chmod +x "$BUILD_DIR/maxcso" # Get binary size SIZE=$(du -h "$BUILD_DIR/maxcso" | cut -f1) echo "📦 Binary copied to: $BUILD_DIR/maxcso ($SIZE)" # Create symlink in bin directory mkdir -p "$BIN_DIR" ln -sf "../maxcso/build/maxcso" "$BIN_DIR/maxcso" echo "🔗 Symlink created: $BIN_DIR/maxcso" # Save build info BUILD_INFO_FILE="$BUILD_DIR/BUILD_INFO.txt" cat > "$BUILD_INFO_FILE" << EOF maxcso Build Information Built: $(date) Build time: ${DURATION}s Source: $(cat "$SCRIPT_DIR/VERSION.txt" 2>/dev/null || echo "Version info not available") Build options: Command: make -j${CORES} Compiler: $(g++ --version 2>/dev/null | head -1 || clang++ --version 2>/dev/null | head -1 || echo "unknown") Parallel jobs: ${CORES} Binary: Path: $BUILD_DIR/maxcso Size: $SIZE Test: EOF echo "" echo "🧪 Testing built binary..." "$BUILD_DIR/maxcso" --help 2>&1 | head -15 >> "$BUILD_INFO_FILE" "$BUILD_DIR/maxcso" --help 2>&1 | head -15 echo "" cat "$BUILD_INFO_FILE" echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "✅ All done!" echo "" echo "Usage:" echo " $BIN_DIR/maxcso --help" echo "" echo "Common operations:" echo " # Compress PSP ISO to CSO" echo " $BIN_DIR/maxcso game.iso" echo "" echo " # Compress with best compression" echo " $BIN_DIR/maxcso --block=2048 game.iso" echo "" echo " # Decompress CSO back to ISO" echo " $BIN_DIR/maxcso --decompress game.cso" echo "" echo " # Show compression info" echo " $BIN_DIR/maxcso --info game.cso" echo "" echo "Or add to PATH:" echo " export PATH=\"$BIN_DIR:\$PATH\"" echo " maxcso --help" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" else echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "❌ Build failed!" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "Common issues:" echo " 1. Missing build-essential - install with: apt-get install build-essential" echo " 2. Missing dependencies - install with: apt-get install libuv1-dev liblz4-dev zlib1g-dev" echo " 3. Check build output above for specific errors" echo "" exit 1 fi