Makefile 1.2 KiB raw
1
# Builds the RISC-V emulator.
2
3
PREFIX  ?= $(HOME)/bin
4
CC      := clang
5
CFLAGS  := -fvisibility=hidden -std=c99 -O3 -g \
6
           -Wall -Wextra -Wpedantic \
7
           -Wformat=2 -Wformat-security \
8
           -Wnull-dereference \
9
           -Wno-format-nonliteral \
10
           -Wcast-align \
11
           -Wunused -Wuninitialized \
12
           -Wmissing-field-initializers \
13
           -fno-common -fstack-protector-all \
14
           -mcmodel=medium \
15
           -march=native -flto
16
LDFLAGS := -fuse-ld=lld -Wl,-z,stack-size=33554432
17
EMULATOR_SRCS  := emulator.c jit.c riscv/debug.c io.c riscv.c
18
19
default: bin/emulator
20
21
bin/emulator: $(EMULATOR_SRCS) jit.h color.h types.h io.h riscv.h riscv/debug.h
22
	@echo "cc    emulator => $@"
23
	@mkdir -p bin
24
	@$(CC) $(CFLAGS) $(LDFLAGS) $(EMULATOR_SRCS) -o $@
25
26
install: bin/emulator
27
	@echo "copy  bin/emulator => $(PREFIX)/emulator"
28
	@mkdir -p $(PREFIX)
29
	@cp bin/emulator $(PREFIX)/emulator
30
31
test: bin/emulator
32
	@mkdir -p build
33
	@printf '\163\045\100\361\163\000\120\020' > build/machine.rv64
34
	@bin/emulator -machine -run build/machine.rv64
35
36
fmt:
37
	git ls-files "*.c" "*.h" | xargs clang-format -i
38
39
clean:
40
	@rm -rf bin/emulator build
41
42
.PHONY: default clean install test
43
.SUFFIXES:
44
.DELETE_ON_ERROR:
45
.SILENT: