Newer
Older
tree-os / Makefile
@lukas lukas on 2 Apr 2021 1018 bytes cleanup
CC = i686-elf-gcc
CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/kernel
LD = i686-elf-ld
AS = nasm
ASFlAGS = -felf32
GENISO = genisoimage
GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os
EMU = qemu-system-x86_64
EMUFLAGS = -m 256M -cdrom

BUILD_FOLDER = build

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

default: run

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

tree-os.iso: iso/boot/tree-os.elf
	$(GENISO) $(GENISOFLAGS) -o $@ iso

iso/boot/tree-os.elf: linker.ld $(OBJS)
	$(LD) -T linker.ld -o $@ $(OBJS)

$(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) tree-os.iso iso/boot/tree-os.elf

cleanELF:
	rm iso/boot/tree-os.elf