aboutsummaryrefslogtreecommitdiff
path: root/makefile
blob: b1493376d0452ec30fc35c21bd59eab38b575fc3 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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

export TARGET := i686-elf

export AR := llvm-ar
export NASM := nasm
export LD := ld.lld
export CXX := clang++
export CXX_FLAGS := -std=c++20 -ffreestanding \
    -nostdlib -nostdinc -nostdinc++ \
    -fno-exceptions -fno-rtti -Wall -Wextra -O2
CXX_INCLUDE := $(CURDIR)/libk
CXX_OBJ := kernel.o vga.o

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

default: glitch.elf

check-grub: glitch.elf
	grub-file --is-x86-multiboot2 glitch.elf

glitch.elf: boot.o $(CXX_OBJ) libk/libk.a
	$(LD) -T linker.ld -o glitch.elf boot.o $(CXX_OBJ) -Llibk -lk

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

$(CXX_OBJ): %.o : %.cc
	$(CXX) -target $(TARGET) $(CXX_FLAGS) -I$(CXX_INCLUDE) -c $^ -o $@

libk/libk.a:
	$(MAKE) -C libk libk.a

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

run: glitch.elf
	qemu-system-i386 -kernel glitch.elf
run-iso: iso
	qemu-system-i386 -cdrom myos.iso

clean:
	rm boot.o $(CXX_OBJ) glitch.elf
	$(MAKE) -C libk clean

clean-iso:
	rm -rf isodir