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
@@ -112,7 +112,7 @@ ifeq ($(uname_S),Darwin)
112
TKFRAMEWORK = /System/Library/Frameworks/Tk.framework/Resources/Wish\ Shell.app
113
endif
114
endif
115
- TKEXECUTABLE = $(shell basename "$(TKFRAMEWORK)" .app)
115
+ TKEXECUTABLE = $(TKFRAMEWORK)/Contents/MacOS/$(shell basename "$(TKFRAMEWORK)" .app)
116
TKEXECUTABLE_SQ = $(subst ','\'',$(TKEXECUTABLE))
117
endif
118
@@ -130,7 +130,6 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
130
131
gg_libdir ?= $(sharedir)/git-gui/lib
132
libdir_SQ = $(subst ','\'',$(gg_libdir))
133
-libdir_SED = $(subst ','\'',$(subst \,\\,$(gg_libdir_sed_in)))
133
exedir = $(dir $(gitexecdir))share/git-gui/lib
134
135
GITGUI_RELATIVE :=
@@ -139,7 +138,6 @@ GITGUI_MACOSXAPP :=
138
ifeq ($(exedir),$(gg_libdir))
139
GITGUI_RELATIVE := 1
140
endif
142
-gg_libdir_sed_in := $(gg_libdir)
141
ifeq ($(uname_S),Darwin)
142
ifeq ($(shell test -d $(TKFRAMEWORK) && echo y),y)
143
GITGUI_MACOSXAPP := YesPlease
@@ -163,22 +161,8 @@ Git\ Gui.app: GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS \
161
macosx/Info.plist \
162
macosx/git-gui.icns \
163
macosx/AppMain.tcl \
166
- $(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE)
167
- $(QUIET_GEN)rm -rf '$@' '$@'+ && \
168
- mkdir -p '$@'+/Contents/MacOS && \
169
- mkdir -p '$@'+/Contents/Resources/Scripts && \
170
- cp '$(subst ','\'',$(subst \,,$(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE)))' \
171
- '$@'+/Contents/MacOS && \
172
- cp macosx/git-gui.icns '$@'+/Contents/Resources && \
173
- sed -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
174
- -e 's/@@GITGUI_TKEXECUTABLE@@/$(TKEXECUTABLE)/g' \
175
- macosx/Info.plist \
176
- >'$@'+/Contents/Info.plist && \
177
- sed -e 's|@@gitexecdir@@|$(gitexecdir_SQ)|' \
178
- -e 's|@@GITGUI_LIBDIR@@|$(libdir_SED)|' \
179
- macosx/AppMain.tcl \
180
- >'$@'+/Contents/Resources/Scripts/AppMain.tcl && \
181
- mv '$@'+ '$@'
164
+ $(TKEXECUTABLE)
165
+ $(QUIET_GEN)$(SHELL_PATH) generate-macos-app.sh . "$@" ./GIT-GUI-BUILD-OPTIONS ./GIT-VERSION-FILE
166
endif
167
168
ifdef GITGUI_WINDOWS_WRAPPER
generate-macos-app.sh
new
+30
@@ -0,0 +1,30 @@
1
+#!/bin/sh
2
+
3
+set -e
4
+
5
+SOURCE_DIR="$1"
6
+OUTPUT="$2"
7
+BUILD_OPTIONS="$3"
8
+VERSION_FILE="$4"
9
+
10
+. "$BUILD_OPTIONS"
11
+. "$VERSION_FILE"
12
+
13
+rm -rf "$OUTPUT" "$OUTPUT+"
14
+
15
+mkdir -p "$OUTPUT+/Contents/MacOS"
16
+mkdir -p "$OUTPUT+/Contents/Resources/Scripts"
17
+
18
+cp "$TKEXECUTABLE" "$OUTPUT+/Contents/MacOS"
19
+cp "$SOURCE_DIR/macosx/git-gui.icns" "$OUTPUT+/Contents/Resources"
20
+sed \
21
+ -e "s/@@GITGUI_VERSION@@/$GITGUI_VERSION/g" \
22
+ -e "s/@@GITGUI_TKEXECUTABLE@@/$(basename "$TKEXECUTABLE")/g" \
23
+ "$SOURCE_DIR/macosx/Info.plist" \
24
+ >"$OUTPUT+/Contents/Info.plist"
25
+sed \
26
+ -e "s|@@gitexecdir@@|$GITGUI_GITEXECDIR|" \
27
+ -e "s|@@GITGUI_LIBDIR@@|$GITGUI_LIBDIR|" \
28
+ "$SOURCE_DIR/macosx/AppMain.tcl" \
29
+ >"$OUTPUT+/Contents/Resources/Scripts/AppMain.tcl"
30
+mv "$OUTPUT+" "$OUTPUT"
generate-macos-wrapper.sh
+1
-1
@@ -26,7 +26,7 @@ rm -f "$OUTPUT" "$OUTPUT+"
26
echo "git-gui version $GITGUI_VERSION"
27
else
28
libdir="${GIT_GUI_LIB_DIR:-$GITGUI_LIBDIR}"
29
- exec "$libdir/Git Gui.app/Contents/MacOS/$TKEXECUTABLE" "$0" "$@"
29
+ exec "$libdir/Git Gui.app/Contents/MacOS/$(basename "$TKEXECUTABLE")" "$0" "$@"
30
fi
31
EOF
32
) >"$OUTPUT+"