-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
47 lines (34 loc) · 944 Bytes
/
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
#Binaries
LD=ld
CC=gcc
ASM=nasm
QEMU=qemu-system-x86_64
#Flags
AFLAGS=-fbin
CFLAGS=-Os -m32 -nostdlib -ffreestanding -fno-pie
LFLAGS=--oformat=binary -m elf_i386
#Directories
SRC=src
BIN=bin
QEMULIB="C:\Program Files\qemu"
CINCLUDE=$(wildcard $(SRC)/kernel/*.h)
COBJ=$(patsubst $(SRC)/kernel/%.c, $(BIN)/%.o, $(wildcard $(SRC)/kernel/*.c))
KENTRY_ADDR=0x9000
run: $(BIN)/os.bin
$(QEMU) -drive format=raw,file=$< -L $(QEMULIB)
os: kernel boot
cat $(BIN)/boot.bin $(BIN)/kernel.bin > $(BIN)/os.bin
qemu-img resize -f raw $(BIN)/os.bin +10M
kernel: $(BIN)/kentry.o $(COBJ)
$(LD) -o $(BIN)/kernel.bin -Ttext $(KENTRY_ADDR) $^ $(LFLAGS)
boot: $(SRC)/bootsec/boot.s
$(ASM) $(AFLAGS) -o $(BIN)/boot.bin $< -I $(SRC)/bootsec/
$(BIN)/kentry.o: $(SRC)/kernel/kernel_entry.s
$(ASM) -felf32 $< -o $@
$(BIN)/%.o: $(SRC)/kernel/%.c $(CINCLUDE)
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: rmbin rmobj
rmbin:
rm $(BIN)/*.bin
rmobj:
rm $(BIN)/*.o