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