author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Tue, 31 Jan 2017 03:41:07 +0200 | |
changeset 190 | d1b12b602915 |
parent 185 | 59df68b203ca |
permissions | -rw-r--r-- |
48 | 1 |
# |
2 |
# You can override such variables in Makefile.config: |
|
3 |
# |
|
185
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
4 |
# FORCE Non empty allow deploy with unclean working state. |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
5 |
# |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
6 |
# SF_USER SourceForge user name. |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
7 |
# WWW_SRV_NAME |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
8 |
# WWW_SRV_USER |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
9 |
# WWW_SRV_DIR |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
10 |
# HG_SRV_NAME |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
11 |
# HG_SRV_USER |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
12 |
# HG_SRV_DIR |
48 | 13 |
|
14 |
################################################################ |
|
15 |
# Standard GNU Makefile settings. |
|
16 |
||
17 |
SHELL = /bin/bash |
|
18 |
export PATH := /bin:/usr/bin:${PATH} |
|
19 |
||
20 |
# Disable built in pattern rules. |
|
21 |
MAKEFLAGS += -r |
|
22 |
# Disable built in variables. |
|
23 |
MAKEFLAGS += -R |
|
24 |
# Disable built in suffix rules. |
|
25 |
.SUFFIXES: |
|
26 |
# Delete target file if command fails. |
|
27 |
.DELETE_ON_ERROR: |
|
28 |
# Default target. |
|
29 |
.DEFAULT_GOAL = help |
|
30 |
||
31 |
################################################################ |
|
32 |
# Build script definitions. |
|
33 |
||
34 |
BUILD_SCRIPTS := $(firstword $(MAKEFILE_LIST)) |
|
35 |
||
36 |
ifneq '' '$(wildcard Makefile.config)' |
|
37 |
include Makefile.config |
|
38 |
BUILD_SCRIPTS += Makefile.config |
|
39 |
endif |
|
40 |
||
41 |
################################################################ |
|
42 |
# Version extracting/generation. |
|
43 |
||
44 |
# Prevent making distribution with wrong version. |
|
45 |
ifneq '' '$(filter deploy% dist%,$(MAKECMDGOALS))' |
|
46 |
ifeq '' '$(MAKE_RESTARTS)' |
|
47 |
$(info $(shell rm -f VERSION)) |
|
48 |
endif |
|
49 |
endif |
|
50 |
||
51 |
# Here are vmajor and vminor. Look README section "Versioning rules." |
|
52 |
-include VERSION |
|
53 |
||
54 |
VERSION: |
|
55 |
\ |
|
56 |
vtagdist=$$(hg log -r . --template '{latesttagdistance}'); \ |
|
57 |
vatrelease=$$([ $$vtagdist -le 1 ] && echo yes || echo no); \ |
|
58 |
vtag=$$(hg log -r . --template '{latesttag}'); \ |
|
50
0bda4161d1b9
Fix tag prefix (after copy/paste).
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
49
diff
changeset
|
59 |
vmajor=$${vtag#v}; \ |
48 | 60 |
vmajor=$${vmajor%%.*}; \ |
61 |
vminor=$${vtag#*.}; \ |
|
62 |
vrev=$$(hg id -i); \ |
|
63 |
visclean=$$(case $$vrev in *+) echo no;; *) echo yes;; esac); \ |
|
64 |
vrev=$${vrev%+}; \ |
|
65 |
{ \ |
|
66 |
echo "vrev=$$vrev"; \ |
|
67 |
echo "vtag=$$vtag"; \ |
|
68 |
echo "vtagdist=$$vtagdist"; \ |
|
69 |
echo "visclean=$$visclean"; \ |
|
70 |
echo "vatrelease=$$vatrelease"; \ |
|
71 |
echo "vmajor=$$vmajor"; \ |
|
72 |
echo "vminor=$$vminor"; \ |
|
73 |
} >VERSION |
|
74 |
||
75 |
################################################################ |
|
76 |
# Determine platform/environment. |
|
77 |
||
78 |
host_os = unix |
|
79 |
ifneq '' '$(COMSPEC)' |
|
80 |
ifneq '' '$(WINDIR)' |
|
81 |
# Probably under Windows. |
|
82 |
host_os = windows |
|
83 |
ifneq '' '$(wildcard /etc/setup/*cygwin*)' |
|
84 |
# Probably under Cygwin. |
|
85 |
host_os = cygwin |
|
86 |
endif |
|
87 |
endif |
|
88 |
endif |
|
89 |
||
90 |
################################################################ |
|
77 | 91 |
# Build tools definition/switches. |
92 |
||
93 |
RST_WARNING_FLAGS := --halt warning |
|
94 |
RST_FLAGS := --strip-comments |
|
95 |
RST_FLAGS += $(RST_WARNING_FLAGS) |
|
96 |
||
97 |
RST2HTML := rst2html |
|
98 |
ifeq '$(host_os)' 'cygwin' |
|
99 |
RST2HTML := rst2html.py |
|
100 |
endif |
|
101 |
RST2HTML_FLAGS := $(RST_FLAGS) |
|
102 |
||
103 |
################################################################ |
|
48 | 104 |
# Project dirs/files. |
105 |
||
106 |
pkgname = 2048-js-ai |
|
107 |
sfpkgname = js-2048-ai |
|
108 |
fullpkgname = $(pkgname)-$(vmajor).$(vminor) |
|
109 |
||
110 |
DIST_DIR = $(fullpkgname) |
|
111 |
||
77 | 112 |
RST_GEN_FILES := VERSION.rst |
113 |
RST_COMMON_FILES := VERSION.rst header.rst |
|
114 |
RST_FILES := $(filter-out $(RST_COMMON_FILES),$(sort $(wildcard *.rst) $(RST_GEN_FILES))) |
|
115 |
RST_HTML_FILES := $(RST_FILES:.rst=.html) |
|
116 |
||
57
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
117 |
JS_FILES := $(wildcard *.js) |
77 | 118 |
HTML_FILES := 2048.html |
178
ef24ad27c83d
Add deploy dependency on CSS file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
175
diff
changeset
|
119 |
CSS_FILES := rst.css |
ef24ad27c83d
Add deploy dependency on CSS file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
175
diff
changeset
|
120 |
WWW_FILES := $(JS_FILES) $(HTML_FILES) $(CSS_FILES) $(RST_HTML_FILES) |
48 | 121 |
|
82 | 122 |
DIST_FILES = $(WWW_FILES) $(RST_FILES) VERSION |
48 | 123 |
|
124 |
DIST_TARBALLS = $(DIST_DIR).tar.gz $(DIST_DIR).zip |
|
125 |
||
57
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
126 |
JSDOC_DIR := jsdoc |
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
127 |
|
48 | 128 |
################################################################ |
129 |
# Deploy targets. |
|
130 |
||
185
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
131 |
SF_USER ?= gavenkoa |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
132 |
|
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
133 |
WWW_SRV_NAME ?= defun.work |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
134 |
WWW_SRV_USER ?= user |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
135 |
WWW_SRV_DIR ?= /srv/www/2048 |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
136 |
HG_SRV_NAME ?= hg.defun.work |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
137 |
HG_SRV_USER ?= user |
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
138 |
HG_SRV_DIR ?= /srv/hg/2048-js-ai |
48 | 139 |
|
140 |
.PHONY: deploy |
|
175
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
141 |
deploy: deploy2defun deploy2sf |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
142 |
|
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
143 |
.PHONY: deploy2defun |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
144 |
deploy2defun: deploy2defun-src deploy2defun-www |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
145 |
|
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
146 |
.PHONY: deploy2defun-src |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
147 |
deploy2defun-src: |
185
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
148 |
hg push ssh://$(HG_SRV_USER)@$(HG_SRV_NAME)/$(HG_SRV_DIR)/ || [ $$? = 1 ] |
175
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
149 |
|
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
150 |
.PHONY: deploy2defun-www |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
151 |
deploy2defun-www: deploy-check $(WWW_FILES) |
185
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
152 |
( echo 'cd $(WWW_SRV_DIR)'; \ |
175
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
153 |
for f in $(WWW_FILES); do \ |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
154 |
echo "put $$f"; \ |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
155 |
echo "chmod 644 $$f"; \ |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
156 |
done; \ |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
157 |
echo "put 2048.html index.html"; \ |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
158 |
echo 'quit'; \ |
185
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
159 |
) | sftp -b - $(WWW_SRV_USER)@$(WWW_SRV_NAME) |
48 | 160 |
|
161 |
# First time you deploy to SourceForge (sf) you need manually login to: |
|
162 |
# $ sftp $(SF_USER),$(pkgname)@web.sourceforge.net |
|
163 |
# as it may require interactive input for accepting server public key. |
|
164 |
# Next time any action fully automated. |
|
165 |
||
166 |
.PHONY: deploy2sf |
|
167 |
deploy2sf: deploy2sf-src deploy2sf-www deploy2sf-release |
|
168 |
||
169 |
.PHONY: deploy2sf-src |
|
170 |
deploy2sf-src: |
|
171 |
hg push ssh://$(SF_USER)@hg.code.sf.net/p/$(sfpkgname)/hg || [ $$? = 1 ] |
|
172 |
||
173 |
# Will be accessed via http://$(pkgname).sourceforge.net |
|
174 |
.PHONY: deploy2sf-www |
|
175 |
deploy2sf-www: deploy-check $(WWW_FILES) |
|
176 |
( echo 'cd htdocs'; \ |
|
177 |
for f in $(WWW_FILES); do \ |
|
178 |
echo "put $$f"; \ |
|
179 |
echo "chmod 644 $$f"; \ |
|
180 |
done; \ |
|
175
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
181 |
echo "put 2048.html index.html"; \ |
48 | 182 |
echo 'quit'; \ |
183 |
) | sftp -b - $(SF_USER),$(sfpkgname)@web.sourceforge.net |
|
184 |
||
185 |
.PHONY: deploy2sf-release |
|
186 |
deploy2sf-release: deploy-check $(DIST_TARBALLS) |
|
187 |
( echo 'cd /home/frs/project/$(shell v=$(sfpkgname); echo $${v:0:1}/$${v:0:2})/$(sfpkgname)'; \ |
|
188 |
echo "put README.rst"; \ |
|
189 |
echo "chmod 644 README.rst"; \ |
|
183
e3293e79262b
Fix sftp error: Couldn't create directory: Failure
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
178
diff
changeset
|
190 |
echo "-mkdir v$(vmajor).$(vminor)"; \ |
48 | 191 |
echo "cd v$(vmajor).$(vminor)"; \ |
192 |
for f in $(DIST_TARBALLS); do \ |
|
193 |
echo "put $$f"; \ |
|
194 |
echo "chmod 644 $$f"; \ |
|
195 |
done; \ |
|
196 |
echo 'quit'; \ |
|
197 |
) | sftp -b - $(SF_USER),$(sfpkgname)@frs.sourceforge.net |
|
198 |
||
199 |
.PHONY: deploy-check |
|
200 |
deploy-check: |
|
201 |
\ |
|
185
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
202 |
case "$(FORCE)$(visclean)" in \ |
48 | 203 |
no) echo "Local changes found. Build stop."; \ |
204 |
exit 1;; \ |
|
205 |
esac |
|
206 |
\ |
|
185
59df68b203ca
Add option to allow deploy with unclean working state. Add
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
183
diff
changeset
|
207 |
case "$(FORCE)$(vatrelease)" in \ |
48 | 208 |
no) echo "We are not at release. Build stop."; \ |
209 |
exit 1;; \ |
|
210 |
esac |
|
211 |
||
212 |
################################################################ |
|
213 |
# Dist targets. |
|
214 |
||
215 |
.PHONY: dist |
|
216 |
dist: dist-bin |
|
217 |
||
218 |
.PHONY: dist-bin |
|
49
4b48e9e06000
Fix dist build target.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
48
diff
changeset
|
219 |
dist-bin: $(DIST_TARBALLS) |
48 | 220 |
|
221 |
%.tar.gz: % |
|
222 |
tar zcf $*.tar.gz $* |
|
223 |
||
224 |
%.tar.bz2: % |
|
225 |
tar jcf $*.tar.bz2 $* |
|
226 |
||
49
4b48e9e06000
Fix dist build target.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
48
diff
changeset
|
227 |
%.zip: % |
4b48e9e06000
Fix dist build target.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
48
diff
changeset
|
228 |
zip -r $*.zip $* |
4b48e9e06000
Fix dist build target.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
48
diff
changeset
|
229 |
|
48 | 230 |
$(DIST_DIR): $(DIST_FILES) |
231 |
rm -rf $@ |
|
232 |
mkdir $@ |
|
233 |
cp $(DIST_FILES) $@ |
|
234 |
||
235 |
################################################################ |
|
77 | 236 |
# Documentation targets. |
237 |
||
238 |
.PHONY: docs |
|
175
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
239 |
docs: html |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
240 |
|
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
241 |
.PHONY: html |
9a83576eec4c
Deploy to personal home page. Use game itself as index.html.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
84
diff
changeset
|
242 |
html: rst2html |
77 | 243 |
|
244 |
.PHONY: rst2html |
|
245 |
rst2html: $(RST_HTML_FILES) |
|
246 |
||
247 |
$(RST_HTML_FILES): $(RST_COMMON_FILES) |
|
248 |
||
249 |
$(RST_HTML_FILES): %.html: %.rst rst.css header.rst VERSION.rst $(BUILD_SCRIPTS) |
|
250 |
$(RST2HTML) $(RST2HTML_FLAGS) --stylesheet=rst.css $*.rst $@ |
|
251 |
||
252 |
VERSION.rst: VERSION $(BUILD_SCRIPTS) |
|
253 |
{ \ |
|
254 |
echo 'For ``$(pkgname)`` version: ``$(vmajor).$(vminor)``.'; \ |
|
255 |
echo; \ |
|
256 |
case ${visclean} in \ |
|
257 |
yes) echo 'Source files are at revision: ``$(vrev)``.';; \ |
|
258 |
no) echo 'Some source files was modified from revision: ``$(vrev)``.';; \ |
|
259 |
esac; \ |
|
260 |
echo; \ |
|
261 |
case ${vatrelease} in \ |
|
262 |
yes) echo 'Package is at release state.';; \ |
|
263 |
no) echo 'Package is far from release state by $(vtagdist) changes.';; \ |
|
264 |
esac; \ |
|
265 |
echo; \ |
|
266 |
echo 'Build date: ``'$$(date +%F)'``.'; \ |
|
267 |
} >$@ |
|
268 |
||
269 |
################################################################ |
|
48 | 270 |
# Helpers targets. |
271 |
||
272 |
.PHONY: help |
|
273 |
help: |
|
274 |
@\ |
|
275 |
echo; \ |
|
276 |
echo Current configuration:; \ |
|
277 |
echo; \ |
|
278 |
sed 's=^= =' <VERSION |
|
279 |
@if [ -f Makefile.config ]; then \ |
|
280 |
echo; \ |
|
281 |
echo User configuration:; \ |
|
282 |
echo; \ |
|
283 |
sed 's=^= =' <Makefile.config; \ |
|
284 |
fi |
|
285 |
@\ |
|
286 |
echo; \ |
|
287 |
echo Supported targets:; \ |
|
288 |
echo; \ |
|
289 |
sed -n -e '/^[[:alnum:]_-]*:/{s=^\(.*\):.*= \1=;p;}' $(BUILD_SCRIPTS) |
|
290 |
||
57
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
291 |
.PHONY: jsdoc |
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
292 |
jsdoc: |
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
293 |
jsdoc -a -p -d=$(JSDOC_DIR) $(JS_FILES) |
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
294 |
|
48 | 295 |
################################################################ |
296 |
# Clean targets. |
|
297 |
||
298 |
.PHONY: distclean |
|
299 |
distclean: clean |
|
300 |
rm -f VERSION |
|
301 |
||
302 |
.PHONY: clean |
|
303 |
clean: |
|
77 | 304 |
rm -rf $(JSDOC_DIR) $(RST_GEN_FILES) $(RST_HTML_FILES) $(DIST_DIR) $(DIST_TARBALLS) |
57
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
305 |