-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
57 lines (37 loc) · 1.24 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
55
56
57
MAKEFLAGS := --jobs=$(shell nproc)
MAKEFLAGS += --output-sync=target
RESULT=os.bin
QEMU=qemu-system-x86_64
QEMU_FLAGS=-s -boot acd
QEMU_DRIVE_FLAGS=format=raw,index=0,if=floppy
CFLAGS=-c -g -O0 -std=c99 -Wall -Wextra -pedantic -ffreestanding -mno-red-zone
C_SOURCES = $(wildcard kernel/*.c drivers/*.c utils/*.c)
HEADERS = $(wildcard kernel/*.h drivers/*.h utils/*.h)
OBJ=${C_SOURCES:.c=.o}
.PHONY: all clean run dump debug force
all: ${RESULT}
clean:
@$(foreach file, $(wildcard boot/*.bin *.elf */*.o), rm -vf $(file);)
force:
$(MAKE) -B
run: ${RESULT}
${QEMU} ${QEMU_FLAGS} -drive file=$^,${QEMU_DRIVE_FLAGS}
dump: ${RESULT}
xxd -ae $^
debug: ${RESULT} kernel.elf
${QEMU} ${QEMU_FLAGS} -S -drive file=${RESULT},${QEMU_DRIVE_FLAGS} &
${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
${RESULT}: boot/bootsect.bin kernel.bin
cat $^ > $@
kernel.bin: kernel/entry.o ${OBJ}
${CC} -Wl,--oformat=binary -lgcc -nostdlib -Ttext 0x1000 -e 0x1000 -o $@ $^
chmod -x $@
kernel.elf: kernel/entry.o ${OBJ}
${CC} -lgcc -nostdlib -Ttext 0x1000 -e 0x1000 -o $@ $^
chmod -x $@
boot/bootsect.bin: boot/*.asm
nasm boot/bootsect.asm -f bin -Ov -o $@
%.o: %.c ${HEADERS}
${CC} ${CFLAGS} $< -o $@
%.o: %.asm
nasm $< -f elf64 -Ov -o $@