Skip to content

Commit 743e1cb

Browse files
committed
git-gui: extract script to generate macOS wrapper
Extract script to generate the macOS wrapper for git-gui. This change allows us to reuse the build logic with the Meson build system. Signed-off-by: Patrick Steinhardt <[email protected]>
1 parent 2cc5b0f commit 743e1cb

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

GIT-GUI-BUILD-OPTIONS.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ GITGUI_RELATIVE=@GITGUI_RELATIVE@
44
SHELL_PATH=@SHELL_PATH@
55
TCLTK_PATH=@TCLTK_PATH@
66
TCL_PATH=@TCL_PATH@
7+
TKEXECUTABLE=@TKEXECUTABLE@

Makefile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ ifeq ($(uname_S),Darwin)
113113
endif
114114
endif
115115
TKEXECUTABLE = $(shell basename "$(TKFRAMEWORK)" .app)
116+
TKEXECUTABLE_SQ = $(subst ','\'',$(TKEXECUTABLE))
116117
endif
117118

118119
ifeq ($(findstring $(firstword -$(MAKEFLAGS)),s),s)
@@ -155,20 +156,8 @@ endif
155156
ifdef GITGUI_MACOSXAPP
156157
GITGUI_MAIN := git-gui.tcl
157158

158-
git-gui: GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS
159-
$(QUIET_GEN)rm -f $@ $@+ && \
160-
echo '#!$(SHELL_PATH_SQ)' >$@+ && \
161-
echo 'if test "z$$*" = zversion ||' >>$@+ && \
162-
echo ' test "z$$*" = z--version' >>$@+ && \
163-
echo then >>$@+ && \
164-
echo ' 'echo \'git-gui version '$(GITGUI_VERSION)'\' >>$@+ && \
165-
echo else >>$@+ && \
166-
echo ' libdir="$${GIT_GUI_LIB_DIR:-$(libdir_SQ)}"' >>$@+ && \
167-
echo ' 'exec \"'$$libdir/Git Gui.app/Contents/MacOS/$(subst \,,$(TKEXECUTABLE))'\" \
168-
'"$$0" "$$@"' >>$@+ && \
169-
echo fi >>$@+ && \
170-
chmod +x $@+ && \
171-
mv $@+ $@
159+
git-gui: generate-macos-wrapper.sh GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS
160+
$(QUIET_GEN)$(SHELL_PATH) generate-macos-wrapper.sh "$@" ./GIT-GUI-BUILD-OPTIONS ./GIT-VERSION-FILE
172161

173162
Git\ Gui.app: GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS \
174163
macosx/Info.plist \
@@ -236,6 +225,7 @@ GIT-GUI-BUILD-OPTIONS: FORCE
236225
-e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
237226
-e 's|@TCLTK_PATH@|$(TCLTK_PATH_SQ)|' \
238227
-e 's|@TCL_PATH@|$(TCL_PATH_SQ)|' \
228+
-e 's|@TKEXECUTABLE@|$(TKEXECUTABLE_SQ)|' \
239229
$@.in >$@+
240230
@if grep -q '^[A-Z][A-Z_]*=@.*@$$' $@+; then echo "Unsubstituted build options in $@" >&2 && exit 1; fi
241231
@if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi

generate-macos-wrapper.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if test "$#" -ne 3
6+
then
7+
echo >&2 "usage: $0 <OUTPUT> <BUILD_OPTIONS> <VERSION_FILE>"
8+
exit 1
9+
fi
10+
11+
OUTPUT="$1"
12+
BUILD_OPTIONS="$2"
13+
VERSION_FILE="$3"
14+
15+
. "$BUILD_OPTIONS"
16+
17+
rm -f "$OUTPUT" "$OUTPUT+"
18+
19+
(
20+
echo "#!$SHELL_PATH"
21+
cat "$BUILD_OPTIONS" "$VERSION_FILE"
22+
cat <<-'EOF'
23+
if test "z$*" = zversion ||
24+
test "z$*" = z--version
25+
then
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" "$@"
30+
fi
31+
EOF
32+
) >"$OUTPUT+"
33+
34+
chmod +x "$OUTPUT+"
35+
mv "$OUTPUT+" "$OUTPUT"

0 commit comments

Comments
 (0)