]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: extract script to generate macOS wrapper
authorPatrick Steinhardt <ps@pks.im>
Tue, 11 Mar 2025 10:07:19 +0000 (11:07 +0100)
committerPatrick Steinhardt <ps@pks.im>
Tue, 13 May 2025 06:45:51 +0000 (08:45 +0200)
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 <ps@pks.im>
GIT-GUI-BUILD-OPTIONS.in
Makefile
generate-macos-wrapper.sh [new file with mode: 0755]

index 3c112af57803a0a29b624dd47e82dcfcc43c6c15..5fd885c2bf73e93988285d9bfa47c8444b702b1f 100644 (file)
@@ -4,3 +4,4 @@ GITGUI_RELATIVE=@GITGUI_RELATIVE@
 SHELL_PATH=@SHELL_PATH@
 TCLTK_PATH=@TCLTK_PATH@
 TCL_PATH=@TCL_PATH@
+TKEXECUTABLE=@TKEXECUTABLE@
index 5166bba1f2a90bbf8758f196f4cac76d111ee953..722df4ae3fb42909399694c4d0127da63fbe9084 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -113,6 +113,7 @@ ifeq ($(uname_S),Darwin)
                 endif
         endif
        TKEXECUTABLE = $(shell basename "$(TKFRAMEWORK)" .app)
+       TKEXECUTABLE_SQ = $(subst ','\'',$(TKEXECUTABLE))
 endif
 
 ifeq ($(findstring $(firstword -$(MAKEFLAGS)),s),s)
@@ -155,20 +156,8 @@ endif
 ifdef GITGUI_MACOSXAPP
 GITGUI_MAIN := git-gui.tcl
 
-git-gui: GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS
-       $(QUIET_GEN)rm -f $@ $@+ && \
-       echo '#!$(SHELL_PATH_SQ)' >$@+ && \
-       echo 'if test "z$$*" = zversion ||' >>$@+ && \
-       echo '   test "z$$*" = z--version' >>$@+ && \
-       echo then >>$@+ && \
-       echo '  'echo \'git-gui version '$(GITGUI_VERSION)'\' >>$@+ && \
-       echo else >>$@+ && \
-       echo '  libdir="$${GIT_GUI_LIB_DIR:-$(libdir_SQ)}"' >>$@+ && \
-       echo '  'exec \"'$$libdir/Git Gui.app/Contents/MacOS/$(subst \,,$(TKEXECUTABLE))'\" \
-               '"$$0" "$$@"' >>$@+ && \
-       echo fi >>$@+ && \
-       chmod +x $@+ && \
-       mv $@+ $@
+git-gui: generate-macos-wrapper.sh GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS
+       $(QUIET_GEN)$(SHELL_PATH) generate-macos-wrapper.sh "$@" ./GIT-GUI-BUILD-OPTIONS ./GIT-VERSION-FILE
 
 Git\ Gui.app: GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS \
                macosx/Info.plist \
@@ -236,6 +225,7 @@ GIT-GUI-BUILD-OPTIONS: FORCE
                -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
                -e 's|@TCLTK_PATH@|$(TCLTK_PATH_SQ)|' \
                -e 's|@TCL_PATH@|$(TCL_PATH_SQ)|' \
+               -e 's|@TKEXECUTABLE@|$(TKEXECUTABLE_SQ)|' \
                $@.in >$@+
        @if grep -q '^[A-Z][A-Z_]*=@.*@$$' $@+; then echo "Unsubstituted build options in $@" >&2 && exit 1; fi
        @if cmp $@+ $@ >/dev/null 2>&1; then $(RM) $@+; else mv $@+ $@; fi
diff --git a/generate-macos-wrapper.sh b/generate-macos-wrapper.sh
new file mode 100755 (executable)
index 0000000..da7e478
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+set -e
+
+if test "$#" -ne 3
+then
+       echo >&2 "usage: $0 <OUTPUT> <BUILD_OPTIONS> <VERSION_FILE>"
+       exit 1
+fi
+
+OUTPUT="$1"
+BUILD_OPTIONS="$2"
+VERSION_FILE="$3"
+
+. "$BUILD_OPTIONS"
+
+rm -f "$OUTPUT" "$OUTPUT+"
+
+(
+       echo "#!$SHELL_PATH"
+       cat "$BUILD_OPTIONS" "$VERSION_FILE"
+       cat <<-'EOF'
+       if test "z$*" = zversion ||
+          test "z$*" = z--version
+       then
+               echo "git-gui version $GITGUI_VERSION"
+       else
+               libdir="${GIT_GUI_LIB_DIR:-$GITGUI_LIBDIR}"
+               exec "$libdir/Git Gui.app/Contents/MacOS/$TKEXECUTABLE" "$0" "$@"
+       fi
+       EOF
+) >"$OUTPUT+"
+
+chmod +x "$OUTPUT+"
+mv "$OUTPUT+" "$OUTPUT"