Current state of mal for Clojure West lighting talk.
[jackhill/mal.git] / Makefile
CommitLineData
31690700
JM
1#
2# Command line settings
3#
4
5MAL_IMPL = js
6
7#
8# Settings
9#
10
11IMPLS = bash c clojure java js make php python mal
12
13step0 = step0_repl
14step1 = step1_read_print
15step2 = step2_eval
16step3 = step3_env
17step4 = step4_if_fn_do
18step5 = step5_tco
19step6 = step6_file
20step7 = step7_quote
21step8 = step8_macros
22step9 = step9_interop
23stepA = stepA_more
24
25EXCLUDE_TESTS = test^make^step5 test^mal^step0 test^mal^step5 test^mal^step9 test^java^step9
26
27#
28# Utility functions
29#
30
31STEP_TEST_FILES = $(strip $(wildcard $(1)/tests/$($(2)).mal) $(wildcard tests/$($(2)).mal))
32
33bash_STEP_TO_PROG = bash/$($(1)).sh
34c_STEP_TO_PROG = c/$($(1))
35clojure_STEP_TO_PROG = clojure/src/$($(1)).clj
36java_STEP_TO_PROG = java/src/main/java/mal/$($(1)).java
37js_STEP_TO_PROG = js/$($(1)).js
38make_STEP_TO_PROG = make/$($(1)).mk
39php_STEP_TO_PROG = php/$($(1)).php
40python_STEP_TO_PROG = python/$($(1)).py
41mal_STEP_TO_PROG = mal/$($(1)).mal
42
43
44bash_RUNTEST = ../runtest.py $(4) ../$(1) -- bash ../$(2) $(5)
45c_RUNTEST = ../runtest.py $(4) ../$(1) -- ../$(2) $(5)
46clojure_RUNTEST = ../runtest.py $(4) ../$(1) -- lein with-profile +$(3) trampoline run $(5)
47java_RUNTEST = ../runtest.py $(4) ../$(1) -- mvn -quiet exec:java -Dexec.mainClass="mal.$($(3))" -Dexec.args="--raw$(if $(5), $(5),)"
48js_RUNTEST = ../runtest.py $(4) ../$(1) -- node ../$(2) $(5)
49make_RUNTEST = ../runtest.py $(4) ../$(1) -- make -f ../$(2) $(5)
50php_RUNTEST = ../runtest.py $(4) ../$(1) -- php ../$(2) $(5)
51python_RUNTEST = ../runtest.py $(4) ../$(1) -- python ../$(2) $(5)
52mal_RUNTEST = $(call $(MAL_IMPL)_RUNTEST,$(1),$(call $(MAL_IMPL)_STEP_TO_PROG,stepA),stepA,--start-timeout 30 --test-timeout 120,../$(2))
53
54
55# Derived lists
56STEPS = $(sort $(filter step%,$(.VARIABLES)))
57IMPL_TESTS = $(foreach impl,$(IMPLS),test^$(impl))
58STEP_TESTS = $(foreach step,$(STEPS),test^$(step))
59ALL_TESTS = $(filter-out $(EXCLUDE_TESTS),\
60 $(strip $(sort \
61 $(foreach impl,$(IMPLS),\
62 $(foreach step,$(STEPS),test^$(impl)^$(step))))))
63
64IMPL_STATS = $(foreach impl,$(IMPLS),stats^$(impl))
65
66#
67# Build rules
68#
69
70# Build a program in 'c' directory
71c/%:
72 $(MAKE) -C $(dir $(@)) $(notdir $(@))
73
74# Allow test, test^STEP, test^IMPL, and test^IMPL^STEP
75.SECONDEXPANSION:
76$(IMPL_TESTS): $$(filter $$@^%,$$(ALL_TESTS))
77
78.SECONDEXPANSION:
79$(STEP_TESTS): $$(foreach step,$$(subst test^,,$$@),$$(filter %^$$(step),$$(ALL_TESTS)))
80
81.SECONDEXPANSION:
82$(ALL_TESTS): $$(call $$(word 2,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 3,$$(subst ^, ,$$(@))))
83 @$(foreach impl,$(word 2,$(subst ^, ,$(@))),\
84 $(foreach step,$(word 3,$(subst ^, ,$(@))),\
85 cd $(if $(filter mal,$(impl)),$(MAL_IMPL),$(impl)); \
86 $(foreach test,$(call STEP_TEST_FILES,$(impl),$(step)),\
87 echo '----------------------------------------------'; \
88 echo 'Testing $@, step file: $+, test file: $(test)'; \
89 echo 'Running: $(call $(impl)_RUNTEST,$(test),$(+),$(step))'; \
90 $(call $(impl)_RUNTEST,$(test),$(+),$(step)))))
91
92test: $(ALL_TESTS)
93tests: $(ALL_TESTS)
94
95
96# Stats rules
97
98.SECONDEXPANSION:
99$(IMPL_STATS):
100 @echo "----------------------------------------------"; \
101 $(foreach impl,$(word 2,$(subst ^, ,$(@))),\
102 echo "Stats for $(impl):"; \
103 $(MAKE) --no-print-directory -C $(impl) stats)
104
105stats: $(IMPL_STATS)