README: add RPython and bump count to 36.
[jackhill/mal.git] / Makefile
CommitLineData
31690700
JM
1#
2# Command line settings
3#
4
5MAL_IMPL = js
6
a05f7822
JM
7PYTHON = python
8
31690700
JM
9#
10# Settings
11#
12
58b84dd5 13IMPLS = bash c clojure coffee cpp crystal cs erlang factor forth go groovy \
a9cd6543 14 haskell java julia js lua make mal ocaml matlab miniMAL nim \
80320efc 15 perl php ps python r racket rpython ruby rust scala swift vb guile
31690700
JM
16
17step0 = step0_repl
18step1 = step1_read_print
19step2 = step2_eval
20step3 = step3_env
21step4 = step4_if_fn_do
22step5 = step5_tco
23step6 = step6_file
24step7 = step7_quote
25step8 = step8_macros
01c97316 26step9 = step9_try
90f618cb 27stepA = stepA_mal
31690700 28
cc021efe
JM
29EXCLUDE_TESTS += test^bash^step5 # no stack exhaustion or completion
30EXCLUDE_TESTS += test^c^step5 # segfault
0fbd1b81 31EXCLUDE_TESTS += test^cpp^step5 # completes at 10,000
cc021efe 32EXCLUDE_TESTS += test^cs^step5 # fatal stack overflow fault
e07b9830 33EXCLUDE_TESTS += test^erlang^step5 # erlang is TCO, test passes
7907cd90 34EXCLUDE_TESTS += test^haskell^step5 # test completes
cc021efe
JM
35EXCLUDE_TESTS += test^make^step5 # no TCO capability/step
36EXCLUDE_TESTS += test^mal^step5 # no TCO capability/step
dbac60df
JM
37EXCLUDE_TESTS += test^miniMAL^step5 # strange error with runtest.py
38EXCLUDE_TESTS += test^nim^step5 # test completes, even at 100,000
17e1c5f9 39EXCLUDE_TESTS += test^go^step5 # test completes, even at 100,000
cc021efe 40EXCLUDE_TESTS += test^php^step5 # test completes, even at 100,000
7907cd90 41EXCLUDE_TESTS += test^racket^step5 # test completes
cc021efe 42EXCLUDE_TESTS += test^ruby^step5 # test completes, even at 100,000
a77e2b31 43EXCLUDE_TESTS += test^rust^step5 # no catching stack overflows
44d4e31f 44EXCLUDE_TESTS += test^ocaml^step5 # test completes, even at 1,000,000
dbac60df 45EXCLUDE_TESTS += test^vb^step5 # completes at 10,000
725ee0bd 46EXCLUDE_TESTS += test^crystal^step5 # test completes, even at 1,000,000
cc021efe 47
db4c329a 48EXCLUDE_PERFS = perf^mal # TODO: fix this
31690700
JM
49
50#
51# Utility functions
52#
53
54STEP_TEST_FILES = $(strip $(wildcard $(1)/tests/$($(2)).mal) $(wildcard tests/$($(2)).mal))
55
db4c329a
JM
56bash_STEP_TO_PROG = bash/$($(1)).sh
57c_STEP_TO_PROG = c/$($(1))
31690700 58clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
891c3f3b 59coffee_STEP_TO_PROG = coffee/$($(1)).coffee
9ddaa0b9 60cpp_STEP_TO_PROG = cpp/$($(1))
86fe6314 61crystal_STEP_TO_PROG = crystal/$($(1))
db4c329a 62cs_STEP_TO_PROG = cs/$($(1)).exe
2cc3804b 63erlang_STEP_TO_PROG = erlang/$($(1))
389c9b8a 64factor_STEP_TO_PROG = factor/src/$($(1))/$($(1)).factor
59038a10 65forth_STEP_TO_PROG = forth/$($(1)).fs
69b4abd6 66go_STEP_TO_PROG = go/$($(1))
a9cd6543 67groovy_STEP_TO_PROG = groovy/$($(1)).groovy
db4c329a 68java_STEP_TO_PROG = java/src/main/java/mal/$($(1)).java
b76aa73b 69haskell_STEP_TO_PROG = haskell/$($(1))
a23e0cdb 70julia_STEP_TO_PROG = julia/$($(1)).jl
db4c329a 71js_STEP_TO_PROG = js/$($(1)).js
9d42904e 72lua_STEP_TO_PROG = lua/$($(1)).lua
db4c329a
JM
73make_STEP_TO_PROG = make/$($(1)).mk
74mal_STEP_TO_PROG = mal/$($(1)).mal
59d10e1b 75ocaml_STEP_TO_PROG = ocaml/$($(1))
9a54ea18 76matlab_STEP_TO_PROG = matlab/$($(1)).m
c1fe72ae 77miniMAL_STEP_TO_PROG = miniMAL/$($(1)).json
dbac60df 78nim_STEP_TO_PROG = nim/$($(1))
b5dedee0 79perl_STEP_TO_PROG = perl/$($(1)).pl
db4c329a
JM
80php_STEP_TO_PROG = php/$($(1)).php
81ps_STEP_TO_PROG = ps/$($(1)).ps
82python_STEP_TO_PROG = python/$($(1)).py
4d1456b9 83r_STEP_TO_PROG = r/$($(1)).r
f5223195 84racket_STEP_TO_PROG = racket/$($(1)).rkt
80320efc 85rpython_STEP_TO_PROG = rpython/$($(1))
db4c329a 86ruby_STEP_TO_PROG = ruby/$($(1)).rb
434516e0 87rust_STEP_TO_PROG = rust/target/release/$($(1))
821930db 88scala_STEP_TO_PROG = scala/$($(1)).scala
2539e6af 89swift_STEP_TO_PROG = swift/$($(1))
ee7cd585 90vb_STEP_TO_PROG = vb/$($(1)).exe
5eb1f5cb 91guile_STEP_TO_PROG = guile/$($(1)).scm
db4c329a 92
c4033aab
JM
93# Needed some argument munging
94COMMA = ,
95noop =
96SPACE = $(noop) $(noop)
389c9b8a 97export FACTOR_ROOTS := src
db4c329a
JM
98
99bash_RUNSTEP = bash ../$(2) $(3)
100c_RUNSTEP = ../$(2) $(3)
101clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3)
891c3f3b 102coffee_RUNSTEP = coffee ../$(2) $(3)
9ddaa0b9 103cpp_RUNSTEP = ../$(2) $(3)
86fe6314 104crystal_RUNSTEP = ../$(2) $(3)
db4c329a 105cs_RUNSTEP = mono ../$(2) --raw $(3)
2cc3804b 106erlang_RUNSTEP = ../$(2) $(3)
389c9b8a 107factor_RUNSTEP = factor ../$(2) $(3)
59038a10 108forth_RUNSTEP = gforth ../$(2) $(3)
69b4abd6 109go_RUNSTEP = ../$(2) $(3)
a9cd6543 110groovy_RUNSTEP = groovy ../$(2) $(3)
b76aa73b 111haskell_RUNSTEP = ../$(2) $(3)
798206ac 112java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" $(if $(3), -Dexec.args="$(3)",)
a23e0cdb 113julia_RUNSTEP = ../$(2) $(3)
db4c329a 114js_RUNSTEP = node ../$(2) $(3)
798206ac 115lua_RUNSTEP = ../$(2) $(3)
db4c329a
JM
116make_RUNSTEP = make -f ../$(2) $(3)
117mal_RUNSTEP = $(call $(MAL_IMPL)_RUNSTEP,$(1),$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),../$(2),") #"
59d10e1b 118ocaml_RUNSTEP = ../$(2) $(3)
7f567f36
JM
119matlab_args = $(subst $(SPACE),$(COMMA),$(foreach x,$(strip $(1)),'$(x)'))
120matlab_RUNSTEP = matlab -nodisplay -nosplash -nodesktop -nojvm -r "$($(1))($(call matlab_args,$(3)));quit;"
c1fe72ae 121miniMAL_RUNSTEP = miniMAL ../$(2) $(3)
dbac60df 122nim_RUNSTEP = ../$(2) $(3)
82acd3de 123perl_RUNSTEP = perl ../$(2) $(3)
db4c329a 124php_RUNSTEP = php ../$(2) $(3)
01c97316 125ps_RUNSTEP = $(4)gs -q -I./ -dNODISPLAY -- ../$(2) $(3)$(4)
db4c329a 126python_RUNSTEP = $(PYTHON) ../$(2) $(3)
4d1456b9 127r_RUNSTEP = Rscript ../$(2) $(3)
f5223195 128racket_RUNSTEP = ../$(2) $(3)
80320efc 129rpython_RUNSTEP = ../$(2) $(3)
db4c329a 130ruby_RUNSTEP = ruby ../$(2) $(3)
abdd56eb 131rust_RUNSTEP = ../$(2) $(3)
821930db 132scala_RUNSTEP = sbt 'run-main $($(1))$(if $(3), $(3),)'
2539e6af 133swift_RUNSTEP = ../$(2) $(3)
ee7cd585 134vb_RUNSTEP = mono ../$(2) --raw $(3)
5eb1f5cb 135# needs TERM=dumb to work with readline
44af092c 136guile_RUNSTEP = guile -L ../guile ../$(2) $(3)
db4c329a
JM
137
138# Extra options to pass to runtest.py
7907cd90 139mal_TEST_OPTS = --start-timeout 60 --test-timeout 120
31690700
JM
140
141
142# Derived lists
143STEPS = $(sort $(filter step%,$(.VARIABLES)))
8569b2af
JM
144DO_IMPLS = $(filter-out $(SKIP_IMPLS),$(IMPLS))
145IMPL_TESTS = $(foreach impl,$(DO_IMPLS),test^$(impl))
31690700
JM
146STEP_TESTS = $(foreach step,$(STEPS),test^$(step))
147ALL_TESTS = $(filter-out $(EXCLUDE_TESTS),\
148 $(strip $(sort \
8569b2af 149 $(foreach impl,$(DO_IMPLS),\
31690700
JM
150 $(foreach step,$(STEPS),test^$(impl)^$(step))))))
151
8569b2af
JM
152IMPL_STATS = $(foreach impl,$(DO_IMPLS),stats^$(impl))
153IMPL_STATS_LISP = $(foreach impl,$(DO_IMPLS),stats-lisp^$(impl))
31690700 154
8569b2af 155IMPL_PERF = $(filter-out $(EXCLUDE_PERFS),$(foreach impl,$(DO_IMPLS),perf^$(impl)))
db4c329a 156
31690700
JM
157#
158# Build rules
159#
160
161# Build a program in 'c' directory
162c/%:
163 $(MAKE) -C $(dir $(@)) $(notdir $(@))
164
9ddaa0b9
ST
165# Build a program in 'cpp' directory
166cpp/%:
167 $(MAKE) -C $(dir $(@)) $(notdir $(@))
168
31690700
JM
169# Allow test, test^STEP, test^IMPL, and test^IMPL^STEP
170.SECONDEXPANSION:
171$(IMPL_TESTS): $$(filter $$@^%,$$(ALL_TESTS))
172
173.SECONDEXPANSION:
174$(STEP_TESTS): $$(foreach step,$$(subst test^,,$$@),$$(filter %^$$(step),$$(ALL_TESTS)))
175
176.SECONDEXPANSION:
177$(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
178 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
179 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
180 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
181 $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
182 echo '----------------------------------------------'; \
183 echo 'Testing $@, step file: $+, test file: $(test)'; \
db4c329a 184 echo 'Running: ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+))'; \
dbac60df 185 ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+));)))
31690700
JM
186
187test: $(ALL_TESTS)
188tests: $(ALL_TESTS)
189
190
191# Stats rules
192
db4c329a
JM
193stats: $(IMPL_STATS)
194stats-lisp: $(IMPL_STATS_LISP)
195
31690700
JM
196.SECONDEXPANSION:
197$(IMPL_STATS):
198 @echo "----------------------------------------------"; \
199 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
200 echo "Stats for $(impl):"; \
201 $(MAKE) --no-print-directory -C $(impl) stats)
202
712af9ef
JM
203.SECONDEXPANSION:
204$(IMPL_STATS_LISP):
205 @echo "----------------------------------------------"; \
206 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
207 echo "Stats (lisp only) for $(impl):"; \
208 $(MAKE) --no-print-directory -C $(impl) stats-lisp)
209
db4c329a
JM
210
211# Performance test rules
212
213perf: $(IMPL_PERF)
214
215.SECONDEXPANSION:
216$(IMPL_PERF):
217 @echo "----------------------------------------------"; \
218 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
219 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
220 echo "Performance test for $(impl):"; \
221 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal)'; \
222 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal); \
223 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal)'; \
699f0ad2
JM
224 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal); \
225 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal)'; \
226 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal))