-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (46 loc) · 1.57 KB
/
Makefile
File metadata and controls
64 lines (46 loc) · 1.57 KB
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
55
56
57
58
59
60
61
62
63
64
# $@ = target file
# $< = first dependency
# $^ = all dependencies
# detect all .o files based on their .c source
C_SOURCES = $(wildcard kernel/*.c drivers/*.c cpu/*.c stdlib/*.c)
HEADERS = $(wildcard kernel/*.h drivers/*.h cpu/*.h stdlib/*.h)
OBJ_FILES = ${C_SOURCES:.c=.o cpu/isr_keyboard.o cpu/kernel_entry.o cpu/gdt.o cpu/exception_isr.o cpu/isr_pit.o cpu/switch_task.o cpu/syscall_isr.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
run: iso
qemu-system-i386 -cdrom kernelx.iso -drive file=disk.img,format=raw,if=ide,index=0,media=disk -m 512M -boot d
# only for debug
kernel.elf: ${OBJ_FILES}
$(LD) -m elf_i386 -T link.ld -o $@ $^
cp kernel.elf iso/boot/kernel.elf
iso: kernel.elf
grub-mkrescue -o kernelx.iso iso/
debug: iso
qemu-system-i386 -cdrom kernelx.iso -drive file=disk.img,format=raw,if=ide,index=0,media=disk -m 512M -boot d -S -s -d guest_errors,int
run_gdb: iso
gdb-multiarch -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
run_bochs: iso
bochs -f bochsrc
%.o: %.c ${HEADERS}
$(CC) -g -m32 -ffreestanding -fno-pie -fno-stack-protector -O1 -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
$(RM) stdlib/*.o
$(RM) iso/boot/*.elf
$(RM) kernelx.iso
format:
find . -regex '.*\.\(c\|h\)$$' -exec clang-format -i {} \;
disk_img:
qemu-img create -f raw disk.img 64M