-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
72 lines (57 loc) · 2.35 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
CC = clang
CXX = clang++
ASM = nasm
LD = ld
SRC_DIR = src
DATA_DIR = data
BUILD_DIR = bin
ARCH = $(shell $(CC) -dumpmachine | cut -f1 -d-)
OUTPUT = $(BUILD_DIR)/kernel.elf
BOOTLOADER = gnu-efi/$(ARCH)/bootloader/main.efi
ASMFLAGS = -f elf64
CFLAGS = -m64 -c -O2 -Wall -Wextra -ffreestanding -fshort-wchar -mno-red-zone -fno-exceptions -fno-rtti
LDFLAGS = -m elf_$(ARCH) -T $(DATA_DIR)/linker.ld -Bsymbolic -nostdlib
QEMUFLAGS = -m 256M -cpu qemu64 -drive if=pflash,format=raw,unit=0,file="$(DATA_DIR)/OVMF_CODE.fd",readonly=on \
-drive if=pflash,format=raw,unit=1,file="$(DATA_DIR)/OVMF_VARS.fd",readonly=on -net none
ASM_SOURCES = $(wildcard $(SRC_DIR)/asm/*.asm)
C_SOURCES = $(wildcard $(SRC_DIR)/*.c)
CPP_SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
FONTS = $(wildcard $(SRC_DIR)/lib/*.psf)
ASM_OBJECTS = $(patsubst $(SRC_DIR)/asm/%.asm,$(BUILD_DIR)/asm_%.o,$(ASM_SOURCES))
C_OBJECTS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/c_%.o,$(C_SOURCES))
CPP_OBJECTS = $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/cpp_%.o,$(CPP_SOURCES))
.PHONY: all bootloader build iso clean super-clean
all: bootloader $(OUTPUT) build iso
bootloader:
mkdir -p $(BUILD_DIR)
cd gnu-efi && $(MAKE) all bootloader && cd ..
build: $(OUTPUT)
dd if=/dev/zero of=$(BUILD_DIR)/os.img bs=512 count=93750
mformat -i $(BUILD_DIR)/os.img -f 1440 ::
mmd -i $(BUILD_DIR)/os.img ::/EFI
mmd -i $(BUILD_DIR)/os.img ::/EFI/BOOT
mcopy -i $(BUILD_DIR)/os.img $(BOOTLOADER) ::/EFI/BOOT/BOOT.EFI
mcopy -i $(BUILD_DIR)/os.img $(OUTPUT) ::
mcopy -i $(BUILD_DIR)/os.img $(DATA_DIR)/startup.nsh ::
mcopy -i $(BUILD_DIR)/os.img $(FONTS) ::
qemu-system-$(ARCH) $(QEMUFLAGS) -drive format=raw,file=$(BUILD_DIR)/os.img
iso: $(OUTPUT)
mkdir -p $(BUILD_DIR)/iso/EFI/BOOT
cp $(BOOTLOADER) $(BUILD_DIR)/iso/EFI/BOOT/BOOTX64.EFI
cp $(OUTPUT) $(BUILD_DIR)/iso/kernel.elf
cp $(DATA_DIR)/startup.nsh $(BUILD_DIR)/iso/startup.nsh
cp $(FONTS) $(BUILD_DIR)/iso/
grub-mkrescue -o $(BUILD_DIR)/os.iso $(BUILD_DIR)/iso
$(BUILD_DIR)/asm_%.o: $(SRC_DIR)/asm/%.asm
$(ASM) $(ASMFLAGS) $< -o $@
$(BUILD_DIR)/c_%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) $< -o $@
$(BUILD_DIR)/cpp_%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CFLAGS) $< -o $@
$(BUILD_DIR)/kernel.elf: $(ASM_OBJECTS) $(C_OBJECTS) $(CPP_OBJECTS)
$(LD) $(LDFLAGS) $^ -o $@
clean:
rm -rf $(BUILD_DIR) $(BOOTLOADER)
super-clean:
rm -rf $(BUILD_DIR)
cd gnu-efi && $(MAKE) clean && cd ..