summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 2f761c9a77716dbdfe79e14da9759aef55395e60 (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
OSNAME = mfsos
OSBIN = $(OSNAME).bin
KERNBIN = kernel.bin

ARCH = x86
ARCH_BOOT = arch/$(ARCH)/boot
BOOTBIN = $(ARCH_BOOT)/bootloader.bin

TARGET_TOOLS = $(HOME)/path/to/cross/compiler/i686-elf-
CC = $(TARGET_TOOLS)gcc
export CC
LD = $(TARGET_TOOLS)ld
export LD
AS = $(TARGET_TOOLS)as
export AS
OBJDUMP = $(TARGET_TOOLS)objdump
export OBJDUMP

C_SOURCES = \
	kernel/main.c \
	kernel/string.c \
	drivers/video/console/vgacon.c
OBJECTS = ${C_SOURCES:.c=.o}

.PHONY: all qemu clean

all: $(OSBIN)

$(OSBIN): $(BOOTBIN) $(KERNBIN)
	cat $^ > $@
	dd if=/dev/zero bs=512 count=15 >> $@

$(BOOTBIN):
	$(MAKE) -C $(ARCH_BOOT)

$(KERNBIN): $(ARCH_BOOT)/head.o $(OBJECTS)
	$(CC) -Wl,--oformat binary -Ttext 0x1000 -o $@ \
		-ffreestanding -nostdlib \
		$^ -lgcc

%.o: %.s
	$(AS) $< -o $@

%.o: %.c
	$(CC) -std=gnu89 -Wall -ffreestanding -nostdlib \
		-I arch/$(ARCH)/include \
		-I kernel \
		-I drivers \
		-c $< -o $@ -lgcc

qemu: $(OSBIN)
	qemu-system-i386 -kernel $(OSBIN)

clean:
	$(MAKE) -C $(ARCH_BOOT) clean
	rm -rf $(ARCH_BOOT)/head.o kernel/main.o
	rm -rf $(KERNBIN) $(OSBIN) $(OBJECTS)