-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
99 lines (80 loc) · 1.68 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
CC = riscv64-unknown-elf-gcc
SHELL = /bin/bash
BINARY = bin
HOST = riscv
GDB_PORT = 11111
GDB=riscv64-unknown-elf-gdb
CFLAGS ?= -O2
CPPFLAGS ?=
LDFLAGS ?=
LIBS ?=
include lib/make.config
include kernel/make.config
DESTDIR ?=
CFLAGS := $(CFLAGS) $(KERNEL_CFLAGS)
CPPFLAGS := $(CPPFLAGS) -Iinclude
LDFLAGS := $(LDFLAGS) -Wl,--gc-sections -nostartfiles -nodefaultlibs
LIBS := $(LIBS) -nostdlib -lgcc
ARCHDIR = arch/$(HOST)
include $(ARCHDIR)/make.config
CFLAGS := $(CFLAGS) $(KERNEL_ARCH_CFLAGS)
LDFLAGS := $(LDFLAGS) $(KERNEL_ARCH_LDFLAGS)
LIBS := $(LIBS) $(KERNEL_ARCH_LIBS)
include drivers/make.config
# make DEBUG=1
DEBUG ?= 0
ifeq ($(DEBUG), 1)
CFLAGS += -g -DDEBUG
else
CFLAGS += -DNDEBUG
endif
OBJS = \
$(KERNEL_LIBS) \
$(KERNEL_OBJS) \
$(KERNEL_ARCH_OBJS) \
$(KERNEL_DRIVER_OBJS)
LINK_LIST = \
$(LDFLAGS) \
$(OBJS) \
$(LIBS)
.PHONY: all clean quemu rebuild
.SUFFIXES: .o .c .S
all: rebuild
rebuild:
$(MAKE) clean
$(MAKE) $(BINARY)
$(BINARY): $(OBJS)
$(CC) -o $@ $(CPPFLAGS) $(CFLAGS) $(LINK_LIST)
.c.o:
$(CC) -MD -c $< -o $@ -std=gnu11 $(CFLAGS) $(CPPFLAGS)
.S.o:
$(CC) -MD -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
clean:
rm -r -f $(BINARY)
rm -f $(OBJS) *.o */*.o */*/*.o
rm -f $(OBJS:.o=.d) *.d */*.d */*/*.d
qemu-gdb:
echo "CTRL-a-x to quit Qemu when running -nographic"
qemu-system-riscv64 \
-machine virt \
-m 128M \
-kernel $(BINARY) \
-gdb tcp::$(GDB_PORT) \
-bios none \
-S \
-nographic
qemu:
echo "CTRL-a-x to quit Qemu when running -nographic"
qemu-system-riscv64 \
-machine virt \
-m 128M \
-kernel $(BINARY) \
-bios none \
-nographic
.PHONY: gdb
gdb:
$(GDB) \
-q \
-ex 'file $(BINARY)' \
-ex 'target remote localhost:$(GDB_PORT)' \
-ex "b main"