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 <spearce@spearce.org>
Shawn O. Pearce committed
May 27, 2007 at 00:03 UTC
ea75ee3598ab6f8d0828f8cc6ec3d4a5f8d66813
2 files changed
+16
-4
Makefile
+10
-2
@@ -22,7 +22,7 @@ ifndef gitexecdir
22
endif
23
24
ifndef sharedir
25
- sharedir := $(dir $(gitexecdir))/share
25
+ sharedir := $(dir $(gitexecdir))share
26
endif
27
28
ifndef INSTALL
@@ -53,12 +53,19 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
53
libdir ?= $(sharedir)/git-gui/lib
54
libdir_SQ = $(subst ','\'',$(libdir))
55
56
+exedir = $(dir $(gitexecdir))share/git-gui/lib
57
+exedir_SQ = $(subst ','\'',$(exedir))
58
+
59
$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
60
$(QUIET_GEN)rm -f $@ $@+ && \
61
+ if test '$(exedir_SQ)' = '$(libdir_SQ)'; then \
62
+ GITGUI_RELATIVE=1; \
63
+ fi && \
64
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
65
-e 's|^exec wish "$$0"|exec $(subst |,'\|',$(TCLTK_PATH_SQ)) "$$0"|' \
66
-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)|' \
69
$@.sh >$@+ && \
70
chmod +x $@+ && \
71
mv $@+ $@
@@ -88,6 +95,7 @@ TRACK_VARS = \
95
$(subst ','\'',SHELL_PATH='$(SHELL_PATH_SQ)') \
96
$(subst ','\'',TCL_PATH='$(TCL_PATH_SQ)') \
97
$(subst ','\'',TCLTK_PATH='$(TCLTK_PATH_SQ)') \
98
+ $(subst ','\'',gitexecdir='$(gitexecdir_SQ)') \
99
$(subst ','\'',libdir='$(libdir_SQ)') \
100
#end TRACK_VARS
101
git-gui.sh
+6
-2
@@ -25,7 +25,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}
25
## configure our library
26
27
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]} {
33
set oguilib [file join [file dirname [file normalize $argv0]] lib]
34
}
35
set idx [file join $oguilib tclIndex]
@@ -55,7 +59,7 @@ if {$idx ne {}} {
59
} else {
60
set auto_path [concat [list $oguilib] $auto_path]
61
}
58
-unset -nocomplain fd idx
62
+unset -nocomplain oguilib oguirel idx fd
63
64
if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
65
unset _verbose