Newer
Older
tree-os / Makefile
CC = i686-elf-gcc
CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0
LD = i686-elf-ld
LD_FLAGS = -z max-page-size=0x1000 -T linker.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 -drive format=raw,file=tree-os.iso -drive format=raw,file=disk.img,id=disk,if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0


BUILD_FOLDER = build

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

run: tree-os.iso
	@echo "starting qemu"
	@$(EMU) $(EMUFLAGS)

tree-os.iso: iso/boot/tree-os.bin
	@echo "creating the iso image"
	@grub-mkrescue -o $@ iso

iso/boot/tree-os.bin: linker.ld $(OBJS)
	@echo "linking"
	@$(LD) $(LD_FLAGS) -o $@ $(OBJS)

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

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

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

clean:
	@echo "clearing build folder"
	@rm -r $(BUILD_FOLDER) tree-os.iso

cleanELF:
	@echo "clearing the elf file"
	@rm iso/boot/tree-os.elf