-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathMakefile
54 lines (40 loc) · 1.26 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
# $@ = target file
# $< = first dependency
# $^ = all dependencies
# detect all .o files based on their .c source
C_SOURCES = $(wildcard kernel/*.c drivers/*.c cpu/*.c)
HEADERS = $(wildcard kernel/*.h drivers/*.h cpu/*.h)
OBJ_FILES = ${C_SOURCES:.c=.o cpu/interrupt.o}
CC ?= x86_64-elf-gcc
LD ?= x86_64-elf-ld
# First rule is the one executed when no parameters are fed to the Makefile
all: run
# Notice how dependencies are built as needed
kernel.bin: boot/kernel_entry.o ${OBJ_FILES}
$(LD) -m elf_i386 -o $@ -Ttext 0x1000 $^ --oformat binary
os-image.bin: boot/mbr.bin kernel.bin
cat $^ > $@
run: os-image.bin
qemu-system-i386 -fda $<
echo: os-image.bin
xxd $<
# only for debug
kernel.elf: boot/kernel_entry.o ${OBJ_FILES}
$(LD) -m elf_i386 -o $@ -Ttext 0x1000 $^
debug: os-image.bin kernel.elf
qemu-system-i386 -s -S -fda os-image.bin -d guest_errors,int &
i386-elf-gdb -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
%.o: %.c ${HEADERS}
$(CC) -g -m32 -ffreestanding -fno-pie -fno-stack-protector -c $< -o $@ # -g for debugging
%.o: %.asm
nasm $< -f elf -o $@
%.bin: %.asm
nasm $< -f bin -o $@
%.dis: %.bin
ndisasm -b 32 $< > $@
clean:
$(RM) *.bin *.o *.dis *.elf
$(RM) kernel/*.o
$(RM) boot/*.o boot/*.bin
$(RM) drivers/*.o
$(RM) cpu/*.o