#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" BUILD_DIR="${ROOT_DIR}/build/dev" DIST_DIR="${ROOT_DIR}/dist" APP_NAME="AVA2" BUNDLE_DIR="${DIST_DIR}/${APP_NAME}.app" echo "==========================================================" echo " AVA2 Metin2 Client — macOS App Packaging Tool" echo "==========================================================" echo "Root Dir: ${ROOT_DIR}" echo "Build Dir: ${BUILD_DIR}" echo "Dist Dir: ${DIST_DIR}" echo "Bundle: ${BUNDLE_DIR}" echo "" # 1. Compile client targets if needed echo "[1/5] Building native targets..." cmake --build "${BUILD_DIR}" --target ava2_client -j8 # 2. Setup bundle structure echo "[2/5] Creating macOS Application Bundle directory tree..." rm -rf "${BUNDLE_DIR}" mkdir -p "${BUNDLE_DIR}/Contents/MacOS" mkdir -p "${BUNDLE_DIR}/Contents/Resources" mkdir -p "${BUNDLE_DIR}/Contents/Frameworks" # 3. Copy binary echo "[3/5] Installing executable and Info.plist..." cp "${BUILD_DIR}/ava2_client" "${BUNDLE_DIR}/Contents/MacOS/ava2_client" chmod +x "${BUNDLE_DIR}/Contents/MacOS/ava2_client" if [ -f "${ROOT_DIR}/support/mac/Info.plist.in" ]; then cp "${ROOT_DIR}/support/mac/Info.plist.in" "${BUNDLE_DIR}/Contents/Info.plist" fi # 4. Package core game assets into Bundle Resources echo "[4/5] Packaging client assets into bundle..." python3 "${SCRIPT_DIR}/pack_assets.py" \ --source "${ROOT_DIR}" \ --output "${BUNDLE_DIR}/Contents/Resources" \ --manifest "${BUNDLE_DIR}/Contents/Resources/asset_manifest.json" # Symlink resources relative to MacOS folder for direct path resolution cd "${BUNDLE_DIR}/Contents/MacOS" ln -sf "../Resources/mark" mark ln -sf "../Resources/locale" locale ln -sf "../Resources/uiscript" uiscript ln -sf "../Resources/textureset" textureset ln -sf "../Resources/sound" sound ln -sf "../Resources/runtime" runtime ln -sf "../Resources/upstream" upstream cd "${ROOT_DIR}" # Bundle and relocate SDL3 dylib for self-contained deployment if [ -f "/opt/homebrew/opt/sdl3/lib/libSDL3.0.dylib" ]; then echo "[4.1/5] Bundling SDL3.0.dylib into Frameworks..." cp "/opt/homebrew/opt/sdl3/lib/libSDL3.0.dylib" "${BUNDLE_DIR}/Contents/Frameworks/" install_name_tool -change "/opt/homebrew/opt/sdl3/lib/libSDL3.0.dylib" "@executable_path/../Frameworks/libSDL3.0.dylib" "${BUNDLE_DIR}/Contents/MacOS/ava2_client" install_name_tool -id "@executable_path/../Frameworks/libSDL3.0.dylib" "${BUNDLE_DIR}/Contents/Frameworks/libSDL3.0.dylib" echo "[4.2/5] Ad-hoc signing bundle binaries for macOS arm64..." codesign -f -s - "${BUNDLE_DIR}/Contents/Frameworks/libSDL3.0.dylib" codesign -f -s - "${BUNDLE_DIR}/Contents/MacOS/ava2_client" fi # 5. Create Distribution Archive echo "[5/5] Creating release distribution tarball..." cd "${DIST_DIR}" tar -czf "${APP_NAME}-macOS-arm64.tar.gz" "${APP_NAME}.app" cd "${ROOT_DIR}" BUNDLE_SIZE=$(du -sh "${BUNDLE_DIR}" | cut -f1) ARCHIVE_SIZE=$(du -sh "${DIST_DIR}/${APP_NAME}-macOS-arm64.tar.gz" | cut -f1) echo "" echo "==========================================================" echo " Packaging Succeeded!" echo " Bundle: ${BUNDLE_DIR} (${BUNDLE_SIZE})" echo " Archive: ${DIST_DIR}/${APP_NAME}-macOS-arm64.tar.gz (${ARCHIVE_SIZE})" echo "=========================================================="