git-gui: extract script to generate macOS app

Extract script to generate the macOS app. This change allows us to reuse
the build logic with the Meson build system.

Note that as part of this change we also modify the TKEXECUTABLE
variable to track its full path. Like this we don't have to propagate
both the TKEXECUTABLE and TKFRAMEWORK variables into the script, and the
basename can be trivially computed from TKEXECUTABLE anyway.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
maint
Patrick Steinhardt 2025-05-13 08:48:07 +02:00
parent 743e1cbd7e
commit 28a8e5c884
3 changed files with 34 additions and 20 deletions

View File

@ -112,7 +112,7 @@ ifeq ($(uname_S),Darwin)
TKFRAMEWORK = /System/Library/Frameworks/Tk.framework/Resources/Wish\ Shell.app TKFRAMEWORK = /System/Library/Frameworks/Tk.framework/Resources/Wish\ Shell.app
endif endif
endif endif
TKEXECUTABLE = $(shell basename "$(TKFRAMEWORK)" .app) TKEXECUTABLE = $(TKFRAMEWORK)/Contents/MacOS/$(shell basename "$(TKFRAMEWORK)" .app)
TKEXECUTABLE_SQ = $(subst ','\'',$(TKEXECUTABLE)) TKEXECUTABLE_SQ = $(subst ','\'',$(TKEXECUTABLE))
endif endif


@ -130,7 +130,6 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))


gg_libdir ?= $(sharedir)/git-gui/lib gg_libdir ?= $(sharedir)/git-gui/lib
libdir_SQ = $(subst ','\'',$(gg_libdir)) libdir_SQ = $(subst ','\'',$(gg_libdir))
libdir_SED = $(subst ','\'',$(subst \,\\,$(gg_libdir_sed_in)))
exedir = $(dir $(gitexecdir))share/git-gui/lib exedir = $(dir $(gitexecdir))share/git-gui/lib


GITGUI_RELATIVE := GITGUI_RELATIVE :=
@ -139,7 +138,6 @@ GITGUI_MACOSXAPP :=
ifeq ($(exedir),$(gg_libdir)) ifeq ($(exedir),$(gg_libdir))
GITGUI_RELATIVE := 1 GITGUI_RELATIVE := 1
endif endif
gg_libdir_sed_in := $(gg_libdir)
ifeq ($(uname_S),Darwin) ifeq ($(uname_S),Darwin)
ifeq ($(shell test -d $(TKFRAMEWORK) && echo y),y) ifeq ($(shell test -d $(TKFRAMEWORK) && echo y),y)
GITGUI_MACOSXAPP := YesPlease GITGUI_MACOSXAPP := YesPlease
@ -163,22 +161,8 @@ Git\ Gui.app: GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS \
macosx/Info.plist \ macosx/Info.plist \
macosx/git-gui.icns \ macosx/git-gui.icns \
macosx/AppMain.tcl \ macosx/AppMain.tcl \
$(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE) $(TKEXECUTABLE)
$(QUIET_GEN)rm -rf '$@' '$@'+ && \ $(QUIET_GEN)$(SHELL_PATH) generate-macos-app.sh . "$@" ./GIT-GUI-BUILD-OPTIONS ./GIT-VERSION-FILE
mkdir -p '$@'+/Contents/MacOS && \
mkdir -p '$@'+/Contents/Resources/Scripts && \
cp '$(subst ','\'',$(subst \,,$(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE)))' \
'$@'+/Contents/MacOS && \
cp macosx/git-gui.icns '$@'+/Contents/Resources && \
sed -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
-e 's/@@GITGUI_TKEXECUTABLE@@/$(TKEXECUTABLE)/g' \
macosx/Info.plist \
>'$@'+/Contents/Info.plist && \
sed -e 's|@@gitexecdir@@|$(gitexecdir_SQ)|' \
-e 's|@@GITGUI_LIBDIR@@|$(libdir_SED)|' \
macosx/AppMain.tcl \
>'$@'+/Contents/Resources/Scripts/AppMain.tcl && \
mv '$@'+ '$@'
endif endif


ifdef GITGUI_WINDOWS_WRAPPER ifdef GITGUI_WINDOWS_WRAPPER

30
generate-macos-app.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh

set -e

SOURCE_DIR="$1"
OUTPUT="$2"
BUILD_OPTIONS="$3"
VERSION_FILE="$4"

. "$BUILD_OPTIONS"
. "$VERSION_FILE"

rm -rf "$OUTPUT" "$OUTPUT+"

mkdir -p "$OUTPUT+/Contents/MacOS"
mkdir -p "$OUTPUT+/Contents/Resources/Scripts"

cp "$TKEXECUTABLE" "$OUTPUT+/Contents/MacOS"
cp "$SOURCE_DIR/macosx/git-gui.icns" "$OUTPUT+/Contents/Resources"
sed \
-e "s/@@GITGUI_VERSION@@/$GITGUI_VERSION/g" \
-e "s/@@GITGUI_TKEXECUTABLE@@/$(basename "$TKEXECUTABLE")/g" \
"$SOURCE_DIR/macosx/Info.plist" \
>"$OUTPUT+/Contents/Info.plist"
sed \
-e "s|@@gitexecdir@@|$GITGUI_GITEXECDIR|" \
-e "s|@@GITGUI_LIBDIR@@|$GITGUI_LIBDIR|" \
"$SOURCE_DIR/macosx/AppMain.tcl" \
>"$OUTPUT+/Contents/Resources/Scripts/AppMain.tcl"
mv "$OUTPUT+" "$OUTPUT"

View File

@ -26,7 +26,7 @@ rm -f "$OUTPUT" "$OUTPUT+"
echo "git-gui version $GITGUI_VERSION" echo "git-gui version $GITGUI_VERSION"
else else
libdir="${GIT_GUI_LIB_DIR:-$GITGUI_LIBDIR}" libdir="${GIT_GUI_LIB_DIR:-$GITGUI_LIBDIR}"
exec "$libdir/Git Gui.app/Contents/MacOS/$TKEXECUTABLE" "$0" "$@" exec "$libdir/Git Gui.app/Contents/MacOS/$(basename "$TKEXECUTABLE")" "$0" "$@"
fi fi
EOF EOF
) >"$OUTPUT+" ) >"$OUTPUT+"