#!/bin/bash set -e # Build extract-xiso from source # Tool for creating and extracting Xbox ISO images SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" XISO_DIR="$SCRIPT_DIR/src" BUILD_DIR="$SCRIPT_DIR/build" BIN_DIR="$SCRIPT_DIR/../bin" echo "╔════════════════════════════════════════════════════════════════╗" echo "║ Build extract-xiso Tool ║" echo "╚════════════════════════════════════════════════════════════════╝" echo "" # Check if source exists if [ ! -d "$XISO_DIR" ]; then echo "❌ extract-xiso source not found!" echo " Please run ./clone.sh first to download the source." exit 1 fi cd "$XISO_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=() if ! command -v gcc &> /dev/null && ! command -v clang &> /dev/null; then MISSING_DEPS+=("gcc or clang") fi if ! command -v cmake &> /dev/null; then MISSING_DEPS+=("cmake") fi if ! command -v make &> /dev/null; then MISSING_DEPS+=("make") fi if [ ${#MISSING_DEPS[@]} -gt 0 ]; then echo "⚠️ Missing dependencies: ${MISSING_DEPS[*]}" echo "" echo "Install with:" echo " sudo apt-get install build-essential cmake" echo "" read -p "🤔 Try to continue anyway? (y/N) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi fi # Build configuration echo "🔧 Build configuration:" echo " CMake build system" echo " Very fast build (seconds!)" echo "" # Create build directory inside src mkdir -p "$XISO_DIR/build" cd "$XISO_DIR/build" # Clean old build (optional) if [ -f "extract-xiso" ]; then echo "" read -p "🧹 Clean previous build? (Y/n) " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Nn]$ ]]; then echo "🧹 Cleaning previous build..." rm -rf * fi fi echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🔨 Starting build..." echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "⏱️ This should only take a few seconds..." echo "" START_TIME=$(date +%s) # Run CMake and build if cmake .. && make; 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 XISO_BIN="" if [ -f "extract-xiso" ]; then XISO_BIN="$XISO_DIR/build/extract-xiso" else echo "⚠️ Could not find built extract-xiso binary!" echo " Searching for it..." find . -name "extract-xiso" -type f 2>/dev/null exit 1 fi # Create build directory and copy binary mkdir -p "$BUILD_DIR" cp "$XISO_BIN" "$BUILD_DIR/extract-xiso" chmod +x "$BUILD_DIR/extract-xiso" echo "📦 Binary copied to: $BUILD_DIR/extract-xiso" # Create symlink in bin directory mkdir -p "$BIN_DIR" ln -sf "../extract-xiso/build/extract-xiso" "$BIN_DIR/extract-xiso" echo "🔗 Symlink created: $BIN_DIR/extract-xiso" echo "" # Test the binary echo "🧪 Testing built binary..." "$BUILD_DIR/extract-xiso" -v 2>&1 || "$BUILD_DIR/extract-xiso" -h 2>&1 | head -5 || true echo "" # Record build info BUILD_INFO="$BUILD_DIR/BUILD_INFO.txt" cat > "$BUILD_INFO" << EOF extract-xiso Build Information Built: $(date) Build time: ${DURATION}s Source: $(grep -E "^(Commit|Short|Tag|Date):" "$SCRIPT_DIR/VERSION.txt" 2>/dev/null || echo " No version info") Build options: Command: make Simple Makefile build Binary: Path: $BUILD_DIR/extract-xiso Size: $(du -h "$BUILD_DIR/extract-xiso" | cut -f1) Test: $("$BUILD_DIR/extract-xiso" -v 2>&1 || "$BUILD_DIR/extract-xiso" -h 2>&1 | head -10 || echo " Version test skipped") EOF cat "$BUILD_INFO" echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "✅ All done!" echo "" echo "Usage:" echo " $BIN_DIR/extract-xiso -h" echo "" echo "Common operations:" echo " # Create XISO from directory" echo " $BIN_DIR/extract-xiso -c game_directory -o game.iso" echo "" echo " # Extract XISO to directory" echo " $BIN_DIR/extract-xiso game.iso" echo "" echo "Or add to PATH:" echo " export PATH=\"$BIN_DIR:\$PATH\"" echo " extract-xiso -h" 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. Check if gcc/clang is installed: gcc --version" echo " 3. Check if make is installed: make --version" echo "" exit 1 fi