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>
Patrick Steinhardt committed
May 13, 2025 at 08:48 UTC
28a8e5c8849e158abaf49d86b5ae7c9249d3e483
3 files changed
+34
-20
Makefile
+3
-19
index 722df4ae3f..cde1b7e607 100644
--- a/Makefile
+++ b/Makefile
@@ -112,7 +112,7 @@ ifeq ($(uname_S),Darwin)
TKFRAMEWORK = /System/Library/Frameworks/Tk.framework/Resources/Wish\ Shell.app
endif
endif
- TKEXECUTABLE = $(shell basename "$(TKFRAMEWORK)" .app)
+ TKEXECUTABLE = $(TKFRAMEWORK)/Contents/MacOS/$(shell basename "$(TKFRAMEWORK)" .app)
TKEXECUTABLE_SQ = $(subst ','\'',$(TKEXECUTABLE))
endif
@@ -130,7 +130,6 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
gg_libdir ?= $(sharedir)/git-gui/lib
libdir_SQ = $(subst ','\'',$(gg_libdir))
-libdir_SED = $(subst ','\'',$(subst \,\\,$(gg_libdir_sed_in)))
exedir = $(dir $(gitexecdir))share/git-gui/lib
GITGUI_RELATIVE :=
@@ -139,7 +138,6 @@ GITGUI_MACOSXAPP :=
ifeq ($(exedir),$(gg_libdir))
GITGUI_RELATIVE := 1
endif
-gg_libdir_sed_in := $(gg_libdir)
ifeq ($(uname_S),Darwin)
ifeq ($(shell test -d $(TKFRAMEWORK) && echo y),y)
GITGUI_MACOSXAPP := YesPlease
@@ -163,22 +161,8 @@ Git\ Gui.app: GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS \
macosx/Info.plist \
macosx/git-gui.icns \
macosx/AppMain.tcl \
- $(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE)
- $(QUIET_GEN)rm -rf '$@' '$@'+ && \
- 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 '$@'+ '$@'
+ $(TKEXECUTABLE)
+ $(QUIET_GEN)$(SHELL_PATH) generate-macos-app.sh . "$@" ./GIT-GUI-BUILD-OPTIONS ./GIT-VERSION-FILE
endif
ifdef GITGUI_WINDOWS_WRAPPER
generate-macos-app.sh
+30
new file mode 100755
index 0000000000..71b9fa67a4
--- /dev/null
+++ b/generate-macos-app.sh
@@ -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"
generate-macos-wrapper.sh
+1
-1
index da7e4782f7..0304937f41 100755
--- a/generate-macos-wrapper.sh
+++ b/generate-macos-wrapper.sh
@@ -26,7 +26,7 @@ rm -f "$OUTPUT" "$OUTPUT+"
echo "git-gui version $GITGUI_VERSION"
else
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
EOF
) >"$OUTPUT+"