-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
44 lines (31 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
C_SOURCES = $(wildcard kernel/*.c wildcard drivers/*.c)
HEADERS = $(wildcard kernel/*.h wildcard drivers/*.h)
OBJ = ${C_SOURCES:.c=.o}
CC = x86_64-elf-gcc
LD = x86_64-elf-ld
GDB = x86_64-elf-gdb
QEMU = qemu-system-x86_64
CFLAGS = -g -Wall -std=gnu99 -ffreestanding
EXEC = os-image
all: ${EXEC}
run: all
${QEMU} -fda ${EXEC}
debug: ${EXEC} kernel.elf
${QEMU} -s -S -fda ${EXEC} &
${GDB} -ex "set architecture i386:x86_64" -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
${EXEC}: boot/boot_sect.bin kernel.bin
cat $^ > ${EXEC}
kernel.bin: kernel/kernel_entry.o ${OBJ}
${LD} -o $@ -Ttext 0x1000 $^ --oformat binary
# for debugging purposes
kernel.elf: kernel/kernel_entry.o ${OBJ}
${LD} -o $@ -Ttext 0x1000 $^
%.o: %.c ${HEADERS}
${CC} ${CFLAGS} -c $< -o $@
%.o: %.asm
nasm $< -f elf64 -o $@
%.bin: %.asm
nasm $< -f bin -I './boot/' -o $@
clean:
rm -fr *.bin *.o ${EXEC} *.elf
rm -fr kernel/*.o boot/*.bin