wesnoth: add darwin app bundle

This commit is contained in:
Niklas Korz
2025-05-05 14:44:10 +02:00
parent effa279e04
commit a0891b0b76
+30 -1
View File
@@ -1,6 +1,7 @@
{
lib,
stdenv,
stdenvNoCC,
fetchFromGitHub,
cmake,
pkg-config,
@@ -91,7 +92,34 @@ stdenv.mkDerivation rec {
"-DENABLE_SYSTEM_LUA=ON"
];
NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isDarwin "-framework AppKit";
postInstall = lib.optionalString stdenv.hostPlatform.isDarwin ''
app_name="The Battle for Wesnoth"
app_bundle="$out/Applications/$app_name.app"
app_contents="$app_bundle/Contents"
mkdir -p "$app_contents"
echo "APPL????" > "$app_contents/PkgInfo"
mv $out/bin "$app_contents/MacOS"
mv $out/share/wesnoth "$app_contents/Resources"
pushd ../projectfiles/Xcode
substitute Info.plist "$app_contents/Info.plist" \
--replace-fail ''\'''${EXECUTABLE_NAME}' wesnoth \
--replace-fail '$(PRODUCT_BUNDLE_IDENTIFIER)' org.wesnoth.Wesnoth \
--replace-fail ''\'''${PRODUCT_NAME}' "$app_name"
cp -r Resources/SDLMain.nib "$app_contents/Resources/"
install -m0644 Resources/{container-migration.plist,icon.icns} "$app_contents/Resources"
popd
# Make the game and dedicated server binary available for shell users
mkdir -p "$out/bin"
ln -s "$app_contents/MacOS/wesnothd" "$out/bin/wesnothd"
# Symlinking the game binary is unsifficient as it would be unable to
# find the bundle resources
cat << EOF > "$out/bin/wesnoth"
#!${stdenvNoCC.shell}
open -na "$app_bundle" --args "\$@"
EOF
chmod +x "$out/bin/wesnoth"
'';
meta = with lib; {
description = "Battle for Wesnoth, a free, turn-based strategy game with a fantasy theme";
@@ -107,5 +135,6 @@ stdenv.mkDerivation rec {
license = licenses.gpl2Plus;
maintainers = with maintainers; [ abbradar ];
platforms = platforms.unix;
mainProgram = "wesnoth";
};
}