CC = /usr/bin/gcc
LD = /usr/bin/ld
DD = /bin/dd
IMAGE = harddisk.img
FLOPPY = /dev/fd0

all: econos bootsector

econos:
	@echo -e "(BUILD) FCOS v0.01"

bootsector:
	@echo "Building bootsector."
	@$(CC) -c boot.s
	@$(LD) -N -s -e init boot.o -o boot.out --oformat binary -Ttext 0x7c00
	@$(DD) if=boot.out of=$(IMAGE) conv=notrunc
	@make clean

bootfloppy:
	@echo "Building boot floppy."
	@$(CC) -c boot.s
	@$(LD) -N -s -e init boot.o -o boot.out --oformat binary -Ttext 0x7c00
	@$(DD) if=/dev/zero of=bootfloppy.img bs=512 count=1
	@$(DD) if=boot.out of=bootfloppy.img conv=notrunc
	@$(DD) if=bootfloppy.img of=$(FLOPPY) bs=512 count=1
	@make clean

clean:
	@find . -regex ".*\.o\|.*~" -print | xargs -r rm
	@find . -name boot.out -print |xargs -r rm
	@find . -name bootfloppy.img -print |xargs -r rm
	@echo "(CLEAN) *.o *~"
