Makefile 3.0 KiB raw
1
# Radiance build file.
2
3
# Core standard library modules.
4
STD := -pkg std $(patsubst %,-mod %,$(shell cat std.lib))
5
6
# Full standard library with test modules.
7
STD_TEST := $(STD) $(patsubst %,-mod %,$(shell cat std.lib.test))
8
9
# Source files.
10
STD_LIB := $(shell find lib -name '*.rad')
11
RAD_BIN := bin/radiance.rv64.dev
12
13
# Emulator command used to invoke the self-hosted compiler.
14
EMU       := $(or $(RAD_EMULATOR),emulator)
15
EMU_FLAGS := -memory-size=385024 \
16
			 -data-size=348160 \
17
			 -stack-size=512 \
18
			 -count-instructions
19
RADIANCE  := $(EMU) $(EMU_FLAGS) -run $(RAD_BIN)
20
21
# Verify the emulator binary exists.
22
EMU_PATH := $(shell command -v $(EMU) 2>/dev/null)
23
24
default: emulator $(RAD_BIN)
25
test: emulator std-test bin-test
26
27
# Emulator command check
28
29
emulator:
30
ifeq ($(EMU_PATH),)
31
	$(error Emulator not found. Install it or set RAD_EMULATOR to its path)
32
endif
33
34
# Compiler build
35
36
SEED      := seed/radiance.rv64
37
SEED_OPTS := $(STD) -pkg radiance -mod compiler/radiance.rad -entry radiance
38
39
$(RAD_BIN): $(STD_LIB) compiler/radiance.rad
40
	@echo "radiance $(SEED) => $@"
41
	@$(EMU) $(EMU_FLAGS) -run $(SEED) $(SEED_OPTS) -o $@
42
43
# Standard Library Tests
44
45
STD_LIB_TEST := lib/std.test.rv64
46
47
std-test: $(STD_LIB_TEST)
48
	@echo
49
	@$(EMU) $(EMU_FLAGS) -run $(STD_LIB_TEST)
50
51
$(STD_LIB_TEST): $(STD_LIB) $(RAD_BIN)
52
	@echo "radiance -test $(STD_TEST) -entry std -o $@"
53
	@$(RADIANCE) -test $(STD_TEST) -entry std -o $@
54
55
clean-std-test:
56
	@rm -f lib/std.test.rv64 \
57
		lib/std.test.rv64.debug \
58
		lib/std.test.rv64.s \
59
		lib/std.test.rv64.o \
60
		lib/std.test.rv64.rw.data \
61
		lib/std.test.rv64.ro.data
62
63
# Binary Tests
64
65
BIN_TEST_DIR := test/tests
66
# Only tests with `//! returns:` are compiled to binaries and executed.
67
BIN_TEST_EXE_SRC := $(shell grep -rl '^//! returns:' $(BIN_TEST_DIR))
68
BIN_TEST_EXE_BIN := $(BIN_TEST_EXE_SRC:.rad=.rv64)
69
BIN_RUNNER   := test/runner.rv64
70
BIN_TEST_RUN := test/run
71
72
bin-test: $(BIN_RUNNER) $(BIN_TEST_EXE_BIN)
73
	@echo
74
	@$(BIN_TEST_RUN)
75
76
# Runner binary: the lowering IL checker.
77
$(BIN_RUNNER): test/runner.rad $(STD_LIB) $(RAD_BIN)
78
	@echo "radiance test/runner.rad => $@"
79
	@$(RADIANCE) $(STD) -pkg runner -mod test/runner.rad -entry runner -o $@
80
81
# Compile each executable test to a binary.
82
$(BIN_TEST_DIR)/%.rv64: $(BIN_TEST_DIR)/%.rad $(RAD_BIN)
83
	@echo "radiance $< => $@"
84
	@$(RADIANCE) -pkg test -mod $< -o $@
85
86
clean-bin-test:
87
	@rm -f $(BIN_RUNNER) \
88
		$(BIN_RUNNER:.rv64=.rv64.debug) \
89
		$(BIN_RUNNER:.rv64=.rv64.s) \
90
		$(BIN_RUNNER:.rv64=.rv64.o) \
91
		$(BIN_RUNNER:.rv64=.rv64.rw.data) \
92
		$(BIN_RUNNER:.rv64=.rv64.ro.data) \
93
		$(BIN_TEST_EXE_BIN) \
94
		$(wildcard $(BIN_TEST_DIR)/*.rv64.debug) \
95
		$(wildcard $(BIN_TEST_DIR)/*.rv64.s) \
96
		$(wildcard $(BIN_TEST_DIR)/*.rv64.rw.data) \
97
		$(wildcard $(BIN_TEST_DIR)/*.rv64.ro.data)
98
99
seed:
100
	seed/update
101
102
clean-rad:
103
	rm -rf bin/*
104
	rm -f seed/radiance.rv64.s[0-9]*
105
106
clean: clean-std-test clean-bin-test clean-rad
107
108
t: test
109
c: clean
110
111
.PHONY: test clean default std-test bin-test seed \
112
	clean-std-test clean-bin-test clean-rad emulator
113
.SUFFIXES:
114
.DELETE_ON_ERROR:
115
.SILENT: