-
Notifications
You must be signed in to change notification settings - Fork 111
/
Makefile
337 lines (280 loc) · 12.7 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
PYRET_COMP0 = build/phase0/pyret.jarr
CLOSURE = java -jar deps/closure-compiler/compiler.jar
NODE = node -max-old-space-size=8192
SWEETJS = node_modules/sweet.js/bin/sjs --readable-names --module ./src/js/macros.js
JS = js
JSBASE = $(JS)/base
JSTROVE = $(JS)/trove
BASE = arr/base
TROVE = arr/trove
COMPILER = arr/compiler
PHASE0 = build/phase0
PHASEA = build/phaseA
PHASEB = build/phaseB
PHASEC = build/phaseC
RELEASE_DIR = build/release
BUNDLED_DEPS = build/bundled-node-deps.js
# HACK HACK HACK (See https://github.com/npm/npm/issues/3738)
export PATH := ./node_modules/.bin:../node_modules/.bin:../../node_modules/.bin:$(PATH)
SHELL := /bin/bash
# CUSTOMIZE THESE IF NECESSARY
PARSERS := $(patsubst src/js/base/%-grammar.bnf,src/js/%-parser.js,$(wildcard src/$(JSBASE)/*-grammar.bnf))
COPY_JS = $(patsubst src/js/base/%.js,src/js/%.js,$(wildcard src/$(JSBASE)/*.js)) \
src/js/js-numbers.js
COMPILER_FILES = $(wildcard src/arr/compiler/*.arr) $(wildcard src/arr/compiler/locators/*.arr) $(wildcard src/js/trove/*.js) $(wildcard src/arr/trove/*.arr)
TROVE_ARR_FILES = $(wildcard src/arr/trove/*.arr)
# You can download the script to work with s3 here:
#
# http://aws.amazon.com/code/Amazon-S3/1710
#
# On Debian, you need the following packages:
#
# - libterm-shellui-perl
# - liblog-log4perl-perl
# - libnet-amazon-s3-perl
# - libnet-amazon-perl
# - libnet-amazon-s3-tools-perl
# - parallel
#
# You will then need to place your AWS id and secret in ~/.aws, in the
# following format:
#
# id = <your aws id>
# secret = <your aws secret>
#
# Make sure that the s3 script is in your PATH, or modify the value
# below.
S3 = s3
PHASEA_ALL_DEPS := $(patsubst src/%,$(PHASEA)/%,$(COPY_JS))
PHASEB_ALL_DEPS := $(patsubst src/%,$(PHASEB)/%,$(COPY_JS))
PHASEC_ALL_DEPS := $(patsubst src/%,$(PHASEC)/%,$(COPY_JS))
PHASEA_DIRS := $(sort $(dir $(PHASEA_ALL_DEPS)))
PHASEB_DIRS := $(sort $(dir $(PHASEB_ALL_DEPS)))
PHASEC_DIRS := $(sort $(dir $(PHASEC_ALL_DEPS)))
# NOTE: Needs TWO blank lines here, dunno why
define \n
endef
ifneq ($(findstring .exe,$(SHELL)),)
override SHELL:=$(COMSPEC)$(ComSpec)
MKDIR = $(foreach dir,$1,if not exist "$(dir)". (md "$(dir)".)$(\n))
RMDIR = $(foreach dir,$1,if exist "$(dir)". (rd /S /Q "$(dir)".)$(\n))
RM = if exist "$1". (del $1)
else
MKDIR = mkdir -p $1
RMDIR = rm -rf $1
RM = rm -f $1
VERSION = $(shell git describe --long --tags HEAD | awk -F '[/-]' '{ print $$1 "r" $$2 }')
endif
-include config.mk
# Make sure that if a compilation step fails, we don't leave an empty but timestamp-up-to-date file
# laying (and lying) around to confuse future make
.DELETE_ON_ERROR:
# MAIN TARGET
.PHONY : phaseA
phaseA: $(PHASEA)/pyret.jarr
.PHONY : phaseA-deps
phaseA-deps: $(PYRET_COMPA) $(PHASEA_ALL_DEPS) $(COMPILER_FILES) $(patsubst src/%,$(PHASEA)/%,$(PARSERS))
$(PHASEA)/pyret.jarr: $(PYRET_COMPA) $(PHASEA_ALL_DEPS) $(COMPILER_FILES) $(patsubst src/%,$(PHASEA)/%,$(PARSERS)) $(BUNDLED_DEPS)
$(NODE) $(PYRET_COMP0) --outfile build/phaseA/pyret.jarr \
--build-runnable src/arr/compiler/pyret.arr \
--builtin-js-dir src/js/trove/ \
--builtin-arr-dir src/arr/trove/ \
--compiled-dir build/phaseA/compiled/ \
-no-check-mode $(EF) \
--require-config src/scripts/standalone-configA.json
.PHONY : phaseB
phaseB: $(PHASEB)/pyret.jarr
$(PHASEB)/pyret.jarr: $(PHASEA)/pyret.jarr $(PHASEB_ALL_DEPS) $(patsubst src/%,$(PHASEB)/%,$(PARSERS))
$(NODE) $(PHASEA)/pyret.jarr --outfile build/phaseB/pyret.jarr \
--build-runnable src/arr/compiler/pyret.arr \
--builtin-js-dir src/js/trove/ \
--builtin-arr-dir src/arr/trove/ \
--compiled-dir build/phaseB/compiled/ \
-no-check-mode $(EF) \
--require-config src/scripts/standalone-configB.json
.PHONY : phaseC
phaseC: $(PHASEC)/pyret.jarr
$(PHASEC)/pyret.jarr: $(PHASEB)/pyret.jarr $(PHASEC_ALL_DEPS) $(patsubst src/%,$(PHASEC)/%,$(PARSERS))
$(NODE) $(PHASEB)/pyret.jarr --outfile build/phaseC/pyret.jarr \
--build-runnable src/arr/compiler/pyret.arr \
--builtin-js-dir src/js/trove/ \
--builtin-arr-dir src/arr/trove/ \
--compiled-dir build/phaseC/compiled/ \
-no-check-mode $(EF) \
--require-config src/scripts/standalone-configC.json
.PHONY : show-comp
show-comp: build/show-compilation.jarr
showpath:
@echo my new PATH = $(PATH)
@echo `which browserify`
$(BUNDLED_DEPS): src/js/trove/require-node-dependencies.js
npx browserify src/js/trove/require-node-dependencies.js -o $(BUNDLED_DEPS)
build/show-compilation.jarr: $(PHASEA)/pyret.jarr src/scripts/show-compilation.arr
$(NODE) $(PHASEA)/pyret.jarr --outfile build/show-compilation.jarr \
--build-runnable src/scripts/show-compilation.arr \
--builtin-js-dir src/js/trove/ \
--builtin-arr-dir src/arr/trove/ \
--compiled-dir build/show-comp/compiled/ \
-no-check-mode \
--require-config src/scripts/standalone-configA.json
ifneq ($(EF),)
EXTRA_FLAGS=$(EF)
else
EXTRA_FLAGS = -no-check-mode
endif
%.jarr: $(PHASEA)/pyret.jarr %.arr
$(NODE) $(PHASEA)/pyret.jarr --outfile $*.jarr \
--build-runnable $*.arr \
--builtin-js-dir src/js/trove/ \
--builtin-arr-dir src/arr/trove/ \
--compiled-dir compiled/ \
$(EXTRA_FLAGS) \
--require-config src/scripts/standalone-configA.json
%.html: $(PHASEA)/pyret.jarr %.arr
$(NODE) $(PHASEA)/pyret.jarr --outfile $*.jarr \
--build-runnable $*.arr \
--builtin-js-dir src/js/trove/ \
--builtin-arr-dir src/arr/trove/ \
--compiled-dir compiled/ \
$(EXTRA_FLAGS) \
--require-config src/scripts/standalone-configA.json \
-bundle-dependencies \
--html-file $*.html
$(PHASEA_ALL_DEPS): | $(PHASEA)
$(PHASEB_ALL_DEPS): | $(PHASEB) phaseA
$(PHASEC_ALL_DEPS): | $(PHASEC) phaseB
$(PHASEA):
@$(call MKDIR,$(PHASEA_DIRS))
$(PHASEB):
@$(call MKDIR,$(PHASEB_DIRS))
$(PHASEC):
@$(call MKDIR,$(PHASEC_DIRS))
$(PHASEA)/$(JS)/%-parser.js: src/$(JSBASE)/%-grammar.bnf src/$(JSBASE)/%-tokenizer.js $(wildcard lib/jglr/*.js)
$(NODE) lib/jglr/parser-generator.js src/$(JSBASE)/$*-grammar.bnf $(PHASEA)/$(JS)/$*-grammar.js "../../../lib/jglr" "jglr/jglr" "pyret-base/js/$*-parser"
$(NODE) $(PHASEA)/$(JS)/$*-grammar.js $(PHASEA)/$(JS)/$*-parser.js
$(PHASEB)/$(JS)/%-parser.js: src/$(JSBASE)/%-grammar.bnf src/$(JSBASE)/%-tokenizer.js $(wildcard lib/jglr/*.js)
$(NODE) lib/jglr/parser-generator.js src/$(JSBASE)/$*-grammar.bnf $(PHASEB)/$(JS)/$*-grammar.js "../../../lib/jglr" "jglr/jglr" "pyret-base/js/$*-parser"
$(NODE) $(PHASEB)/$(JS)/$*-grammar.js $(PHASEB)/$(JS)/$*-parser.js
$(PHASEC)/$(JS)/%-parser.js: src/$(JSBASE)/%-grammar.bnf src/$(JSBASE)/%-tokenizer.js $(wildcard lib/jglr/*.js)
$(NODE) lib/jglr/parser-generator.js src/$(JSBASE)/$*-grammar.bnf $(PHASEC)/$(JS)/$*-grammar.js "../../../lib/jglr" "jglr/jglr" "pyret-base/js/$*-parser"
$(NODE) $(PHASEC)/$(JS)/$*-grammar.js $(PHASEC)/$(JS)/$*-parser.js
$(PHASEA)/$(JS)/%.js : src/$(JSBASE)/%.js
cp $< $@
$(PHASEB)/$(JS)/%.js : src/$(JSBASE)/%.js
cp $< $@
$(PHASEC)/$(JS)/%.js : src/$(JSBASE)/%.js
cp $< $@
.PHONY : install
install:
@$(call MKDIR,node_modules)
npm install
PYRET_TEST_PHASE=$(P)
ifeq ($(PYRET_TEST_PHASE),B)
PYRET_TEST_PHASE=$(PHASEB)
PYRET_TEST_PREREQ=$(PHASEB)/pyret.jarr
PYRET_TEST_CONFIG=src/scripts/standalone-configB.json
else
ifeq ($(PYRET_TEST_PHASE),C)
PYRET_TEST_PHASE=$(PHASEC)
PYRET_TEST_PREREQ=$(PHASEC)/pyret.jarr
PYRET_TEST_CONFIG=src/scripts/standalone-configC.json
else
PYRET_TEST_PHASE=$(PHASEA)
PYRET_TEST_PREREQ=$(PHASEA)/pyret.jarr
PYRET_TEST_CONFIG=src/scripts/standalone-configA.json
endif
endif
TEST_BUILD=$(NODE) $(PYRET_TEST_PHASE)/pyret.jarr \
--builtin-js-dir src/js/trove/ \
--builtin-arr-dir src/arr/trove/ \
--require-config $(PYRET_TEST_CONFIG) \
--compiled-dir tests/compiled/
.PHONY : test-all
test-all: test
.PHONY : test
test: pyret-test type-check-test pyret-io-test
.PHONY : parse-test
parse-test: tests/parse/parse.js build/phaseA/js/pyret-tokenizer.js build/phaseA/js/pyret-parser.js
cd tests/parse/ && $(NODE) parse.js
TEST_FILES := $(wildcard tests/pyret/tests/*.arr)
TYPE_TEST_FILES := $(wildcard tests/type-check/bad/*.arr) $(wildcard tests/type-check/good/*.arr) $(wildcard tests/type-check/should/*.arr) $(wildcard tests/type-check/should-not/*.arr)
REG_TEST_FILES := $(wildcard tests/pyret/regression/*.arr)
MAIN_TEST_FILES := tests/pyret/main2.arr tests/type-check/main.arr tests/pyret/regression.arr tests/lib-test/lib-test-main.arr tests/all.arr
tests/pyret/all.jarr: phaseA $(TEST_FILES) $(TYPE_TEST_FILES) $(REG_TEST_FILES) $(MAIN_TEST_FILES)
$(TEST_BUILD) \
--build-runnable tests/all.arr \
--outfile tests/pyret/all.jarr \
-check-all
.PHONY : all-pyret-test
all-pyret-test: tests/pyret/all.jarr parse-test pyret-io-test
$(NODE) tests/pyret/all.jarr
tests/pyret/main2.jarr: phaseA tests/pyret/main2.arr $(TEST_FILES)
$(TEST_BUILD) \
--outfile tests/pyret/main2.jarr \
--build-runnable tests/pyret/main2.arr \
-check-all # NOTE(joe): check-all doesn't yet do anything
.PHONY : pyret-test
pyret-test: phaseA tests/pyret/main2.jarr
$(NODE) tests/pyret/main2.jarr
.PHONY : pyret-io-test
pyret-io-test: phaseA
npx jest --verbose "tests/io-tests/io.test.js"
.PHONY : regression-test
regression-test: tests/pyret/regression.jarr
$(NODE) tests/pyret/regression.jarr
tests/pyret/regression.jarr: $(PYRET_TEST_PREREQ) $(REG_TEST_FILES) tests/pyret/regression.arr
$(TEST_BUILD) \
--build-runnable tests/pyret/regression.arr --outfile tests/pyret/regression.jarr
.PHONY : type-check-test
type-check-test: phaseA tests/type-check/main.jarr
$(NODE) tests/type-check/main.jarr
tests/type-check/main.jarr: phaseA tests/type-check/main.arr $(TYPE_TEST_FILES)
$(TEST_BUILD) \
--build-runnable tests/type-check/main.arr --outfile tests/type-check/main.jarr
.PHONY : clean
clean:
$(call RMDIR,$(PHASEA))
$(call RMDIR,$(PHASEB))
$(call RMDIR,$(PHASEC))
$(call RMDIR,build/show-comp/compiled)
$(call RMDIR,$(RELEASE_DIR))
$(call RM,$(BUNDLED_DEPS))
.PHONY : test-clean
test-clean:
$(call RMDIR, tests/compiled)
# Written this way because cmd.exe complains about && in command lines
new-bootstrap: no-diff-standalone $(PHASE0BUILD)
cp $(PHASEC)/pyret.jarr $(PYRET_COMP0)
cp -r $(PHASEC)/js $(PHASE0)/
no-diff-standalone: phaseB phaseC
diff $(PHASEB)/pyret.jarr $(PHASEC)/pyret.jarr
$(RELEASE_DIR)/phase1:
$(call MKDIR,$(RELEASE_DIR)/phase1)
ifdef VERSION
release-gzip: $(PYRET_COMP) phase1 standalone1 $(RELEASE_DIR)/phase1
gzip -c $(PHASE1)/pyret.js > $(RELEASE_DIR)/pyret.js
(cd $(PHASE1) && find * -type d -print0) | parallel --gnu -0 mkdir -p '$(RELEASE_DIR)/phase1/{}'
(cd $(PHASE1) && find * -type f -print0) | parallel --gnu -0 "gzip -c '$(PHASE1)/{}' > '$(RELEASE_DIR)/phase1/{}'"
horizon-gzip: standalone1 $(RELEASE_DIR)/phase1
sed "s/define('pyret-start/define('pyret/" $(PHASE1)/pyret.js > $(RELEASE_DIR)/pyret-full.js
gzip -c $(RELEASE_DIR)/pyret-full.js > $(RELEASE_DIR)/pyret.js
(cd $(PHASE1) && find * -type d -print0) | parallel --gnu -0 mkdir -p '$(RELEASE_DIR)/phase1/{}'
(cd $(PHASE1) && find * -type f -print0) | parallel --gnu -0 "gzip -c '$(PHASE1)/{}' > '$(RELEASE_DIR)/phase1/{}'"
# If you need information on using the s3 script, run `s3 --man'
horizon-release: horizon-gzip
cd $(RELEASE_DIR) && \
find * -type f -print0 | parallel --gnu -0 $(S3) add --header 'Content-Type:text/javascript' --header 'Content-Encoding:gzip' --acl 'public-read' ':pyret-horizon/current/{}' '{}'
release: release-gzip
cd $(RELEASE_DIR) && \
find * -type f -print0 | parallel --gnu -0 $(S3) add --header 'Content-Type:text/javascript' --header 'Content-Encoding:gzip' --acl 'public-read' ':pyret-releases/$(VERSION)/{}' '{}'
test-release: release-gzip
cd $(RELEASE_DIR) && \
find * -type f -print0 | parallel --gnu -0 $(S3) add --header 'Content-Type:text/javascript' --header 'Content-Encoding:gzip' --acl 'public-read' ':pyret-releases/$(VERSION)-test/{}' '{}'
else
release-gzip:
$(error Cannot release from this platform)
release:
$(error Cannot release from this platform)
test-release: release-gzip
$(error Cannot release from this platform)
endif