-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (39 loc) · 1.09 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
C_SOURCES = $(wildcard kernel/*.c drivers/*.c cpu/*.c)
ASM_SOURCES = $(wildcard kernel/*.asm cpu/*.asm)
HEADERS = $(wildcard kernel/*.h drivers/*.h cpu/*.h)
OBJ = ${ASM_SOURCES:.asm=.o} ${C_SOURCES:.c=.o}
BUILD := build
ifdef OS
SYSTEM = win32
COMPILE = type
DELETE = del /S /Q
PATH_KERNEL = $(BUILD)\kernel.bin
PATH_BOOT = $(BUILD)\boot_sector.bin
PATH_OUTPUT = $(BUILD)\$@
else
SYSTEM = elf
COMPILE = cat
DELETE = rm
PATH_KERNEL = $(BUILD)/kernel.bin
PATH_BOOT = $(BUILD)/boot_sector.bin
PATH_OUTPUT = $(BUILD)/$@
endif
all: os_image.img
run: all
qemu-system-x86_64 -drive format=raw,file=$(BUILD)/os_image.img,index=0,if=floppy
os_image.img: boot_sector.bin kernel.bin
$(COMPILE) $(PATH_BOOT) $(PATH_KERNEL) > $(PATH_OUTPUT)
kernel.bin: ${OBJ}
ld -mi386pe -T link.ld -o kernel.tmp $^
objcopy -O binary kernel.tmp $(BUILD)/$@
%.o : %.c ${HEADERS}
gcc -fno-pic -g -m32 -ffreestanding -mno-ms-bitfields -c $< -o $@
%.o : %.asm
nasm $< -f $(SYSTEM) -o $@
%.bin: boot/%.asm ${BUILD}
nasm $< -f bin -i 'boot/' -o $(BUILD)/$@
${BUILD}:
mkdir build
clean:
$(DELETE) *.o *.tmp *.bin
rmdir /S /Q build