-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMakefile
More file actions
71 lines (54 loc) · 1.5 KB
/
Copy pathMakefile
File metadata and controls
71 lines (54 loc) · 1.5 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
# CONFIG: Architecture to build for
ARCH ?= amd64
ifeq ($(ARCH),amd64)
TRIPLE ?= x86_64-none-elf-
else ifeq ($(ARCH),x86)
TRIPLE ?= i686-elf-
else
$(error Unknown architecture $(ARCH))
endif
# Toolchain commands (can be overridden)
CARGO ?= cargo
RUSTC ?= rustc
LD := $(TRIPLE)ld
AS := $(TRIPLE)as
OBJDUMP := $(TRIPLE)objdump
OBJCOPY := $(TRIPLE)objcopy
# Object directory
OBJDIR := .obj/$(ARCH)/
LINKSCRIPT := arch/$(ARCH)/link.ld
TARGETSPEC := arch/$(ARCH)/target.json
# Compiler Options
LINKFLAGS := -T $(LINKSCRIPT)
LINKFLAGS += -Map $(OBJDIR)map.txt
LINKFLAGS += --gc-sections
LINKFLAGS += -z max-page-size=0x1000
RUSTFLAGS := --cfg arch__$(ARCH) -C soft-float
RUSTFLAGS += -C panic=abort
# Objects
OBJS := start.o kernel.a
OBJS := $(OBJS:%=$(OBJDIR)%)
BIN := ../kernel.$(ARCH).bin
.PHONY: all clean PHONY
all: $(BIN)
clean:
$(RM) -rf $(BIN) $(BIN).dsm $(OBJDIR)
# Final link command
$(BIN): $(OBJS) arch/$(ARCH)/link.ld
$(LD) -o $@ $(LINKFLAGS) $(OBJS)
$(OBJDUMP) -S $@ > $@.dsm
ifeq ($(ARCH),amd64)
@mv $@ $@.elf64
@$(OBJCOPY) $@.elf64 -F elf32-i386 $@
endif
# Compile rust kernel object
$(OBJDIR)kernel.a: PHONY Makefile $(TARGETSPEC)
@mkdir -p $(dir $@)
RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build -Z build-std=core --target=$(TARGETSPEC) --release
@cp --preserve target/target/release/libkernel.a $@
# Compile architecture's assembly stub
$(OBJDIR)start.o: arch/$(ARCH)/start.S Makefile
@mkdir -p $(dir $@)
$(AS) $(ASFLAGS) -o $@ $<
# Include dependency files
-include $(OBJDIR)start.d