-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
62 lines (50 loc) · 1.6 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
######
#
# This stuff is all for building the kernel itself
#
######
VERSION := alpha-1
kernel_flags := -nostdinc -Iinclude -fno-stack-protector -m64 -g -DSOS_VERSION='"$(VERSION)"'
arch ?= x86_64
BUILD := build
KERNEL := $(BUILD)/kernel.bin
ISO := $(BUILD)/os.iso
LINKER_SCRIPT := src/asm/$(arch)/linker.ld
GRUB_CFG := src/grub/grub.cfg
SFSDISK := $(BUILD)/sfsdisk
SOURCEDIR := ./src
C_SRC := $(shell find $(SOURCEDIR) -name '*.c')
C_OBJ := $(patsubst ./src/%, $(BUILD)/%, $(C_SRC:%.c=%.o))
ASM_SRC := $(wildcard src/asm/$(arch)/*.asm)
ASM_OBJ := $(patsubst src/asm/$(arch)/%.asm, \
build/asm/$(arch)/%.o, $(ASM_SRC))
qemu: $(ISO) $(SFSDISK)
@qemu-system-x86_64 -m 512M -hda $(ISO) -hdb $(SFSDISK)
bochs: $(ISO)
@bochs -q
debugq: kernel_flags += -DDEBUG
debugq: $(ISO) $(SFSDISK)
@objcopy --only-keep-debug $(KERNEL) $(BUILD)/symbols
@qemu-system-x86_64 -m 265M -d int -no-reboot -hda $(ISO) -hdb $(SFSDISK) -s -S &
@gdb
$(SFSDISK):
dd if=/dev/zero of=$@ bs=200K count=1
$(KERNEL): $(C_OBJ) $(ASM_OBJ)
@ld -n -T $(LINKER_SCRIPT) -o $(KERNEL) $(C_OBJ) $(ASM_OBJ)
@echo ld [objects] -o $(KERNEL)
$(BUILD)/%.o: src/%.c
@mkdir -p $(shell dirname $@)
@gcc $(kernel_flags) -c $< -o $@
@echo gcc -c $<
$(BUILD)/asm/$(arch)/%.o: src/asm/$(arch)/%.asm
@mkdir -p $(shell dirname $@)
@nasm -felf64 $< -o $@
@echo nasm -felf64 $<
$(ISO): $(KERNEL) $(GRUB_CFG)
@mkdir -p build/isofiles/boot/grub
@cp $(KERNEL) build/isofiles/boot/kernel.bin
@cp $(GRUB_CFG) build/isofiles/boot/grub
@grub-mkrescue -d /usr/lib/grub/i386-pc -o $(ISO) build/isofiles 2>/dev/null
@echo grub-mkrescue -o $(ISO)
clean:
rm -rf build