#!/usr/bin/env bash # # Build dolphin-tool from Dolphin Emulator # # Builds only the command-line tool (not the full emulator) # For RVZ compression of Wii/GameCube ISOs # set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SRC_DIR="${SCRIPT_DIR}/src" BUILD_DIR="${SCRIPT_DIR}/build" TOOLS_BIN_DIR="${SCRIPT_DIR}/../bin" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "Building dolphin-tool (RVZ compression tool)" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" # Check if source exists if [ ! -d "${SRC_DIR}" ]; then echo "❌ Source directory not found: ${SRC_DIR}" echo " Run ./clone.sh first!" exit 1 fi # Check for required tools echo "🔍 Checking build dependencies..." MISSING_DEPS=() if ! command -v cmake &> /dev/null; then MISSING_DEPS+=("cmake") fi if ! command -v g++ &> /dev/null; then MISSING_DEPS+=("g++") fi if ! command -v pkg-config &> /dev/null; then MISSING_DEPS+=("pkg-config") fi # Check for required libraries MISSING_LIBS=() if ! pkg-config --exists zlib 2>/dev/null; then MISSING_LIBS+=("zlib1g-dev") fi if ! pkg-config --exists liblzma 2>/dev/null; then MISSING_LIBS+=("liblzma-dev") fi if ! pkg-config --exists libzstd 2>/dev/null; then MISSING_LIBS+=("libzstd-dev") fi if ! pkg-config --exists fmt 2>/dev/null; then echo " ⚠️ libfmt-dev not found (may use internal version)" fi if [ ${#MISSING_DEPS[@]} -gt 0 ]; then echo "❌ Missing required tools: ${MISSING_DEPS[*]}" echo "" echo "Install with:" echo " sudo apt-get install cmake build-essential pkg-config" exit 1 fi if [ ${#MISSING_LIBS[@]} -gt 0 ]; then echo "❌ Missing required libraries: ${MISSING_LIBS[*]}" echo "" echo "Install with:" echo " sudo apt-get install ${MISSING_LIBS[*]}" exit 1 fi echo " ✅ cmake found: $(cmake --version | head -1)" echo " ✅ g++ found: $(g++ --version | head -1)" echo "" # Create build directory mkdir -p "${BUILD_DIR}" cd "${BUILD_DIR}" # Record build start time BUILD_START=$(date +%s) echo "🔨 Configuring dolphin-tool with CMake..." echo " Source: ${SRC_DIR}" echo " Build: ${BUILD_DIR}" echo "" # Configure with CMake # Build only the tool, not the full emulator cmake "${SRC_DIR}" \ -DCMAKE_BUILD_TYPE=Release \ -DENABLE_CLI_TOOL=ON \ -DENABLE_QT=OFF \ -DENABLE_LTO=ON \ -DUSE_SHARED_ENET=OFF \ -DCMAKE_INSTALL_PREFIX="${BUILD_DIR}/install" echo "" echo "🔨 Building dolphin-tool..." echo " Using $(nproc) parallel jobs..." echo "" # Build only the dolphin-tool target make -j$(nproc) dolphin-tool 2>&1 | tee "${SCRIPT_DIR}/build.log" # Record build end time BUILD_END=$(date +%s) BUILD_DURATION=$((BUILD_END - BUILD_START)) echo "" echo "✅ Build complete in ${BUILD_DURATION} seconds!" echo "" # Find and copy the binary echo "📦 Locating dolphin-tool binary..." TOOL_PATH="" if [ -f "Binaries/dolphin-tool" ]; then TOOL_PATH="Binaries/dolphin-tool" elif [ -f "dolphin-tool" ]; then TOOL_PATH="dolphin-tool" elif [ -f "Source/Core/DolphinTool/dolphin-tool" ]; then TOOL_PATH="Source/Core/DolphinTool/dolphin-tool" else echo "❌ dolphin-tool binary not found!" echo " Searched in:" echo " - Binaries/dolphin-tool" echo " - dolphin-tool" echo " - Source/Core/DolphinTool/dolphin-tool" exit 1 fi # Copy to our build directory cp "${TOOL_PATH}" "${BUILD_DIR}/dolphin-tool" chmod +x "${BUILD_DIR}/dolphin-tool" echo " ✅ Found: ${TOOL_PATH}" echo "" # Show binary info BINARY_SIZE=$(du -h "${BUILD_DIR}/dolphin-tool" | cut -f1) echo "📦 Binary Information:" echo " Path: ${BUILD_DIR}/dolphin-tool" echo " Size: ${BINARY_SIZE}" echo "" # Test binary echo "🧪 Testing binary..." if "${BUILD_DIR}/dolphin-tool" --version &>/dev/null; then VERSION=$("${BUILD_DIR}/dolphin-tool" --version 2>&1 | head -1) echo " ✅ ${VERSION}" elif "${BUILD_DIR}/dolphin-tool" help &>/dev/null; then echo " ✅ Binary responds to help command" else echo " ⚠️ Binary built but version check returned unexpected output" fi echo "" # Create symlink in tools/bin/ mkdir -p "${TOOLS_BIN_DIR}" ln -sf "${BUILD_DIR}/dolphin-tool" "${TOOLS_BIN_DIR}/dolphin-tool" echo "🔗 Symlink created: ${TOOLS_BIN_DIR}/dolphin-tool → ${BUILD_DIR}/dolphin-tool" echo "" # Save build info BUILD_INFO_FILE="${SCRIPT_DIR}/BUILD_INFO.txt" { echo "dolphin-tool build information" echo "==============================" echo "" echo "Build date: $(date -u +%Y-%m-%d\ %H:%M:%S\ UTC)" echo "Build duration: ${BUILD_DURATION} seconds" echo "Build system: $(uname -s) $(uname -m)" echo "Compiler: $(g++ --version | head -1)" echo "CMake: $(cmake --version | head -1)" echo "Parallel jobs: $(nproc)" echo "" echo "Binary:" echo " Path: ${BUILD_DIR}/dolphin-tool" echo " Size: ${BINARY_SIZE}" echo " MD5: $(md5sum "${BUILD_DIR}/dolphin-tool" | cut -d' ' -f1)" echo "" if "${BUILD_DIR}/dolphin-tool" --version &>/dev/null; then VERSION=$("${BUILD_DIR}/dolphin-tool" --version 2>&1 | head -1) echo " Version: ${VERSION}" fi echo "" echo "Symlink:" echo " ${TOOLS_BIN_DIR}/dolphin-tool → ${BUILD_DIR}/dolphin-tool" } > "${BUILD_INFO_FILE}" echo "📄 Build info saved to: ${BUILD_INFO_FILE}" echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "✅ dolphin-tool is ready to use!" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "Usage examples:" echo " # Convert ISO to RVZ (best compression!)" echo " ${TOOLS_BIN_DIR}/dolphin-tool convert -f rvz -i game.iso -o game.rvz" echo "" echo " # Convert RVZ back to ISO" echo " ${TOOLS_BIN_DIR}/dolphin-tool convert -f iso -i game.rvz -o game.iso" echo "" echo " # Verify disc image" echo " ${TOOLS_BIN_DIR}/dolphin-tool verify -i game.iso" echo ""