#!/usr/bin/env bash # # Build wud-compress # # Builds the Wii U disc image compression tool # Creates WUX (compressed WUD) files # 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 wud-compress" 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 g++ &> /dev/null; then MISSING_DEPS+=("g++") fi if [ ${#MISSING_DEPS[@]} -gt 0 ]; then echo "❌ Missing required dependencies: ${MISSING_DEPS[*]}" echo "" echo "Install with:" echo " sudo apt-get install build-essential" exit 1 fi echo " ✅ g++ found: $(g++ --version | head -1)" echo "" # Create build directory mkdir -p "${BUILD_DIR}" cd "${SRC_DIR}" # Record build start time BUILD_START=$(date +%s) echo "🔨 Compiling wud-compress..." echo " Source: ${SRC_DIR}" echo " Output: ${BUILD_DIR}" echo "" # This is a Visual Studio project, so compile manually with Linux compatibility echo " Compiling from source files..." cd WudCompress # Compile with Linux compatibility macros # Replace Windows-specific functions with Linux equivalents g++ -std=c++11 -O3 -D_FILE_OFFSET_BITS=64 \ -D_ftelli64=ftello64 \ -D_fseeki64=fseeko64 \ -Dstricmp=strcasecmp \ -o "${BUILD_DIR}/wud-compress" \ main.cpp wud.cpp # Record build end time BUILD_END=$(date +%s) BUILD_DURATION=$((BUILD_END - BUILD_START)) echo "" echo "✅ Build complete in ${BUILD_DURATION} seconds!" echo "" # Verify binary if [ ! -f "${BUILD_DIR}/wud-compress" ]; then echo "❌ Binary not found: ${BUILD_DIR}/wud-compress" exit 1 fi # Make executable chmod +x "${BUILD_DIR}/wud-compress" # Show binary info BINARY_SIZE=$(du -h "${BUILD_DIR}/wud-compress" | cut -f1) echo "📦 Binary Information:" echo " Path: ${BUILD_DIR}/wud-compress" echo " Size: ${BINARY_SIZE}" echo " Permissions: $(stat -c %A "${BUILD_DIR}/wud-compress")" echo "" # Test binary echo "🧪 Testing binary..." if "${BUILD_DIR}/wud-compress" --help &>/dev/null || "${BUILD_DIR}/wud-compress" 2>&1 | grep -i "usage\|wud" &>/dev/null; then echo " ✅ Binary responds to commands" else echo " ⚠️ Binary may not support --help (this is normal)" fi echo "" # Create symlink in tools/bin/ mkdir -p "${TOOLS_BIN_DIR}" ln -sf "${BUILD_DIR}/wud-compress" "${TOOLS_BIN_DIR}/wud-compress" echo "🔗 Symlink created: ${TOOLS_BIN_DIR}/wud-compress → ${BUILD_DIR}/wud-compress" echo "" # Save build info BUILD_INFO_FILE="${SCRIPT_DIR}/BUILD_INFO.txt" { echo "wud-compress 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 "Parallel jobs: $(nproc)" echo "" echo "Binary:" echo " Path: ${BUILD_DIR}/wud-compress" echo " Size: ${BINARY_SIZE}" echo " MD5: $(md5sum "${BUILD_DIR}/wud-compress" | cut -d' ' -f1)" echo "" echo "Symlink:" echo " ${TOOLS_BIN_DIR}/wud-compress → ${BUILD_DIR}/wud-compress" } > "${BUILD_INFO_FILE}" echo "📄 Build info saved to: ${BUILD_INFO_FILE}" echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "✅ wud-compress is ready to use!" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "Usage:" echo " ${TOOLS_BIN_DIR}/wud-compress compress game.wud game.wux" echo " ${TOOLS_BIN_DIR}/wud-compress decompress game.wux game.wud" echo ""