This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
116 lines (90 loc) · 2.58 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
# See LICENSE file for copyright and license details.
.POSIX:
PROGRAM ?=separation-kernel
BUILD ?=build
TARGET=$(ELF) $(BIN)
ELF=$(BUILD)/$(PROGRAM).elf
BIN=$(BUILD)/$(PROGRAM).bin
LDS ?=config.lds
CONFIG_H ?=config.h
PLATFORM_H ?=bsp/virt.h
C_SRCS=$(wildcard src/*.c)
S_SRCS=$(wildcard src/*.S)
OBJS=$(patsubst %.c, $(BUILD)/%.o, $(C_SRCS)) \
$(patsubst %.S, $(BUILD)/%.o, $(S_SRCS))
DEPS=$(patsubst %.c, $(BUILD)/%.d, $(C_SRCS)) \
$(patsubst %.S, $(BUILD)/%.d, $(S_SRCS))
HDRS=$(wildcard inc/*.h) $(CAP_H) $(ASM_CONST_H) $(CONFIG_H) $(PLATFORM_H)
DA=$(patsubst %.elf, %.da, $(ELF))
CAP_H=inc/gen/cap.h
ASM_CONSTS_H=inc/gen/asm_consts.h
# Tools
RISCV_PREFIX ?=riscv64-unknown-elf
CC=$(RISCV_PREFIX)-gcc
SIZE=$(RISCV_PREFIX)-size
OBJCOPY=$(RISCV_PREFIX)-objcopy
OBJDUMP=$(RISCV_PREFIX)-objdump
ARCH ?=rv64imac
ABI ?=lp64
CMODEL ?=medany
CFLAGS+=-march=$(ARCH) -mabi=$(ABI) -mcmodel=$(CMODEL)
CFLAGS+=-std=gnu18
CFLAGS+= -T$(LDS) -nostartfiles
CFLAGS+=-Wall -fanalyzer -Werror
CFLAGS+=-gdwarf-2
CFLAGS+=-Og
CFLAGS+=-include $(PLATFORM_H) -include $(CONFIG_H)
CFLAGS+=-Iinc
ifneq "$(PAYLOAD)" ""
CFLAGS+=-DPAYLOAD=\"$(PAYLOAD)\"
endif
.PHONY: all target clean size da cloc format api
.SECONDARY:
all: target
target: $(TARGET)
$(CAP_H): gen/cap.yml scripts/cap_gen.py
@printf "GEN\t$@\n"
@mkdir -p $(@D)
@./scripts/cap_gen.py $< > $@
$(ASM_CONSTS_H): gen/asm_consts.c inc/proc.h inc/cap_node.h inc/consts.h
@printf "GEN\t$@\n"
@mkdir -p $(@D)
@$(CC) $(CFLAGS) -S -o - $< | grep -oE "#\w+ .*" > $@
$(BUILD)/%.o: %.S $(ASM_CONSTS_H) $(CONFIG_H) $(PLATFORM_H) $(PAYLOAD)
@printf "CC\t$@\n"
@mkdir -p $(@D)
@$(CC) $(CFLAGS) -MMD -c -o $@ $<
$(BUILD)/%.o: %.c $(CAP_H) $(CONFIG_H) $(PLATFORM_H)
@printf "CC\t$@\n"
@mkdir -p $(@D)
@$(CC) $(CFLAGS) -MMD -c -o $@ $<
$(ELF): $(OBJS) $(LDS)
@printf "CC\t$@\n"
@mkdir -p $(@D)
@$(CC) $(CFLAGS) -o $@ $(OBJS)
$(BIN): $(ELF)
@printf "OBJCOPY\t$@\n"
@$(OBJCOPY) -O binary $< $@
$(DA): $(ELF)
@printf "OBJDUMP\t$@\n"
@$(OBJDUMP) -d $< > $@
api/s3k_cap.h: inc/gen/cap.h
@printf "GEN\t$@\n"
@sed '/kassert/d' inc/gen/cap.h > api/s3k_cap.h
api/s3k_consts.h: inc/const.h
@printf "GEN\t$@\n"
@cp inc/consts.h api/s3k_consts.h
api: api/s3k_consts.h api/s3k_cap.h
clean:
@echo "CLEAN\t$(PROGRAM)"
@rm -f $(OBJS) $(DEPS) $(CAP_H) $(ASM_CONST_H) $(TARGET) $(DA)
size:
@printf "SIZE\t$(PROGRAM)\n"
@$(SIZE) $(OBJS) $(TARGET)
cloc:
@printf "CLOC\t$(PROGRAM)\n"
@cloc $(HDRS) $(SRCS)
format:
@printf "FORMAT\t$(PROGRAM)\n"
@clang-format -i $(filter inc/%.h, $(HDRS)) $(filter src/%.c, $(SRCS)) $(wildcard api/*.h)
-include $(DEPS)