-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
139 lines (114 loc) · 3.38 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
.POSIX:
BUILD?=build
S3K_PATH?=../s3k
CONFIG_H?=config.h
export RISCV_PREFIX ?=riscv64-unknown-elf-
export CC=${RISCV_PREFIX}gcc
export OBJCOPY=${RISCV_PREFIX}objcopy
export OBJDUMP=${RISCV_PREFIX}objdump
CFLAGS=-march=rv64imac -mabi=lp64 -mcmodel=medany\
-static-pie \
-std=c11\
-Wall -Werror\
-g -Os\
-flto\
-ffreestanding\
-Iinc
ASFLAGS=-march=rv64imac -mabi=lp64 -mcmodel=medany\
-g
LDFLAGS=-march=rv64imac -mabi=lp64 -mcmodel=medany\
-nostartfiles -static-pie -mno-relax\
-Wl,--gc-sections,--no-dynamic-linker\
-flto
# -Wl,--no-warn-rwx-segments\
# -Wstack-usage=2048 -fstack-usage\
# Build all
all: options $(BUILD)/boot.elf $(BUILD)/s3k.elf
options:
@printf "build options:\n"
@printf "CC = ${CC}\n"
@printf "LDFLAGS = ${LDFLAGS}\n"
@printf "ASFLAGS = ${ASFLAGS}\n"
@printf "CFLAGS = ${CFLAGS}\n"
@printf "S3K_PATH = ${S3K_PATH}\n"
@printf "CONFIG_H = ${abspath ${CONFIG_H}}\n"
# Clean all
clean:
rm -rf $(BUILD)
# API
api: inc/s3k.h lib/libs3k.a
inc/s3k.h: $(S3K_PATH)/api/s3k.h
cp $(S3K_PATH)/api/s3k.h inc/s3k.h
lib/libs3k.a: $(wildcard $(S3K_PATH)/api/*.c) inc/s3k.h
$(MAKE) -C $(S3K_PATH)/api libs3k.a
cp $(S3K_PATH)/api/libs3k.a lib/libs3k.a
qemu: $(BUILD)/s3k.elf $(BUILD)/boot.elf
./scripts/qemu.sh $^
$(BUILD)/%.c.o: %.c
@mkdir -p ${@D}
@printf "CC $@\n"
@$(CC) $(CFLAGS) -MMD -c -o $@ $<
$(BUILD)/%.S.o: %.S
@mkdir -p ${@D}
@printf "CC $@\n"
@$(CC) $(ASFLAGS) -MMD -c -o $@ $<
# Boot loader
SRCS=boot/main.c boot/capman.c boot/payload.S common/start.S
DEPS+=$(patsubst %, $(BUILD)/%.d, $(SRCS))
build/boot/payload.S.o: build/monitor.bin build/crypto.bin build/uartppp.bin
$(BUILD)/boot.elf: $(patsubst %, $(BUILD)/%.o, $(SRCS)) lib/libs3k.a
@mkdir -p ${@D}
@printf "CC $@\n"
@$(CC) $(LDFLAGS) -Tdefault.ld -o $@ $^
# Monitor
SRCS=monitor/main.c common/start.S
DEPS+=$(patsubst %, $(BUILD)/%.d, $(SRCS))
$(BUILD)/monitor.elf: $(patsubst %, $(BUILD)/%.o, $(SRCS)) lib/libs3k.a
@mkdir -p ${@D}
@printf "CC $@\n"
@$(CC) $(LDFLAGS) -Tdefault.ld -o $@ $^
# crypto
SRCS=crypto/main.c crypto/aes128.c common/start.S
DEPS+=$(patsubst %, $(BUILD)/%.d, $(SRCS))
$(BUILD)/crypto.elf: $(patsubst %, $(BUILD)/%.o, $(SRCS)) lib/libs3k.a
@mkdir -p ${@D}
@printf "CC $@\n"
@$(CC) $(LDFLAGS) -Tdefault.ld -o $@ $^
# UART driver
SRCS=uartppp/main.c uartppp/ppp.c common/start.S
DEPS+=$(patsubst %, $(BUILD)/%.d, $(SRCS))
$(BUILD)/uartppp.elf: $(patsubst %, $(BUILD)/%.o, $(SRCS)) lib/libs3k.a
@mkdir -p ${@D}
@printf "CC $@\n"
@$(CC) $(LDFLAGS) -Tdefault.ld -o $@ $^
# Application 0
SRCS=app0/main.c common/start.S
DEPS+=$(patsubst %, $(BUILD)/%.d, $(SRCS))
$(BUILD)/app0.elf: $(patsubst %, $(BUILD)/%.o, $(SRCS)) lib/libs3k.a
@mkdir -p ${@D}
@printf "CC $@\n"
@$(CC) $(LDFLAGS) -Tdefault.ld -o $@ $^
# Application 1
SRCS=app1/main.c common/start.S
DEPS+=$(patsubst %, $(BUILD)/%.d, $(SRCS))
$(BUILD)/app1.elf: $(patsubst %, $(BUILD)/%.o, $(SRCS)) lib/libs3k.a
@mkdir -p ${@D}
@printf "CC $@\n"
@$(CC) $(LDFLAGS) -Tdefault.ld -o $@ $^
# Make kernel
$(BUILD)/s3k.elf: ${CONFIG_H}
@mkdir -p ${@D}
@${MAKE} -C ${S3K_PATH} options kernel \
CONFIG_H=${abspath ${CONFIG_H}} \
BUILD_DIR=$(abspath $(BUILD)) \
OBJ_DIR=$(abspath $(BUILD))/s3k
# Create bin file from elf
%.bin: %.elf
@printf "OBJCOPY $< $@\n"
@${OBJCOPY} -O binary $< $@
# Create assebly dump
%.da: %.elf
@printf "OBJDUMP $< $@\n"
@${OBJDUMP} -d $< > $@
.PHONY: all api clean qemu s3k.elf
-include $(DEPS)