-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
40 lines (30 loc) · 1.14 KB
/
Makefile
File metadata and controls
40 lines (30 loc) · 1.14 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
# Automatically generate lists of sources using wildcards .
C_SOURCES = $(wildcard src/kernel/*.c src/drivers/*.c)
HEADERS = $(wildcard src/kernel/*.h src/drivers/*.h)
# TODO : Make sources dep on all header files .
OBJ = ${C_SOURCES:.c=.o}
# Defaul build target
all: os-image
# Run bochs to simulate booting of our code .
run: all
qemu-system-i386 -drive file=bin/os-image,format=raw,index=0,media=disk
# This is the actual disk image that the computer loads
# which is the combination of our compiled bootsector and kernel
os-image: bin/boot_sect.bin bin/kernel.bin
cat $^ > bin/os-image
# This builds the binary of our kernel from two object files :
# - the kernel_entry , which jumps to main () in our kernel
# - the compiled C kernel
bin/kernel.bin : obj/kernel_entry.o ${OBJ}
ld -o $@ -Ttext 0x1000 $^ --oformat binary
# Generic rule for compiling C code to an object file
# For simplicity , we C files depend on all header files .
obj/%.o : src/*/%.c ${HEADERS}
gcc -ffreestanding -c $< -o $@
# Assemble the kernel_entry .
obj/%.o: src/*/%.asm
nasm $< -f elf64 -o $@
bin/%.bin : src/*/%.asm
nasm $< -f bin -o $@
clean:
rm -fr bin/* *.dis obj/*