git-gui: Don't require $DISPLAY just to get --version
[git] / Makefile
1 all::
2
3 # Define V=1 to have a more verbose compile.
4 #
5
6 GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
7         @$(SHELL_PATH) ./GIT-VERSION-GEN
8 -include GIT-VERSION-FILE
9
10 uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
11
12 SCRIPT_SH = git-gui.sh
13 GITGUI_BUILT_INS = git-citool
14 ALL_PROGRAMS = $(GITGUI_BUILT_INS) $(patsubst %.sh,%,$(SCRIPT_SH))
15 ALL_LIBFILES = $(wildcard lib/*.tcl)
16 PRELOAD_FILES = lib/class.tcl
17
18 ifndef SHELL_PATH
19         SHELL_PATH = /bin/sh
20 endif
21
22 ifndef gitexecdir
23         gitexecdir := $(shell git --exec-path)
24 endif
25
26 ifndef sharedir
27         sharedir := $(dir $(gitexecdir))share
28 endif
29
30 ifndef INSTALL
31         INSTALL = install
32 endif
33
34 ifndef V
35         QUIET_GEN      = @echo '   ' GEN $@;
36         QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
37         QUIET_INDEX    = @echo '   ' INDEX $(dir $@);
38         QUIET_2DEVNULL = 2>/dev/null
39 endif
40
41 TCL_PATH   ?= tclsh
42 TCLTK_PATH ?= wish
43
44 ifeq ($(findstring $(MAKEFLAGS),s),s)
45 QUIET_GEN =
46 QUIET_BUILT_IN =
47 endif
48
49 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
50 gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
51 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
52 TCL_PATH_SQ = $(subst ','\'',$(TCL_PATH))
53 TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
54
55 libdir   ?= $(sharedir)/git-gui/lib
56 libdir_SQ = $(subst ','\'',$(libdir))
57
58 exedir    = $(dir $(gitexecdir))share/git-gui/lib
59 exedir_SQ = $(subst ','\'',$(exedir))
60
61 $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
62         $(QUIET_GEN)rm -f $@ $@+ && \
63         GITGUI_RELATIVE= && \
64         if test '$(exedir_SQ)' = '$(libdir_SQ)'; then \
65                 if test "$(uname_O)" = Cygwin; \
66                 then GITGUI_RELATIVE= ; \
67                 else GITGUI_RELATIVE=1; \
68                 fi; \
69         fi && \
70         sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
71                 -e 's|^ exec wish "$$0"| exec $(subst |,'\|',$(TCLTK_PATH_SQ)) "$$0"|' \
72                 -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
73                 -e 's|@@GITGUI_RELATIVE@@|'$$GITGUI_RELATIVE'|' \
74                 -e $$GITGUI_RELATIVE's|@@GITGUI_LIBDIR@@|$(libdir_SQ)|' \
75                 $@.sh >$@+ && \
76         chmod +x $@+ && \
77         mv $@+ $@
78
79 $(GITGUI_BUILT_INS): git-gui
80         $(QUIET_BUILT_IN)rm -f $@ && ln git-gui $@
81
82 lib/tclIndex: $(ALL_LIBFILES)
83         $(QUIET_INDEX)if echo \
84           $(foreach p,$(PRELOAD_FILES),source $p\;) \
85           auto_mkindex lib '*.tcl' \
86         | $(TCL_PATH) $(QUIET_2DEVNULL); then : ok; \
87         else \
88          echo 1>&2 "    * $(TCL_PATH) failed; using unoptimized loading"; \
89          rm -f $@ ; \
90          echo '# Autogenerated by git-gui Makefile' >$@ && \
91          echo >>$@ && \
92          $(foreach p,$(PRELOAD_FILES) $(ALL_LIBFILES),echo '$(subst lib/,,$p)' >>$@ &&) \
93          echo >>$@ ; \
94         fi
95
96 # These can record GITGUI_VERSION
97 $(patsubst %.sh,%,$(SCRIPT_SH)): GIT-VERSION-FILE GIT-GUI-VARS
98 lib/tclIndex: GIT-GUI-VARS
99
100 TRACK_VARS = \
101         $(subst ','\'',SHELL_PATH='$(SHELL_PATH_SQ)') \
102         $(subst ','\'',TCL_PATH='$(TCL_PATH_SQ)') \
103         $(subst ','\'',TCLTK_PATH='$(TCLTK_PATH_SQ)') \
104         $(subst ','\'',gitexecdir='$(gitexecdir_SQ)') \
105         $(subst ','\'',libdir='$(libdir_SQ)') \
106 #end TRACK_VARS
107
108 GIT-GUI-VARS: .FORCE-GIT-GUI-VARS
109         @VARS='$(TRACK_VARS)'; \
110         if test x"$$VARS" != x"`cat $@ 2>/dev/null`" ; then \
111                 echo 1>&2 "    * new locations or Tcl/Tk interpreter"; \
112                 echo 1>$@ "$$VARS"; \
113         fi
114
115 all:: $(ALL_PROGRAMS) lib/tclIndex
116
117 install: all
118         $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(gitexecdir_SQ)'
119         $(INSTALL) git-gui '$(DESTDIR_SQ)$(gitexecdir_SQ)'
120         $(foreach p,$(GITGUI_BUILT_INS), rm -f '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' && ln '$(DESTDIR_SQ)$(gitexecdir_SQ)/git-gui' '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' ;)
121         $(INSTALL) -d -m755 '$(DESTDIR_SQ)$(libdir_SQ)'
122         $(INSTALL) -m644 lib/tclIndex '$(DESTDIR_SQ)$(libdir_SQ)'
123         $(foreach p,$(ALL_LIBFILES), $(INSTALL) -m644 $p '$(DESTDIR_SQ)$(libdir_SQ)' ;)
124
125 dist-version:
126         @mkdir -p $(TARDIR)
127         @echo $(GITGUI_VERSION) > $(TARDIR)/version
128
129 clean::
130         rm -f $(ALL_PROGRAMS) lib/tclIndex
131         rm -f GIT-VERSION-FILE GIT-GUI-VARS
132
133 .PHONY: all install dist-version clean
134 .PHONY: .FORCE-GIT-VERSION-FILE
135 .PHONY: .FORCE-GIT-GUI-VARS