-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
62 lines (49 loc) · 1.39 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
SRCDIR := src
BUILDDIR := build
LINKER_SCRIPT := linker.ld
DEBUG ?= 0
TESTS ?= 0
ARCH ?= x86_64
RUST_FLAGS = +nightly
ASM_FLAGS = -f elf64
LINKER_FLAGS = -m elf_x86_64 -nostdlib
CARGO_BUILD_MODE :=
TARGET_DIR :=
ifeq ($(ARCH),x86_64)
$(info Building for architecture: $(ARCH))
else
$(error ARCH $(ARCH) is not supported)
endif
ifeq ($(TESTS), 1)
CARGO_BUILD_MODE += -F integration
DEBUG = 1
endif
ifeq ($(DEBUG), 1)
ASM_FLAGS += -g
LINKER_FLAGS += -g
TARGET_DIR := target/x86_64-unknown-none/debug
else
CARGO_BUILD_MODE += --release
TARGET_DIR := target/x86_64-unknown-none/release
endif
ASMSOURCES := $(shell find $(SRCDIR)/arch/$(ARCH) -name '*.asm')
OBJFILES := $(patsubst $(SRCDIR)/arch/$(ARCH)/%.asm, $(BUILDDIR)/%.o, $(ASMSOURCES))
RUST_KERNEL_OBJ := $(BUILDDIR)/kernel.o
KERNEL_ELF := $(BUILDDIR)/kernel.elf
ISODIR := $(BUILDDIR)/isofiles
all: $(KERNEL_ELF)
mkdir -p $(ISODIR)/boot/grub
cp $(KERNEL_ELF) $(ISODIR)/boot/kernel.elf
cp ./grub.cfg $(ISODIR)/boot/grub/
grub-mkrescue -o $(BUILDDIR)/tao-os.iso $(ISODIR)
$(BUILDDIR)/%.o: $(SRCDIR)/arch/$(ARCH)/%.asm
mkdir -p $(dir $@)
nasm $(ASM_FLAGS) $< -o $@
$(KERNEL_ELF): $(OBJFILES) $(RUST_KERNEL_OBJ)
ld $(LINKER_FLAGS) -T $(LINKER_SCRIPT) $^ -o $@
$(RUST_KERNEL_OBJ):
cargo $(RUST_FLAGS) build $(CARGO_BUILD_MODE) --target x86_64-unknown-none
cp $(TARGET_DIR)/libtao_os.a $(BUILDDIR)/kernel.o
clean:
rm -rf build
cargo clean