-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
58 lines (46 loc) · 1.48 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
C_SOURCES = $(wildcard src/kernel/*.c src/drivers/*.c src/utils/*.c)
IDT_C_SOURCES = $(wildcard src/idt/*.c)
ASM_SOURCES = $(wildcard src/kernel/*.asm)
C_OBJ = $(patsubst src/%.c, build/%.o, $(C_SOURCES))
ASM_OBJ = $(patsubst src/%.asm, build/%.o, $(ASM_SOURCES))
IDT_C_OBJ = $(patsubst src/%.c, build/%.o, $(IDT_C_SOURCES))
.PHONY: build-os-image
build-os-image: clear build-docker-image
mkdir -p build
docker run -v ./build:/output builder
.PHONY: build-docker-image
build-docker-image:
docker build -t builder .
.PHONY: build
build: prepare-dirs os-image
.PHONY: os-image
os-image: build/boot.bin build/kernel.bin
cat $^ > build/os-image
.PHONY: build/boot.bin
build/boot.bin:
nasm src/boot/boot.asm -i src/boot -f bin -o build/boot.bin
.PHONY: build/kernel.bin
build/kernel.bin: build/kernel_entry.o ${C_OBJ} ${ASM_OBJ} ${IDT_C_OBJ}
ld -m elf_i386 -o $@ -Ttext 0x1000 $^ --oformat binary
.PHONY: build/%.o
build/%.o : src/%.c
gcc -m32 -fno-pie -ffreestanding -Isrc -c $< -o $@
.PHONY: build/idt/idt.o
build/idt/idt.o: src/idt/idt.c
gcc -m32 -fno-pie -ffreestanding -mgeneral-regs-only -Isrc -c src/idt/idt.c -o build/idt/idt.o
.PHONY: build/%.o
build/%.o : src/%.asm
nasm $< -f elf32 -o $@
.PHONY: build/kernel_entry.o
build/kernel_entry.o:
nasm src/boot/kernel_entry.asm -f elf32 -o build/kernel_entry.o
.PHONY: clear
clear:
rm -rf build/*
.PHONY: prepare-dirs
prepare-dirs:
mkdir -p build/boot
mkdir -p build/kernel
mkdir -p build/drivers
mkdir -p build/utils
mkdir -p build/idt