Merge pull request #95 from ivern/kotlin
[jackhill/mal.git] / Makefile
1 #
2 # Command line settings
3 #
4
5 MAL_IMPL = js
6
7 PYTHON = python
8
9 # Extra options to pass to runtest.py
10 TEST_OPTS =
11
12 # Extra implementation specific options to pass to runtest.py
13 mal_TEST_OPTS = --start-timeout 60 --test-timeout 120
14
15 #
16 # Settings
17 #
18
19 IMPLS = awk bash c clojure coffee cpp crystal cs erlang elixir es6 factor forth fsharp go groovy \
20 guile haskell java julia js kotlin lua make mal ocaml matlab miniMAL nim \
21 perl php ps python r racket rpython ruby rust scala swift vb vimscript
22
23 step0 = step0_repl
24 step1 = step1_read_print
25 step2 = step2_eval
26 step3 = step3_env
27 step4 = step4_if_fn_do
28 step5 = step5_tco
29 step6 = step6_file
30 step7 = step7_quote
31 step8 = step8_macros
32 step9 = step9_try
33 stepA = stepA_mal
34
35 EXCLUDE_TESTS += test^awk^step5 # completes at 10,000
36 EXCLUDE_TESTS += test^bash^step5 # no stack exhaustion or completion
37 EXCLUDE_TESTS += test^c^step5 # segfault
38 EXCLUDE_TESTS += test^cpp^step5 # completes at 10,000
39 EXCLUDE_TESTS += test^cs^step5 # fatal stack overflow fault
40 EXCLUDE_TESTS += test^erlang^step5 # erlang is TCO, test passes
41 EXCLUDE_TESTS += test^elixir^step5 # elixir is TCO, test passes
42 EXCLUDE_TESTS += test^fsharp^step5 # completes at 10,000, fatal stack overflow at 100,000
43 EXCLUDE_TESTS += test^haskell^step5 # test completes
44 EXCLUDE_TESTS += test^make^step5 # no TCO capability/step
45 EXCLUDE_TESTS += test^mal^step5 # no TCO capability/step
46 EXCLUDE_TESTS += test^miniMAL^step5 # strange error with runtest.py
47 EXCLUDE_TESTS += test^nim^step5 # test completes, even at 100,000
48 EXCLUDE_TESTS += test^go^step5 # test completes, even at 100,000
49 EXCLUDE_TESTS += test^php^step5 # test completes, even at 100,000
50 EXCLUDE_TESTS += test^racket^step5 # test completes
51 EXCLUDE_TESTS += test^ruby^step5 # test completes, even at 100,000
52 EXCLUDE_TESTS += test^rust^step5 # no catching stack overflows
53 EXCLUDE_TESTS += test^ocaml^step5 # test completes, even at 1,000,000
54 EXCLUDE_TESTS += test^vb^step5 # completes at 10,000
55 EXCLUDE_TESTS += test^crystal^step5 # test completes, even at 1,000,000
56
57 EXCLUDE_PERFS = perf^mal # TODO: fix this
58
59 #
60 # Utility functions
61 #
62
63 STEP_TEST_FILES = $(strip $(wildcard $(1)/tests/$($(2)).mal) $(wildcard tests/$($(2)).mal))
64
65 awk_STEP_TO_PROG = awk/$($(1)).awk
66 bash_STEP_TO_PROG = bash/$($(1)).sh
67 c_STEP_TO_PROG = c/$($(1))
68 clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
69 coffee_STEP_TO_PROG = coffee/$($(1)).coffee
70 cpp_STEP_TO_PROG = cpp/$($(1))
71 crystal_STEP_TO_PROG = crystal/$($(1))
72 cs_STEP_TO_PROG = cs/$($(1)).exe
73 elixir_STEP_TO_PROG = elixir/lib/mix/tasks/$($(1)).ex
74 erlang_STEP_TO_PROG = erlang/$($(1))
75 es6_STEP_TO_PROG = es6/build/$($(1)).js
76 factor_STEP_TO_PROG = factor/src/$($(1))/$($(1)).factor
77 forth_STEP_TO_PROG = forth/$($(1)).fs
78 fsharp_STEP_TO_PROG = fsharp/$($(1)).exe
79 go_STEP_TO_PROG = go/$($(1))
80 groovy_STEP_TO_PROG = groovy/$($(1)).groovy
81 java_STEP_TO_PROG = java/src/main/java/mal/$($(1)).java
82 haskell_STEP_TO_PROG = haskell/$($(1))
83 julia_STEP_TO_PROG = julia/$($(1)).jl
84 js_STEP_TO_PROG = js/$($(1)).js
85 kotlin_STEP_TO_PROG = kotlin/$($(1)).jar
86 lua_STEP_TO_PROG = lua/$($(1)).lua
87 make_STEP_TO_PROG = make/$($(1)).mk
88 mal_STEP_TO_PROG = mal/$($(1)).mal
89 ocaml_STEP_TO_PROG = ocaml/$($(1))
90 matlab_STEP_TO_PROG = matlab/$($(1)).m
91 miniMAL_STEP_TO_PROG = miniMAL/$($(1)).json
92 nim_STEP_TO_PROG = nim/$($(1))
93 perl_STEP_TO_PROG = perl/$($(1)).pl
94 php_STEP_TO_PROG = php/$($(1)).php
95 ps_STEP_TO_PROG = ps/$($(1)).ps
96 python_STEP_TO_PROG = python/$($(1)).py
97 r_STEP_TO_PROG = r/$($(1)).r
98 racket_STEP_TO_PROG = racket/$($(1)).rkt
99 rpython_STEP_TO_PROG = rpython/$($(1))
100 ruby_STEP_TO_PROG = ruby/$($(1)).rb
101 rust_STEP_TO_PROG = rust/target/release/$($(1))
102 scala_STEP_TO_PROG = scala/$($(1)).scala
103 swift_STEP_TO_PROG = swift/$($(1))
104 vb_STEP_TO_PROG = vb/$($(1)).exe
105 vimscript_STEP_TO_PROG = vimscript/$($(1)).vim
106 guile_STEP_TO_PROG = guile/$($(1)).scm
107
108 # Needed some argument munging
109 COMMA = ,
110 noop =
111 SPACE = $(noop) $(noop)
112 export FACTOR_ROOTS := src
113
114 awk_RUNSTEP = awk -O -f ../$(2) $(3)
115 bash_RUNSTEP = bash ../$(2) $(3)
116 c_RUNSTEP = ../$(2) $(3)
117 clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3)
118 coffee_RUNSTEP = coffee ../$(2) $(3)
119 cpp_RUNSTEP = ../$(2) $(3)
120 crystal_RUNSTEP = ../$(2) $(3)
121 cs_RUNSTEP = mono ../$(2) --raw $(3)
122 elixir_RUNSTEP = mix $(notdir $(basename $(2))) $(3)
123 erlang_RUNSTEP = ../$(2) $(3)
124 es6_RUNSTEP = node ../$(2) $(3)
125 factor_RUNSTEP = factor ../$(2) $(3)
126 forth_RUNSTEP = gforth ../$(2) $(3)
127 fsharp_RUNSTEP = mono ../$(2) --raw $(3)
128 go_RUNSTEP = ../$(2) $(3)
129 groovy_RUNSTEP = groovy ../$(2) $(3)
130 haskell_RUNSTEP = ../$(2) $(3)
131 java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" $(if $(3), -Dexec.args="$(3)",)
132 julia_RUNSTEP = ../$(2) $(3)
133 js_RUNSTEP = node ../$(2) $(3)
134 kotlin_RUNSTEP = java -jar ../$(2) $(3)
135 lua_RUNSTEP = ../$(2) $(3)
136 make_RUNSTEP = make -f ../$(2) $(3)
137 mal_RUNSTEP = $(call $(MAL_IMPL)_RUNSTEP,stepA,$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),../$(2),") #"
138 ocaml_RUNSTEP = ../$(2) $(3)
139 matlab_args = $(subst $(SPACE),$(COMMA),$(foreach x,$(strip $(1)),'$(x)'))
140 matlab_RUNSTEP = matlab -nodisplay -nosplash -nodesktop -nojvm -r "$($(1))($(call matlab_args,$(3)));quit;"
141 miniMAL_RUNSTEP = miniMAL ../$(2) $(3)
142 nim_RUNSTEP = ../$(2) $(3)
143 perl_RUNSTEP = perl ../$(2) $(3)
144 php_RUNSTEP = php ../$(2) $(3)
145 ps_RUNSTEP = gs -q -I./ -dNODISPLAY -- ../$(2) $(3)
146 python_RUNSTEP = $(PYTHON) ../$(2) $(3)
147 r_RUNSTEP = Rscript ../$(2) $(3)
148 racket_RUNSTEP = ../$(2) $(3)
149 rpython_RUNSTEP = ../$(2) $(3)
150 ruby_RUNSTEP = ruby ../$(2) $(3)
151 rust_RUNSTEP = ../$(2) $(3)
152 scala_RUNSTEP = sbt 'run-main $($(1))$(if $(3), $(3),)'
153 swift_RUNSTEP = ../$(2) $(3)
154 vb_RUNSTEP = mono ../$(2) --raw $(3)
155 vimscript_RUNSTEP = ./run_vimscript.sh ../$(2) $(3)
156 # needs TERM=dumb to work with readline
157 guile_RUNSTEP = guile --no-auto-compile -L ../guile ../$(2) $(3)
158
159
160 vimscript_TEST_OPTS = --test-timeout 30
161 ifeq ($(MAL_IMPL),vimscript)
162 mal_TEST_OPTS = --start-timeout 60 --test-timeout 180
163 endif
164
165 # Derived lists
166 STEPS = $(sort $(filter step%,$(.VARIABLES)))
167 DO_IMPLS = $(filter-out $(SKIP_IMPLS),$(IMPLS))
168 IMPL_TESTS = $(foreach impl,$(DO_IMPLS),test^$(impl))
169 STEP_TESTS = $(foreach step,$(STEPS),test^$(step))
170 ALL_TESTS = $(filter-out $(EXCLUDE_TESTS),\
171 $(strip $(sort \
172 $(foreach impl,$(DO_IMPLS),\
173 $(foreach step,$(STEPS),test^$(impl)^$(step))))))
174
175 IMPL_STATS = $(foreach impl,$(DO_IMPLS),stats^$(impl))
176 IMPL_STATS_LISP = $(foreach impl,$(DO_IMPLS),stats-lisp^$(impl))
177
178 DOCKER_BUILD = $(foreach impl,$(DO_IMPLS),docker-build^$(impl))
179
180 IMPL_PERF = $(filter-out $(EXCLUDE_PERFS),$(foreach impl,$(DO_IMPLS),perf^$(impl)))
181
182 #
183 # Build rules
184 #
185
186 # Build a program in an implementation directory
187 $(foreach i,$(DO_IMPLS),$(foreach s,$(STEPS),$(call $(i)_STEP_TO_PROG,$(s)))):
188 $(MAKE) -C $(dir $(@)) $(notdir $(@))
189
190 # Allow test, test^STEP, test^IMPL, and test^IMPL^STEP
191 .SECONDEXPANSION:
192 $(IMPL_TESTS): $$(filter $$@^%,$$(ALL_TESTS))
193
194 .SECONDEXPANSION:
195 $(STEP_TESTS): $$(foreach step,$$(subst test^,,$$@),$$(filter %^$$(step),$$(ALL_TESTS)))
196
197 .SECONDEXPANSION:
198 $(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
199 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
200 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
201 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
202 $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
203 echo '----------------------------------------------'; \
204 echo 'Testing $@, step file: $+, test file: $(test)'; \
205 echo 'Running: ../runtest.py $(TEST_OPTS) $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+))'; \
206 ../runtest.py $(TEST_OPTS) $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+));)))
207
208 test: $(ALL_TESTS)
209 tests: $(ALL_TESTS)
210
211
212 # Stats rules
213
214 stats: $(IMPL_STATS)
215 stats-lisp: $(IMPL_STATS_LISP)
216
217 .SECONDEXPANSION:
218 $(IMPL_STATS):
219 @echo "----------------------------------------------"; \
220 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
221 echo "Stats for $(impl):"; \
222 $(MAKE) --no-print-directory -C $(impl) stats)
223
224 .SECONDEXPANSION:
225 $(IMPL_STATS_LISP):
226 @echo "----------------------------------------------"; \
227 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
228 echo "Stats (lisp only) for $(impl):"; \
229 $(MAKE) --no-print-directory -C $(impl) stats-lisp)
230
231 # Docker build rules
232
233 docker-build: $(DOCKER_BUILD)
234
235 .SECONDEXPANSION:
236 $(DOCKER_BUILD):
237 echo "----------------------------------------------"; \
238 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
239 echo "Running: docker build -t kanaka/mal-test-$(impl) .:"; \
240 cd $(impl) && docker build -t kanaka/mal-test-$(impl) .)
241
242 # Performance test rules
243
244 perf: $(IMPL_PERF)
245
246 .SECONDEXPANSION:
247 $(IMPL_PERF):
248 @echo "----------------------------------------------"; \
249 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
250 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
251 echo "Performance test for $(impl):"; \
252 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal)'; \
253 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal); \
254 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal)'; \
255 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal); \
256 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal)'; \
257 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal))