-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
65 lines (52 loc) · 1.58 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
SHELL := /usr/bin/bash
# Recursive wildcard, https://stackoverflow.com/a/18258352/3685882
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
SRC := ./src
OBJ := ./bin/obj
CXX_SRC_FILES := $(call rwildcard,$(SRC),*.cpp)
AS_SRC_FILES := $(call rwildcard,$(SRC),*.s)
CXX_OBJ_FILES := $(patsubst $(SRC)/%.cpp,$(OBJ)/%_cpp.o,$(CXX_SRC_FILES))
AS_OBJ_FILES := $(patsubst $(SRC)/%.s,$(OBJ)/%_s.o,$(AS_SRC_FILES))
CXX := ./toolchain/bin/i686-elf-g++
AS := ./toolchain/bin/i686-elf-as
CXXFLAGS := -ffreestanding -nostdlib -Werror -c -I$(SRC) -fno-exceptions
ASFLAGS := -c
all: run_iso
link: prep $(CXX_OBJ_FILES) $(AS_OBJ_FILES)
$(CXX) \
$(CXX_OBJ_FILES) \
$(AS_OBJ_FILES) \
-o bin/iso/boot/kernel.bin \
-T ./src/Boot/linker.ld \
-e start \
-ffreestanding -nostdlib -fno-exceptions
prep:
rm -rf ./bin
mkdir -p ./bin/obj
mkdir -p ./bin/iso/boot/grub
build_iso: link
# Move our grub config file to the dir for building our iso
cp ./src/Boot/grub.cfg ./bin/iso/boot/grub/grub.cfg
# Create iso
grub-mkrescue \
-o ./bin/kernel.iso \
-p /boot/grub \
./bin/iso
run_img: link
# Launch qemu emulator with pointed at our iso, 1GB RAM
qemu-system-i386 \
-m 64 \
-kernel ./bin/iso/boot/kernel.bin
run_iso: build_iso
# Launch qemu emulator with pointed at our iso, 1GB RAM
qemu-system-i386 \
-m 64 \
-cdrom ./bin/kernel.iso
# Build c++ (*.cpp) files
$(OBJ)/%_cpp.o: $(SRC)/%.cpp
@mkdir -p $$(dirname $@)
$(CXX) $< -o $@ $(CXXFLAGS)
# Build assembly (*.s) files
$(OBJ)/%_s.o: $(SRC)/%.s
@mkdir -p $$(dirname $@)
$(AS) $< -o $@ $(ASFLAGS)