-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
50 lines (39 loc) · 1.38 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
C_SOURCES = $(shell find . -name "*.c")
OBJ_FILES = ${C_SOURCES:.c=.o \
arch/i386/boot/entry.o \
arch/i386/asm/dt.o \
arch/i386/asm/int.o \
arch/i386/asm/page.o \
fonts/console.o \
}
CCFLAGS = -I ./include -I ./arch/i386/include -g -m32 -ffreestanding -nostdlib -fno-builtin -fno-stack-protector -no-pie -fno-pic -Wall -Wextra -O3
KERNELBIN = ./build/kernel.bin
ISO_ROOT = ./build/iso-root
ISO = ./build/out/os-image.iso
build: prepare $(ISO)
prepare:
@mkdir -p ./build/out ./build/iso-root ./build/obj
kernel.bin: ${OBJ_FILES}
ld -m elf_i386 -o ./build/$(notdir $@) -Tlinker.ld ./build/obj/entry.o $(shell find ./build/obj/ -name "*.o" ! -name "entry.o")
$(ISO_ROOT)/boot/grub/grub.cfg:
@mkdir -p $(dir $@)
echo 'set timeout=5' > $@
echo 'set default=0' >> $@
echo '' >> $@
echo 'menuentry "Os" {' >> $@
echo ' multiboot /boot/kernel.bin' >> $@
echo ' boot' >> $@
echo '}' >> $@
$(ISO_ROOT)/boot/kernel.bin: kernel.bin
@mkdir -p $(dir $@)
cp $(KERNELBIN) $@
$(ISO): $(ISO_ROOT)/boot/grub/grub.cfg $(ISO_ROOT)/boot/kernel.bin
grub-mkrescue -o $(ISO) $(ISO_ROOT)
%.o: %.c
$(CC) $(CCFLAGS) -c $< -o ./build/obj/$(notdir $@)
%.o: %.asm
nasm $< -f elf -o ./build/obj/$(notdir $@)
%.o: %.sfn
cd fonts && objcopy -O elf32-i386 -B i386 -I binary console.sfn console.o && mv console.o ../build/obj/console.o
clean:
$(RM) -r ./build