git-gui: Correctly install to /usr/bin on Cygwin
[gitweb.git] / Makefile
index ee564219c0f911025b9bf850539b87edae2d13c4..9d99f670466ca03215ae81268584468d8e46a779 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,8 @@ GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
        @$(SHELL_PATH) ./GIT-VERSION-GEN
 -include GIT-VERSION-FILE
 
+uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
+
 SCRIPT_SH = git-gui.sh
 GITGUI_BUILT_INS = git-citool
 ALL_PROGRAMS = $(GITGUI_BUILT_INS) $(patsubst %.sh,%,$(SCRIPT_SH))
@@ -22,7 +24,7 @@ ifndef gitexecdir
 endif
 
 ifndef sharedir
-       sharedir := $(dir $(gitexecdir))/share
+       sharedir := $(dir $(gitexecdir))share
 endif
 
 ifndef INSTALL
@@ -53,12 +55,23 @@ TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
 libdir   ?= $(sharedir)/git-gui/lib
 libdir_SQ = $(subst ','\'',$(libdir))
 
+exedir    = $(dir $(gitexecdir))share/git-gui/lib
+exedir_SQ = $(subst ','\'',$(exedir))
+
 $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
        $(QUIET_GEN)rm -f $@ $@+ && \
+       GITGUI_RELATIVE= && \
+       if test '$(exedir_SQ)' = '$(libdir_SQ)'; then \
+               if test "$(uname_O)" = Cygwin; \
+               then GITGUI_RELATIVE= ; \
+               else GITGUI_RELATIVE=1; \
+               fi; \
+       fi && \
        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
                -e 's|^exec wish "$$0"|exec $(subst |,'\|',$(TCLTK_PATH_SQ)) "$$0"|' \
                -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
-               -e 's|@@GITGUI_LIBDIR@@|$(libdir_SQ)|' \
+               -e 's|@@GITGUI_RELATIVE@@|'$$GITGUI_RELATIVE'|' \
+               -e $$GITGUI_RELATIVE's|@@GITGUI_LIBDIR@@|$(libdir_SQ)|' \
                $@.sh >$@+ && \
        chmod +x $@+ && \
        mv $@+ $@
@@ -88,6 +101,7 @@ TRACK_VARS = \
        $(subst ','\'',SHELL_PATH='$(SHELL_PATH_SQ)') \
        $(subst ','\'',TCL_PATH='$(TCL_PATH_SQ)') \
        $(subst ','\'',TCLTK_PATH='$(TCLTK_PATH_SQ)') \
+       $(subst ','\'',gitexecdir='$(gitexecdir_SQ)') \
        $(subst ','\'',libdir='$(libdir_SQ)') \
 #end TRACK_VARS