-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
59 lines (44 loc) · 1.44 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
NAME=advos
QEMU=qemu-system-riscv32
XARGO=xargo
TARGET=riscv32imac-unknown-none-elf
CROSS=riscv64-unknown-linux-gnu
CC=$(CROSS)-gcc
CXX=$(CROSS)-g++
AS=$(CROSS)-as
GDB=$(CROSS)-gdb
LDSFILE=lds/hifive.lds
ASFLAGS=-march=rv32ima -mabi=ilp32 -Og -g
LDFLAGS=-T$(LDSFILE) -march=rv32ima -mabi=ilp32 -Og -g -nostartfiles -nostdinc -ffreestanding -nostdlib -Ltarget/$(TARGET)/debug -L.
OUT=$(NAME).elf
QEMUARGS=-machine sifive_e -nographic -serial mon:stdio -kernel $(OUT)
ASM_SOURCES=$(wildcard asm/*.S)
ASM_OBJECTS=$(patsubst %.S,%.o,$(ASM_SOURCES))
RUST_SOURCES:=$(wildcard src/*.rs)
RUST_SOURCES+=$(wildcard src/**/*.rs)
RUST_OBJECT=target/$(TARGET)/debug/lib$(NAME).a
LIBS=-l$(NAME) -lgcc
all: $(OUT)
$(OUT): Makefile $(ASM_OBJECTS) $(RUST_OBJECT) $(LDSFILE)
$(CC) $(LDFLAGS) -o $(OUT) $(ASM_OBJECTS) $(LIBS)
%.o: %.S Makefile
$(CC) $(ASFLAGS) -c $< -o $@
$(RUST_OBJECT): Makefile $(RUST_SOURCES)
$(XARGO) build --target=$(TARGET)
qemu: $(OUT)
$(QEMU) $(QEMUARGS)
gdb: $(OUT)
$(QEMU) $(QEMUARGS) -S -s &
$(GDB) $(OUT) -ex "target remote localhost:1234"
test: Makefile $(ASM_OBJECTS) $(LDSFILE)
$(XARGO) build --target=$(TARGET) --features "testing"
$(CC) $(LDFLAGS) -o $(OUT) $(ASM_OBJECTS) $(LIBS)
$(QEMU) $(QEMUARGS)
$(MAKE) clean
board: Makefile $(ASM_OBJECTS) $(LDSFILE)
$(XARGO) build --target=$(TARGET) --features "board"
$(CC) $(LDFLAGS) -o $(OUT) $(ASM_OBJECTS) $(LIBS)
.PHONY: clean
clean:
$(XARGO) clean
rm -fr $(OUT) $(ASM_OBJECTS)