git-gui: extract script to generate "git-gui"

Extract script to generate "git-gui". This change allows us to reuse the
build logic with the Meson build system.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
This commit is contained in:
Patrick Steinhardt 2025-03-11 11:07:19 +01:00
parent 3e656a4356
commit 854e88335a
2 changed files with 30 additions and 11 deletions

View File

@ -127,7 +127,6 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
TCL_PATH_SQ = $(subst ','\'',$(TCL_PATH))
TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
TCLTK_PATH_SED = $(subst ','\'',$(subst \,\\,$(TCLTK_PATH)))
gg_libdir ?= $(sharedir)/git-gui/lib
libdir_SQ = $(subst ','\'',$(gg_libdir))
@ -202,16 +201,7 @@ git-gui: windows/git-gui.sh
endif
$(GITGUI_MAIN): git-gui.sh GIT-VERSION-FILE GIT-GUI-BUILD-OPTIONS
$(QUIET_GEN)rm -f $@ $@+ && \
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
-e 's|@@SHELL_PATH@@|$(SHELL_PATH_SQ)|' \
-e '1,30s|^ exec wish | exec '\''$(TCLTK_PATH_SED)'\'' |' \
-e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
-e 's|@@GITGUI_RELATIVE@@|$(GITGUI_RELATIVE)|' \
-e '$(GITGUI_RELATIVE)s|@@GITGUI_LIBDIR@@|$(libdir_SED)|' \
git-gui.sh >$@+ && \
chmod +x $@+ && \
mv $@+ $@
$(QUIET_GEN)$(SHELL_PATH) generate-git-gui.sh "$<" "$@" ./GIT-GUI-BUILD-OPTIONS ./GIT-VERSION-FILE
XGETTEXT ?= xgettext
ifdef NO_MSGFMT

29
generate-git-gui.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
set -e
if test "$#" -ne 4
then
echo >&2 "usage: $0 <INPUT> <OUTPUT> <BUILD_OPTIONS> <VERSION_FILE>"
exit 1
fi
INPUT="$1"
OUTPUT="$2"
BUILD_OPTIONS="$3"
VERSION_FILE="$4"
. "${BUILD_OPTIONS}"
. "${VERSION_FILE}"
rm -f "$OUTPUT" "$OUTPUT+"
sed \
-e "1s|#!.*/sh|#!$SHELL_PATH|" \
-e "s|@@SHELL_PATH@@|$SHELL_PATH|" \
-e "1,30s|^ exec wish | exec '$TCLTK_PATH' |" \
-e "s|@@GITGUI_VERSION@@|$GITGUI_VERSION|g" \
-e "s|@@GITGUI_RELATIVE@@|$GITGUI_RELATIVE|" \
-e "${GITGUI_RELATIVE}s|@@GITGUI_LIBDIR@@|$GITGUI_LIBDIR|" \
"$INPUT" >"$OUTPUT"+
chmod +x "$OUTPUT"+
mv "$OUTPUT"+ "$OUTPUT"