Skip to content

Instantly share code, notes, and snippets.

@erfg12
Created September 18, 2025 14:49
Show Gist options
  • Save erfg12/f475d4593c4ef6f0aa10eed5f66a0cff to your computer and use it in GitHub Desktop.
Save erfg12/f475d4593c4ef6f0aa10eed5f66a0cff to your computer and use it in GitHub Desktop.
Bundle SDL game MacOS app, code sign and make dmg for distribution
#!/bin/bash
# build_sdl_app.sh
# Builds SharkShark.app bundle (no signing)
# Assumes:
# - Folder "SharkShark" next to this script
# - Icon file "SharkShark.icns" next to this script
# - Executable SharkShark inside "SharkShark/"
# - SDL frameworks inside "SharkShark/"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SRC_FOLDER="$SCRIPT_DIR/SharkShark"
ICON_FILE="$SCRIPT_DIR/SharkShark.icns"
APP_NAME="SharkShark"
APP_PATH="$SCRIPT_DIR/$APP_NAME.app"
ENTITLEMENTS="$SCRIPT_DIR/$APP_NAME.entitlements.plist"
# --- Clean previous app ---
rm -rf "$APP_PATH"
# --- Create app bundle ---
mkdir -p "$APP_PATH/Contents/MacOS" "$APP_PATH/Contents/Resources" "$APP_PATH/Contents/Frameworks"
# Copy executable
cp "$SRC_FOLDER/$APP_NAME" "$APP_PATH/Contents/MacOS/"
# Copy frameworks
for FMWK in "$SRC_FOLDER"/*.framework; do
cp -R "$FMWK" "$APP_PATH/Contents/Frameworks/"
done
# Copy resources
cp -R "$SRC_FOLDER/res" "$APP_PATH/Contents/Resources/"
cp "$ICON_FILE" "$APP_PATH/Contents/Resources/AppIcon.icns"
# Create Info.plist
cat > "$APP_PATH/Contents/Info.plist" <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key><string>$APP_NAME</string>
<key>CFBundleDisplayName</key><string>$APP_NAME</string>
<key>CFBundleExecutable</key><string>$APP_NAME</string>
<key>CFBundleIdentifier</key><string>com.nas.$APP_NAME</string>
<key>CFBundleVersion</key><string>1.0</string>
<key>CFBundleShortVersionString</key><string>1.0</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>LSMinimumSystemVersion</key><string>10.13</string>
<key>CFBundleIconFile</key><string>AppIcon</string>
</dict>
</plist>
EOL
# Create entitlements file next to script
cat > "$ENTITLEMENTS" <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key><true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key><true/>
<key>com.apple.security.cs.disable-library-validation</key><true/>
</dict>
</plist>
EOL
# --- Fix rpaths and framework IDs ---
for FMWK in SDL2 SDL2_mixer SDL2_ttf; do
FPATH="$APP_PATH/Contents/Frameworks/$FMWK.framework/Versions/A/$FMWK"
install_name_tool -id @rpath/$FMWK.framework/Versions/A/$FMWK "$FPATH"
done
# Fix executable references
install_name_tool -change @rpath/SDL2.framework/Versions/A/SDL2 \
@executable_path/../Frameworks/SDL2.framework/Versions/A/SDL2 "$APP_PATH/Contents/MacOS/$APP_NAME"
install_name_tool -change @rpath/SDL2_mixer.framework/Versions/A/SDL2_mixer \
@executable_path/../Frameworks/SDL2_mixer.framework/Versions/A/SDL2_mixer "$APP_PATH/Contents/MacOS/$APP_NAME"
install_name_tool -change @rpath/SDL2_ttf.framework/Versions/A/SDL2_ttf \
@executable_path/../Frameworks/SDL2_ttf.framework/Versions/A/SDL2_ttf "$APP_PATH/Contents/MacOS/$APP_NAME"
echo "=== Build complete ==="
echo "App bundle ready at: $APP_PATH"
echo "Entitlements file created at: $ENTITLEMENTS"
echo "You can now sign and notarize separately."
#!/bin/bash
# sign_and_dmg.sh
# Signs SharkShark.app and creates a DMG for notarization
APP_NAME="SharkShark"
APP_PATH="$PWD/$APP_NAME.app"
TEAM_ID="xxxxxxxx"
TEAM_NAME="some name here"
SIGN_ID="Developer ID Application: $TEAM_NAME ($TEAM_ID)"
DMG_PATH="$PWD/$APP_NAME.dmg"
APPLE_ID="[email protected]"
if [ ! -d "$APP_PATH" ]; then
echo "Error: $APP_NAME.app not found in current directory."
exit 1
fi
echo "=== Cleaning previous DMG ==="
rm -f "$DMG_PATH"
echo "=== Deep-signing the app ==="
codesign --deep --force --options runtime --sign "$SIGN_ID" "$APP_PATH"
echo "=== Verifying signature ==="
codesign --verify --deep --strict --verbose=2 "$APP_PATH"
spctl --assess --type execute --verbose "$APP_PATH"
echo "=== Creating DMG ==="
hdiutil create -volname "$APP_NAME" -srcfolder "$APP_PATH" -ov -format UDZO "$DMG_PATH"
echo "=== DMG ready for notarization ==="
echo "Submit with:"
echo "xcrun notarytool submit \"$DMG_PATH\" --apple-id \"$APPLE_ID\" --team-id $TEAM_ID --wait"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment