-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
81 lines (58 loc) · 2.05 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
NASM=nasm
NASM_FLAGS=-f elf64
LD=ld
LD_FLAGS=--nmagic --script=$(LINKER)
CC=gcc
CFLAGS=-Wall -c -ggdb -ffreestanding -mgeneral-regs-only
GRUB=grub-mkrescue
GRUB_FLAGS=-o
LINKER=x86_64/boot/linker.ld
ISO_DIR=isofiles
ISO_BOOT_DIR := $(ISO_DIR)/boot
BUILD_DIR=build
x86_64_asm_source_files := $(shell find x86_64 -name *.asm)
x86_64_asm_object_files := $(patsubst x86_64/%.asm, build/x86_64/%.o, $(x86_64_asm_source_files))
kernel_source_files := $(shell find kernel -name *.c)
kernel_object_files := $(patsubst kernel/%.c, build/kernel/%.o, $(kernel_source_files))
kernel_asm_source_files := $(shell find kernel -name *.asm)
kernel_asm_object_files := $(patsubst kernel/%.asm, build/kernel/%.o, $(kernel_asm_source_files))
object_files := $(x86_64_asm_object_files) $(kernel_object_files) $(kernel_asm_object_files)
build/%.o: %.asm
mkdir -p $(dir $@) && \
$(NASM) $(NASM_FLAGS) $< -o $@
build/%.o: %.c
mkdir -p $(dir $@) && \
$(CC) $(CFLAGS) $< -o $@
$(ISO_BOOT_DIR)/kernel.bin: $(object_files)
$(LD) $(LD_FLAGS) --output=$@ $^
$(ISO_DIR)/kernel.iso: $(ISO_BOOT_DIR)/kernel.bin
$(GRUB) $(GRUB_FLAGS) $@ $(ISO_DIR)
build_kernel: $(ISO_BOOT_DIR)/kernel.bin
build_iso: $(ISO_DIR)/kernel.iso
QEMU=qemu-system-x86_64
QEMU_FLAGS=-m 128M -cdrom
# try to generate a unique GDB port
GDBPORT = $(shell expr `id -u` % 5000 + 25000)
# QEMU's gdb stub command line changed in 0.11
QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
then echo "-gdb tcp::$(GDBPORT)"; \
else echo "-s -p $(GDBPORT)"; fi)
# -s -S -kernel
# tap adapter
qemu: $(ISO_DIR)/kernel.iso
$(QEMU) \
$(QEMU_FLAGS) \
$(ISO_DIR)/kernel.iso
.gdbinit: .gdbinit.tmpl
sed "s/:1234/:$(GDBPORT)/" < $^ > $@
qemu-gdb: $(ISO_DIR)/kernel.iso .gdbinit
@echo "*** Now run 'gdb' in another window." 1>&2
$(QEMU) $(QEMU_FLAGS) $(ISO_DIR)/kernel.iso -S $(QEMUGDB)
clean:
rm -rf $(BUILD_DIR)
rm -f $(ISO_DIR)/kernel.*
rm -f $(ISO_DIR)/**/kernel.*
install:
apt install xorriso
apt install mtools
apt install qemu-system-x86