summaryrefslogtreecommitdiff
path: root/Makefile
blob: af294e81f711ea86ea81f142119e7efdb6c20737 (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
56
57
export

ARCH = x86_64-elf-
CC = $(ARCH)gcc
AS = $(ARCH)as
LD = $(ARCH)ld
OBJDUMP = $(ARCH)objcopy
OBJCOPY = $(ARCH)objdump

W := -Wall -Werror -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align
W += -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations
W += -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wconversion
W += -Wstrict-prototypes
WNO := -Wno-error=unused-parameter -Wno-error=unused-variable
WNO += -Wno-error=infinite-recursion

CFLAGS = $(W) $(WNO) -fno-omit-frame-pointer -mcmodel=large
CFLAGS += -mgeneral-regs-only # disables SIMD instructions
CFLAGS += -MD -O3 -ffreestanding -nostdlib
CFLAGS += -fno-common -fno-stack-protector
CFLAGS += -fno-pie -no-pie -fno-pic
LDFLAGS = -z max-page-size=4096

MAKE:=$(MAKE) -s

K = kernel

all: kernel.iso

$K/kernel.bin: FORCE
	@$(MAKE) -C $(@D)
FORCE:

kernel.iso: $K/kernel.bin $K/src/grub.cfg Makefile
	$(info [all] $@)
	@mkdir -p isodir/boot/grub
	@cp $K/kernel.bin isodir/boot/kernel.bin
	@cp $K/src/grub.cfg isodir/boot/grub/grub.cfg
	@grub-mkrescue -o kernel.iso isodir 2> /dev/null


.PHONY: all build qemu bochs clean

QEMU = qemu-system-x86_64
BOCHS = bochs -q

qemu: kernel.iso
	$(QEMU) -cdrom kernel.iso

bochs: kernel.iso
	$(BOCHS) -qf .bochsrc

clean:
	@find -name "*.o" -exec rm {} \;
	@find -name "*.d" -exec rm {} \;
	@rm -f kernel.iso $K/kernel.bin xbochs.log bx_enh_dbg.ini
	@rm -rf isodir