factor out refresh_and_write_cache function
[git/git.git] / git-gui / Makefile
CommitLineData
b4d2b04c
JH
1all::
2
eec10252
JH
3# Define V=1 to have a more verbose compile.
4#
d794d9e7
JH
5# Define NO_MSGFMT if you do not have msgfmt from the GNU gettext
6# package and want to use our rough pure Tcl po->msg translator.
3d252a9c 7# TCL_PATH must be valid for this to work.
d794d9e7 8#
eec10252 9
b30ccd75 10GIT-VERSION-FILE: FORCE
b4d2b04c
JH
11 @$(SHELL_PATH) ./GIT-VERSION-GEN
12-include GIT-VERSION-FILE
13
d794d9e7 14uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
82ff9d2c 15uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
e98d6df7 16uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
82ff9d2c 17
3ed02de2 18SCRIPT_SH = git-gui.sh
d794d9e7 19GITGUI_MAIN := git-gui
b4d2b04c 20GITGUI_BUILT_INS = git-citool
5f5dbd71 21ALL_LIBFILES = $(wildcard lib/*.tcl)
e986e26a 22PRELOAD_FILES = lib/class.tcl
d794d9e7
JH
23NONTCL_LIBFILES = \
24 lib/git-gui.ico \
25 $(wildcard lib/win32_*.js) \
26#end NONTCL_LIBFILES
b4d2b04c
JH
27
28ifndef SHELL_PATH
29 SHELL_PATH = /bin/sh
30endif
31
67c75759
JH
32ifndef gitexecdir
33 gitexecdir := $(shell git --exec-path)
34endif
35
5f5dbd71 36ifndef sharedir
731ab1f5
JH
37ifeq (git-core,$(notdir $(gitexecdir)))
38 sharedir := $(dir $(patsubst %/,%,$(dir $(gitexecdir))))share
39else
c63a3ad2 40 sharedir := $(dir $(gitexecdir))share
5f5dbd71 41endif
731ab1f5 42endif
5f5dbd71 43
67c75759
JH
44ifndef INSTALL
45 INSTALL = install
46endif
b4d2b04c 47
d794d9e7 48RM_RF ?= rm -rf
9269df96
JH
49RMDIR ?= rmdir
50
d9f40593 51INSTALL_D0 = $(INSTALL) -d -m 755 # space is required here
82ff9d2c 52INSTALL_D1 =
d9f40593 53INSTALL_R0 = $(INSTALL) -m 644 # space is required here
82ff9d2c 54INSTALL_R1 =
d9f40593 55INSTALL_X0 = $(INSTALL) -m 755 # space is required here
82ff9d2c 56INSTALL_X1 =
d794d9e7
JH
57INSTALL_A0 = find # space is required here
58INSTALL_A1 = | cpio -pud
82ff9d2c
JH
59INSTALL_L0 = rm -f # space is required here
60INSTALL_L1 = && ln # space is required here
61INSTALL_L2 =
62INSTALL_L3 =
63
9269df96
JH
64REMOVE_D0 = $(RMDIR) # space is required here
65REMOVE_D1 = || true
d794d9e7 66REMOVE_F0 = $(RM_RF) # space is required here
9269df96
JH
67REMOVE_F1 =
68CLEAN_DST = true
69
eec10252 70ifndef V
82ff9d2c 71 QUIET = @
d794d9e7 72 QUIET_GEN = $(QUIET)echo ' ' GEN '$@' &&
82ff9d2c 73 QUIET_INDEX = $(QUIET)echo ' ' INDEX $(dir $@) &&
d794d9e7 74 QUIET_MSGFMT0 = $(QUIET)printf ' MSGFMT %12s ' $@ && v=`
cab31fa0 75 QUIET_MSGFMT1 = 2>&1` && echo "$$v" | sed -e 's/fuzzy translations/fuzzy/' | sed -e 's/ messages*//g'
e986e26a 76 QUIET_2DEVNULL = 2>/dev/null
82ff9d2c
JH
77
78 INSTALL_D0 = dir=
d9f40593 79 INSTALL_D1 = && echo ' ' DEST $$dir && $(INSTALL) -d -m 755 "$$dir"
82ff9d2c 80 INSTALL_R0 = src=
d9f40593 81 INSTALL_R1 = && echo ' ' INSTALL 644 `basename $$src` && $(INSTALL) -m 644 $$src
82ff9d2c 82 INSTALL_X0 = src=
d9f40593 83 INSTALL_X1 = && echo ' ' INSTALL 755 `basename $$src` && $(INSTALL) -m 755 $$src
d794d9e7
JH
84 INSTALL_A0 = src=
85 INSTALL_A1 = && echo ' ' INSTALL ' ' `basename "$$src"` && find "$$src" | cpio -pud
82ff9d2c
JH
86
87 INSTALL_L0 = dst=
88 INSTALL_L1 = && src=
89 INSTALL_L2 = && dst=
90 INSTALL_L3 = && echo ' ' 'LINK ' `basename "$$dst"` '->' `basename "$$src"` && rm -f "$$dst" && ln "$$src" "$$dst"
9269df96
JH
91
92 CLEAN_DST = echo ' ' UNINSTALL
93 REMOVE_D0 = dir=
94 REMOVE_D1 = && echo ' ' REMOVE $$dir && test -d "$$dir" && $(RMDIR) "$$dir" || true
95 REMOVE_F0 = dst=
d794d9e7 96 REMOVE_F1 = && echo ' ' REMOVE `basename "$$dst"` && $(RM_RF) "$$dst"
eec10252
JH
97endif
98
c182ec90 99TCLTK_PATH ?= wish
e98d6df7
JH
100ifeq (./,$(dir $(TCLTK_PATH)))
101 TCL_PATH ?= $(subst wish,tclsh,$(TCLTK_PATH))
102else
103 TCL_PATH ?= $(dir $(TCLTK_PATH))$(notdir $(subst wish,tclsh,$(TCLTK_PATH)))
104endif
105
106ifeq ($(uname_S),Darwin)
107 TKFRAMEWORK = /Library/Frameworks/Tk.framework/Resources/Wish.app
a8816e7b
JH
108 ifeq ($(shell echo "$(uname_R)" | awk -F. '{if ($$1 >= 9) print "y"}')_$(shell test -d $(TKFRAMEWORK) || echo n),y_n)
109 TKFRAMEWORK = /System/Library/Frameworks/Tk.framework/Resources/Wish.app
110 ifeq ($(shell test -d $(TKFRAMEWORK) || echo n),n)
111 TKFRAMEWORK = /System/Library/Frameworks/Tk.framework/Resources/Wish\ Shell.app
112 endif
e98d6df7
JH
113 endif
114 TKEXECUTABLE = $(shell basename "$(TKFRAMEWORK)" .app)
115endif
c182ec90 116
27ebd6e0
JH
117ifeq ($(findstring $(MAKEFLAGS),s),s)
118QUIET_GEN =
27ebd6e0
JH
119endif
120
d794d9e7
JH
121-include config.mak
122
b4d2b04c
JH
123DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
124gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
b4d2b04c 125SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
e986e26a 126TCL_PATH_SQ = $(subst ','\'',$(TCL_PATH))
c182ec90 127TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
d794d9e7 128TCLTK_PATH_SED = $(subst ','\'',$(subst \,\\,$(TCLTK_PATH)))
b4d2b04c 129
9269df96
JH
130gg_libdir ?= $(sharedir)/git-gui/lib
131libdir_SQ = $(subst ','\'',$(gg_libdir))
105c21df 132libdir_SED = $(subst ','\'',$(subst \,\\,$(gg_libdir_sed_in)))
d794d9e7
JH
133exedir = $(dir $(gitexecdir))share/git-gui/lib
134
135GITGUI_SCRIPT := $$0
136GITGUI_RELATIVE :=
137GITGUI_MACOSXAPP :=
138
d794d9e7
JH
139ifeq ($(uname_O),Cygwin)
140 GITGUI_SCRIPT := `cygpath --windows --absolute "$(GITGUI_SCRIPT)"`
e98d6df7
JH
141
142 # Is this a Cygwin Tcl/Tk binary? If so it knows how to do
143 # POSIX path translation just like cygpath does and we must
144 # keep libdir in POSIX format so Cygwin packages of git-gui
145 # work no matter where the user installs them.
146 #
147 ifeq ($(shell echo 'puts [file normalize /]' | '$(TCL_PATH_SQ)'),$(shell cygpath --mixed --absolute /))
148 gg_libdir_sed_in := $(gg_libdir)
149 else
150 gg_libdir_sed_in := $(shell cygpath --windows --absolute "$(gg_libdir)")
151 endif
144126ab
JH
152else
153 ifeq ($(exedir),$(gg_libdir))
154 GITGUI_RELATIVE := 1
d794d9e7 155 endif
105c21df 156 gg_libdir_sed_in := $(gg_libdir)
d794d9e7
JH
157endif
158ifeq ($(uname_S),Darwin)
159 ifeq ($(shell test -d $(TKFRAMEWORK) && echo y),y)
160 GITGUI_MACOSXAPP := YesPlease
161 endif
162endif
163ifneq (,$(findstring MINGW,$(uname_S)))
90dbf226 164ifeq ($(shell expr "$(uname_R)" : '1\.'),2)
d794d9e7 165 NO_MSGFMT=1
90dbf226 166endif
d794d9e7 167 GITGUI_WINDOWS_WRAPPER := YesPlease
731ab1f5 168 GITGUI_RELATIVE := 1
d794d9e7
JH
169endif
170
171ifdef GITGUI_MACOSXAPP
172GITGUI_MAIN := git-gui.tcl
173
174git-gui: GIT-VERSION-FILE GIT-GUI-VARS
175 $(QUIET_GEN)rm -f $@ $@+ && \
176 echo '#!$(SHELL_PATH_SQ)' >$@+ && \
177 echo 'if test "z$$*" = zversion ||' >>$@+ && \
178 echo ' test "z$$*" = z--version' >>$@+ && \
179 echo then >>$@+ && \
180 echo ' 'echo \'git-gui version '$(GITGUI_VERSION)'\' >>$@+ && \
181 echo else >>$@+ && \
1eb0545c
JH
182 echo ' libdir="$${GIT_GUI_LIB_DIR:-$(libdir_SQ)}"' >>$@+ && \
183 echo ' 'exec \"'$$libdir/Git Gui.app/Contents/MacOS/$(subst \,,$(TKEXECUTABLE))'\" \
d794d9e7
JH
184 '"$$0" "$$@"' >>$@+ && \
185 echo fi >>$@+ && \
186 chmod +x $@+ && \
187 mv $@+ $@
188
189Git\ Gui.app: GIT-VERSION-FILE GIT-GUI-VARS \
190 macosx/Info.plist \
191 macosx/git-gui.icns \
192 macosx/AppMain.tcl \
e98d6df7 193 $(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE)
d794d9e7
JH
194 $(QUIET_GEN)rm -rf '$@' '$@'+ && \
195 mkdir -p '$@'+/Contents/MacOS && \
196 mkdir -p '$@'+/Contents/Resources/Scripts && \
e98d6df7 197 cp '$(subst ','\'',$(subst \,,$(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE)))' \
d794d9e7
JH
198 '$@'+/Contents/MacOS && \
199 cp macosx/git-gui.icns '$@'+/Contents/Resources && \
200 sed -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
e98d6df7 201 -e 's/@@GITGUI_TKEXECUTABLE@@/$(TKEXECUTABLE)/g' \
d794d9e7
JH
202 macosx/Info.plist \
203 >'$@'+/Contents/Info.plist && \
204 sed -e 's|@@gitexecdir@@|$(gitexecdir_SQ)|' \
205 -e 's|@@GITGUI_LIBDIR@@|$(libdir_SED)|' \
206 macosx/AppMain.tcl \
207 >'$@'+/Contents/Resources/Scripts/AppMain.tcl && \
208 mv '$@'+ '$@'
209endif
210
211ifdef GITGUI_WINDOWS_WRAPPER
212GITGUI_MAIN := git-gui.tcl
5f5dbd71 213
d794d9e7
JH
214git-gui: windows/git-gui.sh
215 cp $< $@
216endif
c63a3ad2 217
d794d9e7 218$(GITGUI_MAIN): git-gui.sh GIT-VERSION-FILE GIT-GUI-VARS
eec10252 219 $(QUIET_GEN)rm -f $@ $@+ && \
3ed02de2 220 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
12644fa9 221 -e 's|@@SHELL_PATH@@|$(SHELL_PATH_SQ)|' \
d794d9e7
JH
222 -e '1,30s|^ argv0=$$0| argv0=$(GITGUI_SCRIPT)|' \
223 -e '1,30s|^ exec wish | exec '\''$(TCLTK_PATH_SED)'\'' |' \
67c75759 224 -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
d794d9e7
JH
225 -e 's|@@GITGUI_RELATIVE@@|$(GITGUI_RELATIVE)|' \
226 -e '$(GITGUI_RELATIVE)s|@@GITGUI_LIBDIR@@|$(libdir_SED)|' \
227 git-gui.sh >$@+ && \
eec10252 228 chmod +x $@+ && \
b4d2b04c
JH
229 mv $@+ $@
230
d794d9e7
JH
231XGETTEXT ?= xgettext
232ifdef NO_MSGFMT
233 MSGFMT ?= $(TCL_PATH) po/po2msg.sh
234else
235 MSGFMT ?= msgfmt
a6828f53 236 ifneq ($(shell $(MSGFMT) --tcl -l C -d . /dev/null 2>/dev/null; echo $$?),0)
cab31fa0
JH
237 MSGFMT := $(TCL_PATH) po/po2msg.sh
238 endif
d794d9e7
JH
239endif
240
241msgsdir = $(gg_libdir)/msgs
242msgsdir_SQ = $(subst ','\'',$(msgsdir))
243PO_TEMPLATE = po/git-gui.pot
244ALL_POFILES = $(wildcard po/*.po)
245ALL_MSGFILES = $(subst .po,.msg,$(ALL_POFILES))
246
247$(PO_TEMPLATE): $(SCRIPT_SH) $(ALL_LIBFILES)
248 $(XGETTEXT) -kmc -LTcl -o $@ $(SCRIPT_SH) $(ALL_LIBFILES)
249update-po:: $(PO_TEMPLATE)
250 $(foreach p, $(ALL_POFILES), echo Updating $p ; msgmerge -U $p $(PO_TEMPLATE) ; )
251$(ALL_MSGFILES): %.msg : %.po
d9f40593 252 $(QUIET_MSGFMT0)$(MSGFMT) --statistics --tcl -l $(basename $(notdir $<)) -d $(dir $@) $< $(QUIET_MSGFMT1)
b4d2b04c 253
d794d9e7 254lib/tclIndex: $(ALL_LIBFILES) GIT-GUI-VARS
e986e26a
JH
255 $(QUIET_INDEX)if echo \
256 $(foreach p,$(PRELOAD_FILES),source $p\;) \
da10ea37 257 auto_mkindex lib $(patsubst lib/%,%,$(sort $(ALL_LIBFILES))) \
e986e26a
JH
258 | $(TCL_PATH) $(QUIET_2DEVNULL); then : ok; \
259 else \
fb7dfaa7 260 echo >&2 " * $(TCL_PATH) failed; using unoptimized loading"; \
e986e26a
JH
261 rm -f $@ ; \
262 echo '# Autogenerated by git-gui Makefile' >$@ && \
263 echo >>$@ && \
3eae3087 264 $(foreach p,$(PRELOAD_FILES) $(sort $(ALL_LIBFILES)),echo '$(subst lib/,,$p)' >>$@ &&) \
e986e26a
JH
265 echo >>$@ ; \
266 fi
5f5dbd71 267
5f5dbd71
SP
268TRACK_VARS = \
269 $(subst ','\'',SHELL_PATH='$(SHELL_PATH_SQ)') \
e986e26a 270 $(subst ','\'',TCL_PATH='$(TCL_PATH_SQ)') \
5f5dbd71 271 $(subst ','\'',TCLTK_PATH='$(TCLTK_PATH_SQ)') \
c63a3ad2 272 $(subst ','\'',gitexecdir='$(gitexecdir_SQ)') \
9269df96 273 $(subst ','\'',gg_libdir='$(libdir_SQ)') \
d794d9e7 274 GITGUI_MACOSXAPP=$(GITGUI_MACOSXAPP) \
5f5dbd71
SP
275#end TRACK_VARS
276
b30ccd75 277GIT-GUI-VARS: FORCE
5f5dbd71
SP
278 @VARS='$(TRACK_VARS)'; \
279 if test x"$$VARS" != x"`cat $@ 2>/dev/null`" ; then \
fb7dfaa7
JH
280 echo >&2 " * new locations or Tcl/Tk interpreter"; \
281 echo >$@ "$$VARS"; \
5f5dbd71 282 fi
3ed02de2 283
d794d9e7
JH
284ifdef GITGUI_MACOSXAPP
285all:: git-gui Git\ Gui.app
286endif
287ifdef GITGUI_WINDOWS_WRAPPER
288all:: git-gui
289endif
290all:: $(GITGUI_MAIN) lib/tclIndex $(ALL_MSGFILES)
b4d2b04c
JH
291
292install: all
82ff9d2c
JH
293 $(QUIET)$(INSTALL_D0)'$(DESTDIR_SQ)$(gitexecdir_SQ)' $(INSTALL_D1)
294 $(QUIET)$(INSTALL_X0)git-gui $(INSTALL_X1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
f6576f4c 295 $(QUIET)$(INSTALL_X0)git-gui--askpass $(INSTALL_X1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
82ff9d2c 296 $(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(INSTALL_L0)'$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' $(INSTALL_L1)'$(DESTDIR_SQ)$(gitexecdir_SQ)/git-gui' $(INSTALL_L2)'$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' $(INSTALL_L3) &&) true
d794d9e7
JH
297ifdef GITGUI_WINDOWS_WRAPPER
298 $(QUIET)$(INSTALL_R0)git-gui.tcl $(INSTALL_R1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
299endif
82ff9d2c
JH
300 $(QUIET)$(INSTALL_D0)'$(DESTDIR_SQ)$(libdir_SQ)' $(INSTALL_D1)
301 $(QUIET)$(INSTALL_R0)lib/tclIndex $(INSTALL_R1) '$(DESTDIR_SQ)$(libdir_SQ)'
d794d9e7
JH
302ifdef GITGUI_MACOSXAPP
303 $(QUIET)$(INSTALL_A0)'Git Gui.app' $(INSTALL_A1) '$(DESTDIR_SQ)$(libdir_SQ)'
304 $(QUIET)$(INSTALL_X0)git-gui.tcl $(INSTALL_X1) '$(DESTDIR_SQ)$(libdir_SQ)'
305endif
306 $(QUIET)$(foreach p,$(ALL_LIBFILES) $(NONTCL_LIBFILES), $(INSTALL_R0)$p $(INSTALL_R1) '$(DESTDIR_SQ)$(libdir_SQ)' &&) true
307 $(QUIET)$(INSTALL_D0)'$(DESTDIR_SQ)$(msgsdir_SQ)' $(INSTALL_D1)
308 $(QUIET)$(foreach p,$(ALL_MSGFILES), $(INSTALL_R0)$p $(INSTALL_R1) '$(DESTDIR_SQ)$(msgsdir_SQ)' &&) true
b4d2b04c 309
9269df96
JH
310uninstall:
311 $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
312 $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui $(REMOVE_F1)
f6576f4c 313 $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui--askpass $(REMOVE_F1)
9269df96 314 $(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/$p $(REMOVE_F1) &&) true
d794d9e7
JH
315ifdef GITGUI_WINDOWS_WRAPPER
316 $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui.tcl $(REMOVE_F1)
317endif
9269df96
JH
318 $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(libdir_SQ)'
319 $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)'/tclIndex $(REMOVE_F1)
d794d9e7
JH
320ifdef GITGUI_MACOSXAPP
321 $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)/Git Gui.app' $(REMOVE_F1)
322 $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)'/git-gui.tcl $(REMOVE_F1)
323endif
324 $(QUIET)$(foreach p,$(ALL_LIBFILES) $(NONTCL_LIBFILES), $(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)'/$(notdir $p) $(REMOVE_F1) &&) true
325 $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(msgsdir_SQ)'
326 $(QUIET)$(foreach p,$(ALL_MSGFILES), $(REMOVE_F0)'$(DESTDIR_SQ)$(msgsdir_SQ)'/$(notdir $p) $(REMOVE_F1) &&) true
9269df96 327 $(QUIET)$(REMOVE_D0)'$(DESTDIR_SQ)$(gitexecdir_SQ)' $(REMOVE_D1)
d794d9e7 328 $(QUIET)$(REMOVE_D0)'$(DESTDIR_SQ)$(msgsdir_SQ)' $(REMOVE_D1)
9269df96
JH
329 $(QUIET)$(REMOVE_D0)'$(DESTDIR_SQ)$(libdir_SQ)' $(REMOVE_D1)
330 $(QUIET)$(REMOVE_D0)`dirname '$(DESTDIR_SQ)$(libdir_SQ)'` $(REMOVE_D1)
331
3ed02de2 332dist-version:
67c75759
JH
333 @mkdir -p $(TARDIR)
334 @echo $(GITGUI_VERSION) > $(TARDIR)/version
335
b4d2b04c 336clean::
d794d9e7
JH
337 $(RM_RF) $(GITGUI_MAIN) lib/tclIndex po/*.msg
338 $(RM_RF) GIT-VERSION-FILE GIT-GUI-VARS
339ifdef GITGUI_MACOSXAPP
340 $(RM_RF) 'Git Gui.app'* git-gui
341endif
342ifdef GITGUI_WINDOWS_WRAPPER
343 $(RM_RF) git-gui
344endif
b4d2b04c 345
9269df96 346.PHONY: all install uninstall dist-version clean
b30ccd75 347.PHONY: FORCE