-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
97 lines (70 loc) · 2.14 KB
/
Copy pathMakefile
File metadata and controls
97 lines (70 loc) · 2.14 KB
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
BUILD_ID :=\"$(shell git log -1 --abbrev-commit --pretty=oneline)\"
ARCH ?= arm64
PLAT ?= qemu_virt
NCPU ?= 1
DEBUG ?= 1
ARCH_ASM_OBJS :=
ARCH_OBJS :=
KERNEL_ROOT := $(PWD)
include arch/$(ARCH)/arch.mk
INCLUDE := -Iinclude/ -Ilib/include
INCLUDE += -Iarch/$(ARCH)/include -Iarch/$(ARCH)
INCLUDE += -Iplat/$(PLAT)/
OUTPUT := out-$(ARCH)
CFLAGS := -nostdlib -nostdinc -ffreestanding -nostartfiles -fno-builtin $(INCLUDE) $(ARCH_CFLAGS)
CFLAGS += -Wall -Werror
CFLAGS += -DBUILD_ID='"$(BUILD_ID)"' -DNCPU=$(NCPU)
ifeq ($(DEBUG), 1)
CFLAGS += -g
else
CFLAGS += -O3
endif
CONFIG_AJIT ?= 0
ifeq ($(ARCH), sparc)
CONFIG_AJIT = 1
endif
export CONFIG_AJIT
CC := $(CROSS_COMPILE)-gcc
OC := $(CROSS_COMPILE)-objcopy
OD := $(CROSS_COMPILE)-objdump
CORE_KERNEL_OBJS :=
DRIVER_OBJS :=
LIB_OBJS :=
include kernel/core.mk
include drivers/drivers.mk
include lib/lib.mk
CORE_KERNEL_OBJS := $(addprefix kernel/, $(CORE_KERNEL_OBJS))
DRIVER_OBJS := $(addprefix drivers/, $(DRIVER_OBJS))
LIB_OBJS := $(addprefix lib/, $(LIB_OBJS))
ARCH_OBJS := $(addprefix arch/$(ARCH)/, $(ARCH_OBJS))
ARCH_ASM_OBJS := $(addprefix arch/$(ARCH)/, $(ARCH_ASM_OBJS))
ALL_OBJS := $(addprefix $(OUTPUT)/,$(ARCH_ASM_OBJS) $(ARCH_OBJS) $(CORE_KERNEL_OBJS) $(DRIVER_OBJS) $(LIB_OBJS))
ALL_DIRS := $(dir $(ALL_OBJS))
define compile_c_targets
$(OUTPUT)/$(1): $(basename $(1)).c
@$(CC) -c $$^ $(CFLAGS) -o $$@
@echo "CC\t$$^"
endef
define compile_asm_targets
$(OUTPUT)/$(1): $(basename $(1)).S
@$(CC) -c $$^ $(CFLAGS) -o $$@
@echo "CC\t$$^"
endef
default: $(OUTPUT)/kernel.elf
$(foreach f,$(ARCH_ASM_OBJS), $(eval $(call compile_asm_targets,$f)))
$(foreach f,$(ARCH_OBJS) $(CORE_KERNEL_OBJS) $(DRIVER_OBJS) $(LIB_OBJS), $(eval $(call compile_c_targets,$f)))
all_dirs:
@mkdir -p $(ALL_DIRS)
$(OUTPUT)/linker.ld: linker.ld.S
@$(CC) -E -P -x c $(INCLUDE) $< > $@
@echo "GEN\t$@"
$(ALL_OBJS): | all_dirs
$(OUTPUT)/kernel.elf: $(ALL_OBJS) $(OUTPUT)/linker.ld
@$(CC) -T $(OUTPUT)/linker.ld $(CFLAGS) $(ALL_OBJS) -o $@
@$(OC) -O binary $@ $(OUTPUT)/kernel.bin
@$(OD) -d $@ > $(OUTPUT)/kernel.dis
@
@echo "OUT\t$@"
clean:
@rm -rf $(OUTPUT)
@echo "CLEAN"