#!/bin/bash set -euo pipefail # ELF building export MXL_SOURCE=/Users/jitten/extra/mxl export MXL_BUILD="${MXL_SOURCE}/build/Darwin-Clang-Release" WORK_DIR="$(mktemp -d)" trap 'rm -rf "${WORK_DIR}"' EXIT # libmxl.pc in the build tree hardcodes the install/ prefix; rewrite it so # cgo's pkg-config lookup gets the build tree's lib/include dirs. sed -e "s|${MXL_SOURCE}/install|${MXL_SOURCE}/build|g" \ -e "s|^includedir=.*|includedir=${MXL_BUILD}/lib/include|" \ "${MXL_BUILD}/lib/libmxl.pc" > "${WORK_DIR}/libmxl.pc" export PKG_CONFIG_PATH="${WORK_DIR}:${MXL_BUILD}/lib${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" export CGO_CFLAGS="-I${MXL_SOURCE}/lib/include" export CGO_LDFLAGS="-L${MXL_BUILD}/lib" PLAYER_ELF_PATH="./build/mxl-player" go build \ -trimpath \ -ldflags="-s -w" \ -o "${PLAYER_ELF_PATH}" \ ./cmd/mxl-player # MacOS .app package export APP_BUNDLE="./release/mac/MXL-player.app" rm -rf "${APP_BUNDLE}" mkdir -p "${APP_BUNDLE}/Contents/MacOS" mkdir -p "${APP_BUNDLE}/Contents/Frameworks" mkdir -p "${APP_BUNDLE}/Contents/Resources" cp "${PLAYER_ELF_PATH}" "${APP_BUNDLE}/Contents/MacOS/mxl-player" chmod 0755 "${APP_BUNDLE}/Contents/MacOS/mxl-player" # App icon ICONSET="${WORK_DIR}/MXL-player.iconset" mkdir -p "${ICONSET}" for s in 16 32 128 256 512; do sips -z $s $s ./assets/mxl-on-blue-square.png \ --out "${ICONSET}/icon_${s}x${s}.png" > /dev/null sips -z $((s*2)) $((s*2)) ./assets/mxl-on-blue-square.png \ --out "${ICONSET}/icon_${s}x${s}@2x.png" > /dev/null done iconutil -c icns "${ICONSET}" \ -o "${APP_BUNDLE}/Contents/Resources/AppIcon.icns" # Info.plist cat << EOF > "${APP_BUNDLE}/Contents/Info.plist" CFBundleName MXL Player CFBundleDisplayName MXL Player CFBundleIdentifier io.github.jitten.mxl-player CFBundleExecutable mxl-player CFBundlePackageType APPL CFBundleShortVersionString 0.1.0 CFBundleVersion 1 LSMinimumSystemVersion 13.0 NSHighResolutionCapable LSApplicationCategoryType public.app-category.video CFBundleIconFile AppIcon EOF plutil -lint "${APP_BUNDLE}/Contents/Info.plist" # copy runtime libs (install IDs must stay untouched: libmxl is already # @rpath/libmxl.1.dylib from the build tree; SDL3/MoltenVK are dlopen'ed by # leaf name, so their IDs are never referenced) cp -L "${MXL_BUILD}/lib/libmxl.1.dylib" \ "${APP_BUNDLE}/Contents/Frameworks/libmxl.1.dylib" cp -L "$(brew --prefix sdl3)/lib/libSDL3.0.dylib" \ "${APP_BUNDLE}/Contents/Frameworks/libSDL3.0.dylib" cp -L "$(brew --prefix molten-vk)/lib/libMoltenVK.dylib" \ "${APP_BUNDLE}/Contents/Frameworks/libMoltenVK.dylib" # resolve @rpath/libmxl.1.dylib and the dlopen'ed SDL3/MoltenVK leaf names # against the bundle's Frameworks dir install_name_tool \ -add_rpath "@loader_path/../Frameworks" \ "${APP_BUNDLE}/Contents/MacOS/mxl-player" # install_name_tool invalidated the executable's ad-hoc signature; re-sign codesign --force --sign - "${APP_BUNDLE}" codesign --verify "${APP_BUNDLE}" env -u SDL3_LIBRARY \ -u VULKAN_LIBRARY \ -u DYLD_LIBRARY_PATH \ "${APP_BUNDLE}/Contents/MacOS/mxl-player" # compress, preserve MacOS bundle meta ditto -c -k \ --sequesterRsrc \ --keepParent \ "${APP_BUNDLE}" \ ./release/mac/mxl-player-0.1.0-macos-arm64.zip