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