go: update README. Backport Func usage.
[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
69b4abd6 13IMPLS = bash c clojure cs go java js make mal perl php ps python ruby
31690700
JM
14
15step0 = step0_repl
16step1 = step1_read_print
17step2 = step2_eval
18step3 = step3_env
19step4 = step4_if_fn_do
20step5 = step5_tco
21step6 = step6_file
22step7 = step7_quote
23step8 = step8_macros
24step9 = step9_interop
25stepA = stepA_more
26
cc021efe
JM
27EXCLUDE_TESTS += test^bash^step5 # no stack exhaustion or completion
28EXCLUDE_TESTS += test^c^step5 # segfault
29EXCLUDE_TESTS += test^cs^step5 # fatal stack overflow fault
30EXCLUDE_TESTS += test^make^step5 # no TCO capability/step
31EXCLUDE_TESTS += test^mal^step5 # no TCO capability/step
17e1c5f9 32EXCLUDE_TESTS += test^go^step5 # test completes, even at 100,000
cc021efe
JM
33EXCLUDE_TESTS += test^php^step5 # test completes, even at 100,000
34EXCLUDE_TESTS += test^ruby^step5 # test completes, even at 100,000
35
36# interop tests now implemented yet
37EXCLUDE_TESTS += test^cs^step9 test^java^step9 test^mal^step9 \
3f26b8f6
JM
38 test^mal^step0 test^php^step9 test^ps^step9 \
39 test^python^step9 test^ruby^step9
cc021efe 40
db4c329a 41EXCLUDE_PERFS = perf^mal # TODO: fix this
31690700
JM
42
43#
44# Utility functions
45#
46
47STEP_TEST_FILES = $(strip $(wildcard $(1)/tests/$($(2)).mal) $(wildcard tests/$($(2)).mal))
48
db4c329a
JM
49bash_STEP_TO_PROG = bash/$($(1)).sh
50c_STEP_TO_PROG = c/$($(1))
31690700 51clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
db4c329a 52cs_STEP_TO_PROG = cs/$($(1)).exe
69b4abd6 53go_STEP_TO_PROG = go/$($(1))
db4c329a
JM
54java_STEP_TO_PROG = java/src/main/java/mal/$($(1)).java
55js_STEP_TO_PROG = js/$($(1)).js
56make_STEP_TO_PROG = make/$($(1)).mk
57mal_STEP_TO_PROG = mal/$($(1)).mal
b5dedee0 58perl_STEP_TO_PROG = perl/$($(1)).pl
db4c329a
JM
59php_STEP_TO_PROG = php/$($(1)).php
60ps_STEP_TO_PROG = ps/$($(1)).ps
61python_STEP_TO_PROG = python/$($(1)).py
62ruby_STEP_TO_PROG = ruby/$($(1)).rb
63
64
65bash_RUNSTEP = bash ../$(2) $(3)
66c_RUNSTEP = ../$(2) $(3)
67clojure_RUNSTEP = lein with-profile +$(1) trampoline run $(3)
68cs_RUNSTEP = mono ../$(2) --raw $(3)
69b4abd6 69go_RUNSTEP = ../$(2) $(3)
db4c329a
JM
70java_RUNSTEP = mvn -quiet exec:java -Dexec.mainClass="mal.$($(1))" -Dexec.args="--raw$(if $(3), $(3),)"
71js_RUNSTEP = node ../$(2) $(3)
72make_RUNSTEP = make -f ../$(2) $(3)
73mal_RUNSTEP = $(call $(MAL_IMPL)_RUNSTEP,$(1),$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),../$(2),") #"
b5dedee0 74perl_RUNSTEP = perl ../$(2) $(3)
db4c329a
JM
75php_RUNSTEP = php ../$(2) $(3)
76ps_RUNSTEP = $(4)gs -q -dNODISPLAY -- ../$(2) $(3)$(4)
77python_RUNSTEP = $(PYTHON) ../$(2) $(3)
78ruby_RUNSTEP = ruby ../$(2) $(3)
79
80# Extra options to pass to runtest.py
81cs_TEST_OPTS = --redirect
6301e0b6 82mal_TEST_OPTS = --start-timeout 60 --test-timeout 120
31690700
JM
83
84
85# Derived lists
86STEPS = $(sort $(filter step%,$(.VARIABLES)))
87IMPL_TESTS = $(foreach impl,$(IMPLS),test^$(impl))
88STEP_TESTS = $(foreach step,$(STEPS),test^$(step))
89ALL_TESTS = $(filter-out $(EXCLUDE_TESTS),\
90 $(strip $(sort \
91 $(foreach impl,$(IMPLS),\
92 $(foreach step,$(STEPS),test^$(impl)^$(step))))))
93
94IMPL_STATS = $(foreach impl,$(IMPLS),stats^$(impl))
712af9ef 95IMPL_STATS_LISP = $(foreach impl,$(IMPLS),stats-lisp^$(impl))
31690700 96
db4c329a
JM
97IMPL_PERF = $(filter-out $(EXCLUDE_PERFS),$(foreach impl,$(IMPLS),perf^$(impl)))
98
31690700
JM
99#
100# Build rules
101#
102
103# Build a program in 'c' directory
104c/%:
105 $(MAKE) -C $(dir $(@)) $(notdir $(@))
106
107# Allow test, test^STEP, test^IMPL, and test^IMPL^STEP
108.SECONDEXPANSION:
109$(IMPL_TESTS): $$(filter $$@^%,$$(ALL_TESTS))
110
111.SECONDEXPANSION:
112$(STEP_TESTS): $$(foreach step,$$(subst test^,,$$@),$$(filter %^$$(step),$$(ALL_TESTS)))
113
114.SECONDEXPANSION:
115$(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
116 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
117 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
118 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
119 $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
120 echo '----------------------------------------------'; \
121 echo 'Testing $@, step file: $+, test file: $(test)'; \
db4c329a
JM
122 echo 'Running: ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+))'; \
123 ../runtest.py $(call $(impl)_TEST_OPTS) ../$(test) -- $(call $(impl)_RUNSTEP,$(step),$(+)))))
31690700
JM
124
125test: $(ALL_TESTS)
126tests: $(ALL_TESTS)
127
128
129# Stats rules
130
db4c329a
JM
131stats: $(IMPL_STATS)
132stats-lisp: $(IMPL_STATS_LISP)
133
31690700
JM
134.SECONDEXPANSION:
135$(IMPL_STATS):
136 @echo "----------------------------------------------"; \
137 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
138 echo "Stats for $(impl):"; \
139 $(MAKE) --no-print-directory -C $(impl) stats)
140
712af9ef
JM
141.SECONDEXPANSION:
142$(IMPL_STATS_LISP):
143 @echo "----------------------------------------------"; \
144 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
145 echo "Stats (lisp only) for $(impl):"; \
146 $(MAKE) --no-print-directory -C $(impl) stats-lisp)
147
db4c329a
JM
148
149# Performance test rules
150
151perf: $(IMPL_PERF)
152
153.SECONDEXPANSION:
154$(IMPL_PERF):
155 @echo "----------------------------------------------"; \
156 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
157 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
158 echo "Performance test for $(impl):"; \
159 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal)'; \
160 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf1.mal); \
161 echo 'Running: $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal)'; \
162 $(call $(impl)_RUNSTEP,stepA,$(call $(impl)_STEP_TO_PROG,stepA),../tests/perf2.mal))
163