#!/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/release" 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 -S "${ROOT_DIR}" -B "${BUILD_DIR}" -DCMAKE_BUILD_TYPE=RelWithDebInfo 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" ln -sf "ava2_client" "${BUNDLE_DIR}/Contents/MacOS/AVA2" 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 if [ -f "${ROOT_DIR}/support/mac/AppIcon.icns" ]; then cp "${ROOT_DIR}/support/mac/AppIcon.icns" "${BUNDLE_DIR}/Contents/Resources/AppIcon.icns" fi # 4. Package core game assets into Bundle Resources echo "[4/5] Packaging client assets into bundle..." EXTRA_PACK_ARGS="" if [ "${1:-}" = "--full" ] || [ "${1:-}" = "--include-heavy" ]; then echo " (Including heavy 3D assets & BGM)" EXTRA_PACK_ARGS="--include-heavy" fi python3 "${ROOT_DIR}/tools/pack_assets.py" \ --source "${ROOT_DIR}" \ --output "${BUNDLE_DIR}/Contents/Resources" \ --manifest "${BUNDLE_DIR}/Contents/Resources/asset_manifest.json" \ ${EXTRA_PACK_ARGS} # Install Python runtime & script root if [ -f "${BUILD_DIR}/python27.zip" ]; then echo " Installing python27.zip standard library..." cp "${BUILD_DIR}/python27.zip" "${BUNDLE_DIR}/Contents/Resources/python27.zip" fi echo " Python script root installed through the resource manifest." if [ -f "${ROOT_DIR}/runtime/login_view.py" ]; then cp "${ROOT_DIR}/runtime/login_view.py" "${BUNDLE_DIR}/Contents/Resources/login_view.py" fi # Resolve every virtual resource directory, including patch-pack directories. # All links stay inside the bundle; --full copies heavy assets as well. python3 - "${BUNDLE_DIR}" "${ROOT_DIR}" <<'PYLINK' from pathlib import Path import sys bundle, source = map(Path, sys.argv[1:]) resources = bundle / "Contents/Resources" macos = bundle / "Contents/MacOS" for item in resources.iterdir(): link = macos / item.name if not link.exists() and not link.is_symlink(): link.symlink_to(Path("../Resources") / item.name) for name in ("ymir work", "bgm"): src_dir = source / "assets/loose" / name if (source / "assets/loose" / name).is_dir() else (source / name) if not (resources / name).exists() and src_dir.is_dir(): (resources / name).symlink_to(src_dir) (macos / name).symlink_to(Path("../Resources") / name) if not (resources / "UIScript").exists(): (resources / "UIScript").symlink_to("uiscript") if not (resources / "root/UIScript").exists(): (resources / "root/UIScript").symlink_to("uiscript") (resources / "upstream").mkdir(exist_ok=True) link = resources / "upstream/python-root" if not link.exists(): link.symlink_to("../root") PYLINK cd "${ROOT_DIR}" # Include SDL3 and all optional font libraries, with their transitive dependencies. python3 "${ROOT_DIR}/tools/bundle_macos_libraries.py" "${BUNDLE_DIR}" # 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 "=========================================================="