-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
57 lines (43 loc) · 954 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
45
46
47
48
49
50
51
52
53
54
55
56
57
CC=gcc
LD=ld
NASM=nasm
RM=rm
DD=dd
OBJCOPY=objcopy
QEMU=qemu-system-x86_64
CFLAGS=-g -c -m64 -masm=intel -ffreestanding
LFLAGS=-melf_x86_64 -n -Ttext=0x1000
QEMUFLAGS=-fda
OBJS=\
loader.o \
main.o \
vga.o \
io.o \
string.o
ELFS=kernel.elf
BINS=mbr.bin kernel.bin
TARGET=jos.img
mbr.bin: src/boot/mbr.asm
$(NASM) -f bin -o $@ $<
loader.o: src/boot/loader.asm
$(NASM) -f elf64 -o $@ $<
main.o: src/kernel/main.c
$(CC) $(CFLAGS) -o $@ $<
vga.o: src/kernel/vga.c
$(CC) $(CFLAGS) -o $@ $<
io.o: src/kernel/io.c
$(CC) $(CFLAGS) -o $@ $<
string.o: src/kernel/string.c
$(CC) $(CFLAGS) -o $@ $<
kernel.elf: $(OBJS)
$(LD) $(LFLAGS) -o $@ $^
kernel.bin: $(ELFS)
$(OBJCOPY) -O binary $^ $@
$(TARGET): $(BINS)
$(DD) if=/dev/zero of=$@ bs=512 count=2880
$(DD) if=mbr.bin of=$@ bs=512 conv=notrunc
$(DD) if=kernel.bin of=$@ bs=512 seek=1 conv=notrunc
run: $(TARGET)
$(QEMU) $(QEMUFLAGS) $<
clean:
$(RM) $(OBJS) $(ELFS) $(BINS) $(TARGET)