Correct typo
[jackhill/mal.git] / Makefile
1 #
2 # Command line settings
3 #
4
5 MAL_IMPL = js
6
7 PYTHON = python
8
9 #
10 # Settings
11 #
12
13 IMPLS = bash c clojure coffee cs forth go haskell java js lua make mal \
14 ocaml matlab miniMAL perl php ps python r racket ruby rust \
15 scala vb nim
16
17 step0 = step0_repl
18 step1 = step1_read_print
19 step2 = step2_eval
20 step3 = step3_env
21 step4 = step4_if_fn_do
22 step5 = step5_tco
23 step6 = step6_file
24 step7 = step7_quote
25 step8 = step8_macros
26 step9 = step9_try
27 stepA = stepA_mal
28
29 EXCLUDE_TESTS += test^bash^step5 # no stack exhaustion or completion
30 EXCLUDE_TESTS += test^c^step5 # segfault
31 EXCLUDE_TESTS += test^cs^step5 # fatal stack overflow fault
32 EXCLUDE_TESTS += test^haskell^step5 # test completes
33 EXCLUDE_TESTS += test^make^step5 # no TCO capability/step
34 EXCLUDE_TESTS += test^mal^step5 # no TCO capability/step
35 EXCLUDE_TESTS += test^go^step5 # test completes, even at 100,000
36 EXCLUDE_TESTS += test^php^step5 # test completes, even at 100,000
37 EXCLUDE_TESTS += test^racket^step5 # test completes
38 EXCLUDE_TESTS += test^ruby^step5 # test completes, even at 100,000
39 EXCLUDE_TESTS += test^rust^step5 # no catching stack overflows
40 EXCLUDE_TESTS += test^ocaml^step5 # test completes, even at 1,000,000
41 EXCLUDE_TESTS += test^nim^step5 # test completes, even at 100,000
42
43 # interop tests now implemented yet
44 EXCLUDE_TESTS += test^cs^stepA test^go^stepA test^haskell^stepA \
45 test^java^stepA test^mal^stepA test^mal^step0 \
46 test^php^stepA test^ps^stepA test^python^stepA \
47 test^ruby^stepA test^rust^stepA test^vb^stepA
48
49 EXCLUDE_PERFS = perf^mal # TODO: fix this
50
51 #
52 # Utility functions
53 #
54
55 STEP_TEST_FILES = $(strip $(wildcard $(1)/tests/$($(2)).mal) $(wildcard tests/$($(2)).mal))
56
57 bash_STEP_TO_PROG = bash/$($(1)).sh
58 c_STEP_TO_PROG = c/$($(1))
59 clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
60 coffee_STEP_TO_PROG = coffee/$($(1)).coffee
61 cs_STEP_TO_PROG = cs/$($(1)).exe
62 forth_STEP_TO_PROG = forth/$($(1)).fs
63 go_STEP_TO_PROG = go/$($(1))
64 java_STEP_TO_PROG = java/src/main/java/mal/$($(1)).java
65 haskell_STEP_TO_PROG = haskell/$($(1))
66 js_STEP_TO_PROG = js/$($(1)).js
67 lua_STEP_TO_PROG = lua/$($(1)).lua
68 make_STEP_TO_PROG = make/$($(1)).mk
69 mal_STEP_TO_PROG = mal/$($(1)).mal
70 ocaml_STEP_TO_PROG = ocaml/$($(1))
71 matlab_STEP_TO_PROG = matlab/$($(1)).m
72 miniMAL_STEP_TO_PROG = miniMAL/$($(1)).json
73 perl_STEP_TO_PROG = perl/$($(1)).pl
74 php_STEP_TO_PROG = php/$($(1)).php
75 ps_STEP_TO_PROG = ps/$($(1)).ps
76 python_STEP_TO_PROG = python/$($(1)).py
77 r_STEP_TO_PROG = r/$($(1)).r
78 racket_STEP_TO_PROG = racket/$($(1)).rkt
79 ruby_STEP_TO_PROG = ruby/$($(1)).rb
80 rust_STEP_TO_PROG = rust/target/release/$($(1))
81 scala_STEP_TO_PROG = scala/$($(1)).scala
82 vb_STEP_TO_PROG = vb/$($(1)).exe
83 nim_STEP_TO_PROG = nim/$($(1))
84
85 # Needed some argument munging
86 COMMA = ,
87 noop =
88 SPACE = $(noop) $(noop)
89
90 bash_RUNSTEP = bash ../$(2) $(3)
91 c_RUNSTEP = ../$(2) $(3)
92 clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3)
93 coffee_RUNSTEP = coffee ../$(2) $(3)
94 cs_RUNSTEP = mono ../$(2) --raw $(3)
95 forth_RUNSTEP = gforth ../$(2) $(3)
96 go_RUNSTEP = ../$(2) $(3)
97 haskell_RUNSTEP = ../$(2) $(3)
98 java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" -Dexec.args="--raw$(if $(3), $(3),)"
99 js_RUNSTEP = node ../$(2) $(3)
100 lua_RUNSTEP = ../$(2) --raw $(3)
101 make_RUNSTEP = make -f ../$(2) $(3)
102 mal_RUNSTEP = $(call $(MAL_IMPL)_RUNSTEP,$(1),$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),../$(2),") #"
103 ocaml_RUNSTEP = ../$(2) $(3)
104 matlab_args = $(subst $(SPACE),$(COMMA),$(foreach x,$(strip $(1)),'$(x)'))
105 matlab_RUNSTEP = matlab -nodisplay -nosplash -nodesktop -nojvm -r "$($(1))($(call matlab_args,$(3)));quit;"
106 miniMAL_RUNSTEP = miniMAL ../$(2) $(3)
107 perl_RUNSTEP = perl ../$(2) --raw $(3)
108 php_RUNSTEP = php ../$(2) $(3)
109 ps_RUNSTEP = $(4)gs -q -I./ -dNODISPLAY -- ../$(2) $(3)$(4)
110 python_RUNSTEP = $(PYTHON) ../$(2) $(3)
111 r_RUNSTEP = Rscript ../$(2) $(3)
112 racket_RUNSTEP = ../$(2) $(3)
113 ruby_RUNSTEP = ruby ../$(2) $(3)
114 rust_RUNSTEP = ../$(2) $(3)
115 scala_RUNSTEP = sbt 'run-main $($(1))$(if $(3), $(3),)'
116 vb_RUNSTEP = mono ../$(2) --raw $(3)
117 nim_RUNSTEP = ../$(2) $(3)
118
119 # Extra options to pass to runtest.py
120 cs_TEST_OPTS = --mono
121 mal_TEST_OPTS = --start-timeout 60 --test-timeout 120
122 vb_TEST_OPTS = --mono
123
124
125 # Derived lists
126 STEPS = $(sort $(filter step%,$(.VARIABLES)))
127 IMPL_TESTS = $(foreach impl,$(IMPLS),test^$(impl))
128 STEP_TESTS = $(foreach step,$(STEPS),test^$(step))
129 ALL_TESTS = $(filter-out $(EXCLUDE_TESTS),\
130 $(strip $(sort \
131 $(foreach impl,$(IMPLS),\
132 $(foreach step,$(STEPS),test^$(impl)^$(step))))))
133
134 IMPL_STATS = $(foreach impl,$(IMPLS),stats^$(impl))
135 IMPL_STATS_LISP = $(foreach impl,$(IMPLS),stats-lisp^$(impl))
136
137 IMPL_PERF = $(filter-out $(EXCLUDE_PERFS),$(foreach impl,$(IMPLS),perf^$(impl)))
138
139 #
140 # Build rules
141 #
142
143 # Build a program in 'c' directory
144 c/%:
145 $(MAKE) -C $(dir $(@)) $(notdir $(@))
146
147 # Allow test, test^STEP, test^IMPL, and test^IMPL^STEP
148 .SECONDEXPANSION:
149 $(IMPL_TESTS): $$(filter $$@^%,$$(ALL_TESTS))
150
151 .SECONDEXPANSION:
152 $(STEP_TESTS): $$(foreach step,$$(subst test^,,$$@),$$(filter %^$$(step),$$(ALL_TESTS)))
153
154 .SECONDEXPANSION:
155 $(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
156 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
157 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
158 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
159 $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
160 echo '----------------------------------------------'; \
161 echo 'Testing $@, step file: $+, test file: $(test)'; \
162 echo 'Running: ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+))'; \
163 ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+)))))
164
165 test: $(ALL_TESTS)
166 tests: $(ALL_TESTS)
167
168
169 # Stats rules
170
171 stats: $(IMPL_STATS)
172 stats-lisp: $(IMPL_STATS_LISP)
173
174 .SECONDEXPANSION:
175 $(IMPL_STATS):
176 @echo "----------------------------------------------"; \
177 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
178 echo "Stats for $(impl):"; \
179 $(MAKE) --no-print-directory -C $(impl) stats)
180
181 .SECONDEXPANSION:
182 $(IMPL_STATS_LISP):
183 @echo "----------------------------------------------"; \
184 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
185 echo "Stats (lisp only) for $(impl):"; \
186 $(MAKE) --no-print-directory -C $(impl) stats-lisp)
187
188
189 # Performance test rules
190
191 perf: $(IMPL_PERF)
192
193 .SECONDEXPANSION:
194 $(IMPL_PERF):
195 @echo "----------------------------------------------"; \
196 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
197 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
198 echo "Performance test for $(impl):"; \
199 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal)'; \
200 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal); \
201 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal)'; \
202 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal); \
203 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal)'; \
204 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf3.mal))
205