-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
243 lines (194 loc) · 6.52 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#
# -*- Configuration -*-
#
# inputs
SRC_DIR = ./src
INTRO = $(SRC_DIR)/intro.js
OUTRO = $(SRC_DIR)/outro.js
AMD_OPEN = $(SRC_DIR)/amd-open.js
AMD_CLOSE = $(SRC_DIR)/amd-close.js
PJS_SRC = ./node_modules/pjs/src/p.js
BASE_SOURCES = \
$(PJS_SRC) \
$(SRC_DIR)/tree.js \
$(SRC_DIR)/cursor.js \
$(SRC_DIR)/controller.js \
$(SRC_DIR)/publicapi.js \
$(SRC_DIR)/services/*.util.js \
$(SRC_DIR)/services/*.js \
$(SRC_DIR)/configuration/symbols/*.js
SOURCES_FULL = \
$(BASE_SOURCES) \
$(SRC_DIR)/commands/*.js \
$(SRC_DIR)/commands/*/*.js
SOURCES_BASIC = \
$(BASE_SOURCES) \
$(SRC_DIR)/commands/math.js \
$(SRC_DIR)/commands/math/basicSymbols.js \
$(SRC_DIR)/commands/math/commands.js
CSS_DIR = $(SRC_DIR)/css
CSS_MAIN = $(CSS_DIR)/main.less
CSS_SOURCES = $(shell find $(CSS_DIR) -name '*.less' -not -name 'font.less')
FONT_CSS_SOURCES = $(shell find $(CSS_DIR) -name 'font.less')
FONT_SOURCE = $(SRC_DIR)/font
FONT_TARGET = $(BUILD_DIR)/font
UNIT_TESTS = ./test/unit/*.test.js
# outputs
VERSION ?= $(shell node -e "console.log(require('./package.json').version)")
BUILD_DIR = ./build
BUILD_JS = $(BUILD_DIR)/mathquill.js
BASIC_JS = $(BUILD_DIR)/mathquill-basic.js
BUILD_CSS = $(BUILD_DIR)/mathquill.css
BASIC_CSS = $(BUILD_DIR)/mathquill-basic.css
BUILD_TEST = $(BUILD_DIR)/mathquill.test.js
UGLY_JS = $(BUILD_DIR)/mathquill.min.js
UGLY_BASIC_JS = $(BUILD_DIR)/mathquill-basic.min.js
CLEAN += $(BUILD_DIR)/*
DISTDIR = ./mathquill-$(VERSION)
DIST = $(DISTDIR).tgz
CLEAN += $(DIST)
MATHSPACE_JS = $(BUILD_DIR)/mathquill-mathspace.js
MATHSPACE_CSS = $(BUILD_DIR)/mathquill-mathspace.css
MATHSPACE_FONT_CSS = $(BUILD_DIR)/mathquill-font-mathspace.css
MATHSPACE_CSS_MAIN = $(CSS_DIR)/mathspace/main.less
MATHSPACE_FONT_CSS_MAIN = $(CSS_DIR)/mathspace/font.less
# programs and flags
UGLIFY ?= ./node_modules/.bin/uglifyjs
UGLIFY_OPTS ?= --mangle --compress hoist_vars=true
LESSC ?= ./node_modules/.bin/lessc
LESS_OPTS ?=
ifdef OMIT_FONT_FACE
LESS_OPTS += --modify-var="omit-font-face=true"
endif
# Empty target files whose Last Modified timestamps are used to record when
# something like `npm install` last happened (which, for example, would then be
# compared with its dependency, package.json, so if package.json has been
# modified since the last `npm install`, Make will `npm install` again).
# http://www.gnu.org/software/make/manual/html_node/Empty-Targets.html#Empty-Targets
NODE_MODULES_INSTALLED = ./node_modules/.installed--used_by_Makefile
BUILD_DIR_EXISTS = $(BUILD_DIR)/.exists--used_by_Makefile
# environment constants
#
# -*- Build tasks -*-
#
.PHONY: all basic dev js uglify css font dist mathspace clean
all: font css uglify
basic: $(UGLY_BASIC_JS) $(BASIC_CSS)
# dev is like all, but without minification
dev: font css js
js: $(BUILD_JS)
uglify: $(UGLY_JS)
css: $(BUILD_CSS)
font: $(FONT_TARGET)
dist: $(DIST)
mathspace: $(BUILD_JS) $(MATHSPACE_CSS) $(MATHSPACE_FONT_CSS)
clean:
rm -rf $(CLEAN)
$(PJS_SRC): $(NODE_MODULES_INSTALLED)
$(BUILD_JS): $(INTRO) $(SOURCES_FULL) $(OUTRO) $(BUILD_DIR_EXISTS)
cat $^ | ./script/escape-non-ascii > $@
$(UGLY_JS): $(BUILD_JS) $(NODE_MODULES_INSTALLED)
$(UGLIFY) $(UGLIFY_OPTS) < $< > $@
$(BASIC_JS): $(INTRO) $(SOURCES_BASIC) $(OUTRO) $(BUILD_DIR_EXISTS)
cat $^ | ./script/escape-non-ascii > $@
$(UGLY_BASIC_JS): $(BASIC_JS) $(NODE_MODULES_INSTALLED)
$(UGLIFY) $(UGLIFY_OPTS) < $< > $@
$(BUILD_CSS): $(CSS_SOURCES) $(NODE_MODULES_INSTALLED) $(BUILD_DIR_EXISTS)
$(LESSC) $(LESS_OPTS) $(CSS_MAIN) > $@
$(BASIC_CSS): $(CSS_SOURCES) $(NODE_MODULES_INSTALLED) $(BUILD_DIR_EXISTS)
$(LESSC) --modify-var="basic=true" $(LESS_OPTS) $(CSS_MAIN) > $@
$(NODE_MODULES_INSTALLED): package.json
npm install
touch $(NODE_MODULES_INSTALLED)
$(BUILD_DIR_EXISTS):
mkdir -p $(BUILD_DIR)
touch $(BUILD_DIR_EXISTS)
$(FONT_TARGET): $(FONT_SOURCE) $(BUILD_DIR_EXISTS)
rm -rf $@
cp -r $< $@
$(DIST): $(UGLY_JS) $(BUILD_JS) $(BUILD_CSS) $(FONT_TARGET)
rm -rf $(DISTDIR)
cp -r $(BUILD_DIR) $(DISTDIR)
tar -czf $(DIST) --exclude='\.gitkeep' $(DISTDIR)
rm -r $(DISTDIR)
$(MATHSPACE_CSS): $(CSS_SOURCES) $(NODE_MODULES_INSTALLED) $(BUILD_DIR_EXISTS)
$(LESSC) $(LESS_OPTS) $(MATHSPACE_CSS_MAIN) > $@
$(MATHSPACE_FONT_CSS): $(FONT_CSS_SOURCES) $(NODE_MODULES_INSTALLED) $(BUILD_DIR_EXISTS)
$(LESSC) $(LESS_OPTS) $(MATHSPACE_FONT_CSS_MAIN) > $@
#
# -*- Test tasks -*-
#
.PHONY: test server run-server
server:
node script/test_server.js
test: dev $(BUILD_TEST) $(BASIC_JS) $(BASIC_CSS)
@echo
@echo "** now open test/{unit,visual}.html in your browser to run the {unit,visual} tests. **"
$(BUILD_TEST): $(INTRO) $(SOURCES_FULL) $(UNIT_TESTS) $(OUTRO) $(BUILD_DIR_EXISTS)
cat $^ > $@
#
# -*- site (mathquill.github.com) tasks
#
.PHONY: site publish site-pull
SITE = mathquill.github.com
SITE_CLONE_URL = git@github.com:mathquill/mathquill.github.com
SITE_COMMITMSG = 'updating mathquill to $(VERSION)'
DOWNLOADS_PAGE = $(SITE)/downloads.html
DIST_DOWNLOAD = $(SITE)/downloads/$(DIST)
site: $(SITE) $(SITE)/mathquill $(SITE)/demo.html $(SITE)/support $(DOWNLOADS_PAGE)
publish: site-pull site
pwd
cd $(SITE) \
&& git add -- mathquill demo.html support downloads downloads.html \
&& git commit -m $(SITE_COMMITMSG) \
&& git push
$(SITE)/mathquill: $(DIST)
mkdir -p $@
tar -xzf $(DIST) \
--directory $@ \
--strip-components=2
$(DIST_DOWNLOAD): $(DIST)
mkdir -p $(dir $@)
cp $^ $@
# freaking bsd, i swear
# adapted from https://developer.apple.com/library/mac/documentation/opensource/Conceptual/ShellScripting/PortingScriptstoMacOSX/PortingScriptstoMacOSX.html#//apple_ref/doc/uid/TP40004268-TP40003517-SW21
ifeq (x, $(shell echo xy | sed -r 's/(x)y/\1/' 2>/dev/null))
# gnu
SED = sed -r
SED_I = $(SED) -i
else
# bsd
SED = sed -E
SED_I = $(SED) -i ''
endif
$(DOWNLOADS_PAGE): $(DIST_DOWNLOAD)
@echo Using $(SED)
@echo -n updating downloads page...
@$(SED_I) \
-e '/Latest version:/ s/[0-9]+[.][0-9]+[.][0-9]+/$(VERSION)/g' \
$(DOWNLOADS_PAGE)
@mkdir -p tmp
@ls $(SITE)/downloads/*.tgz \
| egrep -o '[0-9]+[.][0-9]+[.][0-9]+' \
| fgrep -v $(VERSION) \
| sort -rn -t. -k 1,1 -k 2,2 -k 3,3 \
| sed 's|.*|<li><a class="prev" href="downloads/mathquill-&.tgz">v&</a></li>|' \
> tmp/versions-list.html
@$(SED_I) \
-e '/<a class="prev"/d' \
-e '/<ul id="prev-versions">/ r tmp/versions-list.html' \
$(DOWNLOADS_PAGE)
@rm tmp/versions-list.html
@echo done.
$(SITE)/demo.html: test/demo.html
cat $^ \
| $(SED) 's:../build/:mathquill/:' \
| $(SED) 's:local test page:live demo:' \
> $@
$(SITE)/support: test/support
rm -rf $@
cp -r $^ $@
$(SITE):
git clone $(SITE_CLONE_URL) $@
site-pull: $(SITE)
cd $(SITE) && git pull