aboutsummaryrefslogtreecommitdiff
path: root/makefile
blob: 82e3bba196c9d94c3d7980118e5c937db307fc4f (plain)
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
# https://www.gnu.org/software/make/manual/html_node/Setting.html
# :=	expanded variable, right-hand side can contain variables
# ?=	only set if it doesn't have a value
# !=	execute a shell script on the right-hand side and assign its result to the left-hand side

TARGET := i686-elf

NASM := nasm
CXX := clang++
CXXFLAGS := -std=c++20 -ffreestanding -nostdinc -fno-exceptions -fno-rtti -Wall -Wextra -O2
INCLUDE := stdlib

OBJ := kernel.o vga.o stdlib/string.o stdlib/stdlib/console.o

# $@ is target
# $< is first dependency
# $^ is all dependencies

default: boot.o $(OBJ)
	ld.lld -T linker.ld -o myos.bin boot.o $(OBJ)

boot.o: boot.asm
	$(NASM) -felf32 -o $@ $^

$(OBJ): %.o : %.cc
	$(CXX) -target $(TARGET) $(CXXFLAGS) -I$(INCLUDE) -c $^ -o $@

iso:
	mkdir -p isodir/boot/grub
	cp myos.bin isodir/boot/myos.bin
	cp grub.cfg isodir/boot/grub/grub.cfg
	grub-mkrescue -o myos.iso isodir

run:
	qemu-system-i386 -kernel myos.bin

clean:
	rm boot.o $(OBJ) myos.bin

clean-iso:
	rm -rf isodir