git-gui: Gracefully handle bad TCL_PATH at compile time
[git/mingw.git] / Makefile
blobee564219c0f911025b9bf850539b87edae2d13c4
1 all::
3 # Define V=1 to have a more verbose compile.
6 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
7 @$(SHELL_PATH) ./GIT-VERSION-GEN
8 -include GIT-VERSION-FILE
10 SCRIPT_SH = git-gui.sh
11 GITGUI_BUILT_INS = git-citool
12 ALL_PROGRAMS = $(GITGUI_BUILT_INS) $(patsubst %.sh,%,$(SCRIPT_SH))
13 ALL_LIBFILES = $(wildcard lib/*.tcl)
14 PRELOAD_FILES = lib/class.tcl
16 ifndef SHELL_PATH
17 SHELL_PATH = /bin/sh
18 endif
20 ifndef gitexecdir
21 gitexecdir := $(shell git --exec-path)
22 endif
24 ifndef sharedir
25 sharedir := $(dir $(gitexecdir))/share
26 endif
28 ifndef INSTALL
29 INSTALL = install
30 endif
32 ifndef V
33 QUIET_GEN = @echo ' ' GEN $@;
34 QUIET_BUILT_IN = @echo ' ' BUILTIN $@;
35 QUIET_INDEX = @echo ' ' INDEX $(dir $@);
36 QUIET_2DEVNULL = 2>/dev/null
37 endif
39 TCL_PATH ?= tclsh
40 TCLTK_PATH ?= wish
42 ifeq ($(findstring $(MAKEFLAGS),s),s)
43 QUIET_GEN =
44 QUIET_BUILT_IN =
45 endif
47 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
48 gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
49 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
50 TCL_PATH_SQ = $(subst ','\'',$(TCL_PATH))
51 TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
53 libdir ?= $(sharedir)/git-gui/lib
54 libdir_SQ = $(subst ','\'',$(libdir))
56 $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
57 $(QUIET_GEN)rm -f $@ $@+ && \
58 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
59 -e 's|^exec wish "$$0"|exec $(subst |,'\|',$(TCLTK_PATH_SQ)) "$$0"|' \
60 -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
61 -e 's|@@GITGUI_LIBDIR@@|$(libdir_SQ)|' \
62 $@.sh >$@+ && \
63 chmod +x $@+ && \
64 mv $@+ $@
66 $(GITGUI_BUILT_INS): git-gui
67 $(QUIET_BUILT_IN)rm -f $@ && ln git-gui $@
69 lib/tclIndex: $(ALL_LIBFILES)
70 $(QUIET_INDEX)if echo \
71 $(foreach p,$(PRELOAD_FILES),source $p\;) \
72 auto_mkindex lib '*.tcl' \
73 | $(TCL_PATH) $(QUIET_2DEVNULL); then : ok; \
74 else \
75 echo 1>&2 " * $(TCL_PATH) failed; using unoptimized loading"; \
76 rm -f $@ ; \
77 echo '# Autogenerated by git-gui Makefile' >$@ && \
78 echo >>$@ && \
79 $(foreach p,$(PRELOAD_FILES) $(ALL_LIBFILES),echo '$(subst lib/,,$p)' >>$@ &&) \
80 echo >>$@ ; \
83 # These can record GITGUI_VERSION
84 $(patsubst %.sh,%,$(SCRIPT_SH)): GIT-VERSION-FILE GIT-GUI-VARS
85 lib/tclIndex: GIT-GUI-VARS
87 TRACK_VARS = \
88 $(subst ','\'',SHELL_PATH='$(SHELL_PATH_SQ)') \
89 $(subst ','\'',TCL_PATH='$(TCL_PATH_SQ)') \
90 $(subst ','\'',TCLTK_PATH='$(TCLTK_PATH_SQ)') \
91 $(subst ','\'',libdir='$(libdir_SQ)') \
92 #end TRACK_VARS
94 GIT-GUI-VARS: .FORCE-GIT-GUI-VARS
95 @VARS='$(TRACK_VARS)'; \
96 if test x"$$VARS" != x"`cat $@ 2>/dev/null`" ; then \
97 echo 1>&2 " * new locations or Tcl/Tk interpreter"; \
98 echo 1>$@ "$$VARS"; \
101 all:: $(ALL_PROGRAMS) lib/tclIndex
103 install: all
104 $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(gitexecdir_SQ)'
105 $(INSTALL) git-gui '$(DESTDIR_SQ)$(gitexecdir_SQ)'
106 $(foreach p,$(GITGUI_BUILT_INS), rm -f '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' && ln '$(DESTDIR_SQ)$(gitexecdir_SQ)/git-gui' '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' ;)
107 $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(libdir_SQ)'
108 $(INSTALL) -m644 lib/tclIndex '$(DESTDIR_SQ)$(libdir_SQ)'
109 $(foreach p,$(ALL_LIBFILES), $(INSTALL) -m644 $p '$(DESTDIR_SQ)$(libdir_SQ)' ;)
111 dist-version:
112 @mkdir -p $(TARDIR)
113 @echo $(GITGUI_VERSION) > $(TARDIR)/version
115 clean::
116 rm -f $(ALL_PROGRAMS) lib/tclIndex
117 rm -f GIT-VERSION-FILE GIT-GUI-VARS
119 .PHONY: all install dist-version clean
120 .PHONY: .FORCE-GIT-VERSION-FILE
121 .PHONY: .FORCE-GIT-GUI-VARS