Newer
Older
tree-os / Makefile
@lukas lukas on 29 Jun 2021 982 bytes custom bootloader test
CC = i686-elf-gcc
CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/kernel
LD = i686-elf-ld
LD_FLAGS = -m elf_i386 -nostdlib -T linker.ld -o
AS = nasm
ASFlAGS = -felf32
EMU = qemu-system-x86_64
EMUFLAGS = -no-reboot -m 256M -fda
DD = dd
DD_FLAGS = status=noxfer conv=notrunc

BUILD_FOLDER = build

SOURCE_FILES := $(shell find src/kernel -name *.c -or -name *.asm -or -name *.s)
OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o)

default: run

run: tree-os.flp
	$(EMU) $(EMUFLAGS) $^

tree-os.flp: tree-os.bin
	$(DD) $(DD_FLAGS) if=$< of=$@

tree-os.bin: loader.bin kernel.bin
	cat $^ > $@

kernel.bin: linker.ld $(OBJS)
	$(LD) $(LD_FLAGS) $@ $(OBJS)

loader.bin: src/boot/boot.asm
	$(AS) -f bin -o $@ $<

$(BUILD_FOLDER)/%.asm.o: %.asm
	mkdir -p $(dir $@)
	$(AS) $(ASFlAGS) $< -o $@

$(BUILD_FOLDER)/%.c.o: %.c
	mkdir -p $(dir $@)
	$(CC) $(CCFLAGS) -r $< -o $@

$(BUILD_FOLDER)/%.s.o: %.s
	mkdir -p $(dir $@)
	$(CC) $(CCFLAGS) -r $< -o $@

clean:
	rm -r $(BUILD_FOLDER)