Skip to content

Commit ea75ee3

Browse files
committed
git-gui: Guess our share/git-gui/lib path at runtime if possible
Johannes Sixt asked me to try to avoid embedding the runtime location of git-gui's library directory in the executable script. Not embedding it helps the MinGW to be relocatable to another directory should a user wish to install the programs in a directory other than the location the packager wanted them to be installed into. Most of this is a hack. We try to determine if the path of our master git-gui script will be able to locate the lib by ../share/git-gui/lib. This should be true if $(gitexecdir) and $(libdir) have the same prefix. If they do then we defer the assignment of $(libdir) until runtime, and we get it from $argv0 rather than embedding it into the script itself. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 3d5793b commit ea75ee3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ifndef gitexecdir
2222
endif
2323

2424
ifndef sharedir
25-
sharedir := $(dir $(gitexecdir))/share
25+
sharedir := $(dir $(gitexecdir))share
2626
endif
2727

2828
ifndef INSTALL
@@ -53,12 +53,19 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
5353
libdir ?= $(sharedir)/git-gui/lib
5454
libdir_SQ = $(subst ','\'',$(libdir))
5555

56+
exedir = $(dir $(gitexecdir))share/git-gui/lib
57+
exedir_SQ = $(subst ','\'',$(exedir))
58+
5659
$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
5760
$(QUIET_GEN)rm -f $@ $@+ && \
61+
if test '$(exedir_SQ)' = '$(libdir_SQ)'; then \
62+
GITGUI_RELATIVE=1; \
63+
fi && \
5864
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
5965
-e 's|^exec wish "$$0"|exec $(subst |,'\|',$(TCLTK_PATH_SQ)) "$$0"|' \
6066
-e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
61-
-e 's|@@GITGUI_LIBDIR@@|$(libdir_SQ)|' \
67+
-e 's|@@GITGUI_RELATIVE@@|'$$GITGUI_RELATIVE'|' \
68+
-e $$GITGUI_RELATIVE's|@@GITGUI_LIBDIR@@|$(libdir_SQ)|' \
6269
$@.sh >$@+ && \
6370
chmod +x $@+ && \
6471
mv $@+ $@
@@ -88,6 +95,7 @@ TRACK_VARS = \
8895
$(subst ','\'',SHELL_PATH='$(SHELL_PATH_SQ)') \
8996
$(subst ','\'',TCL_PATH='$(TCL_PATH_SQ)') \
9097
$(subst ','\'',TCLTK_PATH='$(TCLTK_PATH_SQ)') \
98+
$(subst ','\'',gitexecdir='$(gitexecdir_SQ)') \
9199
$(subst ','\'',libdir='$(libdir_SQ)') \
92100
#end TRACK_VARS
93101

git-gui.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}
2525
## configure our library
2626

2727
set oguilib {@@GITGUI_LIBDIR@@}
28-
if {[string match @@GITGUI_*@@ $oguilib]} {
28+
set oguirel {@@GITGUI_RELATIVE@@}
29+
if {$oguirel eq {1}} {
30+
set oguilib [file dirname [file dirname [file normalize $argv0]]]
31+
set oguilib [file join $oguilib share git-gui lib]
32+
} elseif {[string match @@* $oguirel]} {
2933
set oguilib [file join [file dirname [file normalize $argv0]] lib]
3034
}
3135
set idx [file join $oguilib tclIndex]
@@ -55,7 +59,7 @@ if {$idx ne {}} {
5559
} else {
5660
set auto_path [concat [list $oguilib] $auto_path]
5761
}
58-
unset -nocomplain fd idx
62+
unset -nocomplain oguilib oguirel idx fd
5963

6064
if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
6165
unset _verbose

0 commit comments

Comments
 (0)