author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Thu, 25 Sep 2014 01:10:01 +0300 | |
changeset 138 | 23cd36180bf9 |
parent 84 | 58adeb5e4264 |
child 175 | 9a83576eec4c |
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 |
84
58adeb5e4264
Add missing file to dist and deploy.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
82
diff
changeset
|
111 |
WWW_FILES := $(JS_FILES) $(HTML_FILES) $(RST_HTML_FILES) |
48 | 112 |
|
82 | 113 |
DIST_FILES = $(WWW_FILES) $(RST_FILES) VERSION |
48 | 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; \ |
|
80
1ed275e69293
Make README as index.html in SF.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
77
diff
changeset
|
149 |
echo "put README.html index.html"; \ |
48 | 150 |
echo 'quit'; \ |
151 |
) | sftp -b - $(SF_USER),$(sfpkgname)@web.sourceforge.net |
|
152 |
||
153 |
.PHONY: deploy2sf-release |
|
154 |
deploy2sf-release: deploy-check $(DIST_TARBALLS) |
|
155 |
( echo 'cd /home/frs/project/$(shell v=$(sfpkgname); echo $${v:0:1}/$${v:0:2})/$(sfpkgname)'; \ |
|
156 |
echo "put README.rst"; \ |
|
157 |
echo "chmod 644 README.rst"; \ |
|
158 |
echo "mkdir v$(vmajor).$(vminor)"; \ |
|
159 |
echo "cd v$(vmajor).$(vminor)"; \ |
|
160 |
for f in $(DIST_TARBALLS); do \ |
|
161 |
echo "put $$f"; \ |
|
162 |
echo "chmod 644 $$f"; \ |
|
163 |
done; \ |
|
164 |
echo 'quit'; \ |
|
165 |
) | sftp -b - $(SF_USER),$(sfpkgname)@frs.sourceforge.net |
|
166 |
||
167 |
.PHONY: deploy-check |
|
168 |
deploy-check: |
|
169 |
\ |
|
170 |
case ${visclean} in \ |
|
171 |
no) echo "Local changes found. Build stop."; \ |
|
172 |
exit 1;; \ |
|
173 |
esac |
|
174 |
\ |
|
175 |
case $(vatrelease) in \ |
|
176 |
no) echo "We are not at release. Build stop."; \ |
|
177 |
exit 1;; \ |
|
178 |
esac |
|
179 |
||
180 |
################################################################ |
|
181 |
# Dist targets. |
|
182 |
||
183 |
.PHONY: dist |
|
184 |
dist: dist-bin |
|
185 |
||
186 |
.PHONY: dist-bin |
|
49
4b48e9e06000
Fix dist build target.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
48
diff
changeset
|
187 |
dist-bin: $(DIST_TARBALLS) |
48 | 188 |
|
189 |
%.tar.gz: % |
|
190 |
tar zcf $*.tar.gz $* |
|
191 |
||
192 |
%.tar.bz2: % |
|
193 |
tar jcf $*.tar.bz2 $* |
|
194 |
||
49
4b48e9e06000
Fix dist build target.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
48
diff
changeset
|
195 |
%.zip: % |
4b48e9e06000
Fix dist build target.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
48
diff
changeset
|
196 |
zip -r $*.zip $* |
4b48e9e06000
Fix dist build target.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
48
diff
changeset
|
197 |
|
48 | 198 |
$(DIST_DIR): $(DIST_FILES) |
199 |
rm -rf $@ |
|
200 |
mkdir $@ |
|
201 |
cp $(DIST_FILES) $@ |
|
202 |
||
203 |
################################################################ |
|
77 | 204 |
# Documentation targets. |
205 |
||
206 |
.PHONY: docs |
|
207 |
docs: rst2html |
|
208 |
||
209 |
.PHONY: rst2html |
|
210 |
rst2html: $(RST_HTML_FILES) |
|
211 |
||
212 |
$(RST_HTML_FILES): $(RST_COMMON_FILES) |
|
213 |
||
214 |
$(RST_HTML_FILES): %.html: %.rst rst.css header.rst VERSION.rst $(BUILD_SCRIPTS) |
|
215 |
$(RST2HTML) $(RST2HTML_FLAGS) --stylesheet=rst.css $*.rst $@ |
|
216 |
||
217 |
VERSION.rst: VERSION $(BUILD_SCRIPTS) |
|
218 |
{ \ |
|
219 |
echo 'For ``$(pkgname)`` version: ``$(vmajor).$(vminor)``.'; \ |
|
220 |
echo; \ |
|
221 |
case ${visclean} in \ |
|
222 |
yes) echo 'Source files are at revision: ``$(vrev)``.';; \ |
|
223 |
no) echo 'Some source files was modified from revision: ``$(vrev)``.';; \ |
|
224 |
esac; \ |
|
225 |
echo; \ |
|
226 |
case ${vatrelease} in \ |
|
227 |
yes) echo 'Package is at release state.';; \ |
|
228 |
no) echo 'Package is far from release state by $(vtagdist) changes.';; \ |
|
229 |
esac; \ |
|
230 |
echo; \ |
|
231 |
echo 'Build date: ``'$$(date +%F)'``.'; \ |
|
232 |
} >$@ |
|
233 |
||
234 |
################################################################ |
|
48 | 235 |
# Helpers targets. |
236 |
||
237 |
.PHONY: help |
|
238 |
help: |
|
239 |
@\ |
|
240 |
echo; \ |
|
241 |
echo Current configuration:; \ |
|
242 |
echo; \ |
|
243 |
sed 's=^= =' <VERSION |
|
244 |
@if [ -f Makefile.config ]; then \ |
|
245 |
echo; \ |
|
246 |
echo User configuration:; \ |
|
247 |
echo; \ |
|
248 |
sed 's=^= =' <Makefile.config; \ |
|
249 |
fi |
|
250 |
@\ |
|
251 |
echo; \ |
|
252 |
echo Supported targets:; \ |
|
253 |
echo; \ |
|
254 |
sed -n -e '/^[[:alnum:]_-]*:/{s=^\(.*\):.*= \1=;p;}' $(BUILD_SCRIPTS) |
|
255 |
||
57
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
256 |
.PHONY: jsdoc |
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
257 |
jsdoc: |
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
258 |
jsdoc -a -p -d=$(JSDOC_DIR) $(JS_FILES) |
94e1b2d0bd31
Add JSDoc annotation.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
50
diff
changeset
|
259 |
|
48 | 260 |
################################################################ |
261 |
# Clean targets. |
|
262 |
||
263 |
.PHONY: distclean |
|
264 |
distclean: clean |
|
265 |
rm -f VERSION |
|
266 |
||
267 |
.PHONY: clean |
|
268 |
clean: |
|
77 | 269 |
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
|
270 |