-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (66 loc) · 1.98 KB
/
Copy pathMakefile
File metadata and controls
89 lines (66 loc) · 1.98 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
CC ?= gcc
LD ?= ld
AR ?= ar
NASM ?= nasm
ifeq ($(shell uname -s),Linux)
CC = ./toolchain/x86_64/bin/x86_64-elf-gcc
LD = ./toolchain/x86_64/bin/x86_64-elf-ld
AR = ./toolchain/x86_64/bin/x86_64-elf-ar
endif
OS_NAME = bolt
BUILD_DIR = build
LINKER = linker.ld
ISO_DIR = $(BUILD_DIR)/isofiles
KERNEL_DIR = $(ISO_DIR)/boot
GRUB_DIR = $(KERNEL_DIR)/grub
KERNEL = $(KERNEL_DIR)/kernel.bin
ISO = $(BUILD_DIR)/$(OS_NAME).iso
LIB = $(BUILD_DIR)/lib$(OS_NAME).a
OBJECTS := $(patsubst %.asm,%.o,$(shell find asm -name '*.asm'))
SOURCES := $(patsubst %.c,%.o,$(shell find src -name '*.c'))
CFLAGS = -W -Wall -pedantic -std=c11 -O2 -ffreestanding -nostdlib \
-mno-red-zone -Isrc/include/ -Isrc/ -fno-builtin -fno-stack-protector
default: iso
kernel: $(KERNEL)
.PHONY: kernel
$(KERNEL): $(OBJECTS) $(LIB)
@mkdir -p $(KERNEL_DIR)
@$(LD) --nmagic --output=$@ --script=$(LINKER) $(OBJECTS) $(LIB)
@echo "[LD] $@"
$(OBJECTS): %.o: %.asm
@mkdir -p $(BUILD_DIR)
@$(NASM) -f elf64 $<
@echo "[AS] $<"
$(SOURCES): %.o: %.c
@$(CC) $(CFLAGS) -c $< -o $@
@echo "[CC] $<"
$(LIB): $(SOURCES)
@$(AR) rcs $@ $^
@echo "[AR] $@"
iso: $(ISO)
.PHONY: iso
$(ISO): $(KERNEL)
@mkdir -p $(GRUB_DIR)
@cp -R grub/* $(GRUB_DIR)
grub-mkrescue -o $@ $(ISO_DIR)
run: $(ISO)
qemu-system-x86_64 -cdrom $<
.PHONY: run
debug: CFLAGS += -DENABLE_KERNEL_DEBUG
debug: $(ISO)
qemu-system-x86_64 -cdrom $< -chardev stdio,id=char0,logfile=/tmp/serial.log,signal=off -serial chardev:char0
.PHONY: debug
toolchain:
@-mkdir toolchain/x86_64
@-[ ! -f toolchain/x86_64-elf-tools-linux.zip ] && wget https://github.com/lordmilko/i686-elf-tools/releases/download/7.1.0/x86_64-elf-tools-linux.zip -P toolchain
@echo "Unzipping toolchain"
@unzip -qq toolchain/x86_64-elf-tools-linux -d toolchain/x86_64
@echo "Unzipped toolchain"
.PHONY: toolchain
clean_toolchain:
rm -rf toolchain/x86_64/
.PHONY: clean_toolchain
clean:
rm -f $(OBJECTS) $(SOURCES) $(KERNEL) $(ISO) $(LIB)
rm -rf $(BUILD_DIR)
.PHONY: clean