-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
173 lines (136 loc) · 4.01 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
.PHONY: all
all:
@echo "targets:"
@echo " - test (test-rust, test-elisp, test-foolang, test-cps,"
@echo " test-runtime, test-c-backend, test-benchmark)"
@echo " - clean (clean-c, clean-rust)"
@echo " - commit (tests and commits)"
@echo " - amend (tests and amends last commit)"
.EXTRA_PREREQS:= $(abspath $(lastword $(MAKEFILE_LIST)))
CC := $(shell bash ./find-tool.sh --cc)
AR := $(shell bash ./find-tool.sh --ar)
OK := ok
ifeq ($(strip $(CC)),)
OK :=
endif
ifeq ($(strip $(AR)),)
OK :=
endif
ifeq ($(strip $(OK)),)
$(shell bash ./find-tool.sh --debug 1>&2)
$(error ERROR - Could not find both CC and AR!)
endif
$(info Using CC = $(CC), AR = $(AR))
CPPFLAGS = -Iruntime -Iext
CFLAGS = -g -Wall -Wextra -fsanitize=address -fsanitize=undefined
DEPFLAGS = -MT $@ -MMD -MP -MF build/$*.d
BUILD.a = @$(AR) rc
BUILD.o = @$(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) -c
BUILD.exe = @$(CC) $(CFLAGS) $(CPPFLAGS)
SILENCE = | (grep -v "Creating library" || true)
LOG_BUILD = @echo Building: $@
ifeq ($(OS), Windows_NT)
EXE=.exe
else
EXE=.bin
endif
LIBFOO=build/libfoolang.a
RUNTIME_SRCS=$(wildcard runtime/*.c)
RUNTIME_OBJS=$(RUNTIME_SRCS:%.c=build/%.o)
RUNTIME_DEPFILES=$(RUNTIME_SRCS:%.c=build/%.d)
$(RUNTIME_OBJS): | build/runtime
# Files under tests/c-backend/ are code emitted by
# the C-backend.
#
# Emission tests check that we get the source we expect
# by comparing to the saved files.
#
# Run tests compile and run the saved files. This means
# re-running tests doesn't need to rebuild all tests unless
# the expected source (or runtime!) has changed.
C_BACKEND_TEST_SRCS=$(wildcard tests/c-backend/*.c)
C_BACKEND_TEST_OBJS=$(C_BACKEND_TEST_SRCS:%.c=build/%.o)
C_BACKEND_TEST_EXES=$(C_BACKEND_TEST_SRCS:%.c=build/%$(EXE))
C_BACKEND_TEST_RUNS=$(C_BACKEND_TEST_SRCS:%.c=build/%.run)
$(C_BACKEND_TEST_OBJS): | build/tests/c-backend
# Files under tests/runtime are unit tests for runtime.
RUNTIME_TEST_SRCS=$(wildcard tests/runtime/*.c)
RUNTIME_TEST_OBJS=$(RUNTIME_TEST_SRCS:%.c=build/%.o)
$(RUNTIME_TEST_OBJS): | build/tests/runtime
# Files under tests/bench are benchmark-like tests.
# Currently a hand-compiled version of pi.foo, and
# same expressed in "natural" C.
#
# Currently just run, not timed.
BENCHMARK_SRCS=$(wildcard tests/benchmark/*.c)
BENCHMARK_OBJS=$(BENCHMARK_SRCS:%.c=build/%.o)
BENCHMARK_EXES=$(BENCHMARK_SRCS:%.c=build/%$(EXE))
BENCHMARK_RUNS=$(BENCHMARK_SRCS:%.c=build/%.run)
$(BENCHMARK_OBJS): | build/tests/benchmark
build/runtime:
@mkdir -p build/runtime
build/tests/c-backend:
@mkdir -p build/tests/c-backend
build/tests/runtime:
@mkdir -p build/tests/runtime
build/tests/benchmark:
@mkdir -p build/tests/benchmark
$(LIBFOO): $(RUNTIME_OBJS)
$(LOG_BUILD)
$(BUILD.a) $@ $(RUNTIME_OBJS)
build/tests/runtime/test$(EXE): $(RUNTIME_TEST_OBJS) $(LIBFOO)
$(LOG_BUILD)
$(BUILD.exe) -o $@ $^ $(SILENCE)
.PRECIOUS: %$(EXE)
%$(EXE): %.o $(LIBFOO)
$(LOG_BUILD)
$(BUILD.exe) -o $@ $^ $(SILENCE)
build/%.o : %.c
$(LOG_BUILD)
$(BUILD.o) -o $@ $<
.PHONY: build/%.run
build/%.run: build/%$(EXE)
@echo Running: $<
@set -eu; \
if [ -f $*.output ]; then \
$< | diff --strip-trailing-cr -u - $*.output; \
else \
$<; \
fi
.PHONY: test-benchmark
test-benchmark: $(BENCHMARK_RUNS)
.PHONY: test-c-backend
test-c-backend: $(C_BACKEND_TEST_RUNS)
.PHONY: test-runtime
test-runtime: build/tests/runtime/test.run
.PHONY: test-cps
test-cps:
cargo run foo/impl/cps.foo --use=foo/lib
# Purposefully not running the old transpiler tests!
.PHONY: test-foolang
cargo run foo/impl/test_foolang.foo --use=foo/lib
.PHONY: test-rust
test-rust:
@cargo test
.PHONY: test-elisp
test-elisp:
@tests/test-elisp.sh
.PHONY: test
test: test-rust test-elisp test-foolang
test: test-cps test-runtime test-c-backend test-benchmark
.PHONY: commit
commit: test
@git commit -a -v
.PHONY: amend
amend: test
@git commit -a --amend -v
.PHONY: clean
clean: clean-c clean-rust
.PHONY: clean-c
clean-c:
@rm -rf build/runtime build/test build/libfoolang.a
.PHONY: clean-rust
clean-rust:
@cargo clean
$(RUNTIME_DEPFILES):
include $(wildcard $(RUNTIME_DEPFILES))