AS=as
LD=ld
CC=gcc
CPP=gcc -E

all: bootsect head temp ./tools/build image

bootsect: bootsect.o
	$(LD) -Ttext 0x0 -s --oformat binary -o $@ $<

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

bootsect.s: bootsect.S
	$(CPP) -traditional $< -o $@

head: head.o
	$(LD) -Ttext 0x0 -s --oformat binary -o $@ $<

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

head.s: head.S
	$(CPP) -traditional $< -o $@

temp: temp.o main.o
	$(LD) -e stext -Ttext 0x0 -s --oformat binary temp.o main.o -o $@

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

main.o: main.c
	$(CC) -Wall -O -fstrength-reduce -fomit-frame-pointer -c $< -o  $@

temp.s: temp.S
	$(CPP) -traditional $< -o $@

disk: image
	dd if=image of=/dev/fd0 bs=512

image: bootsect head temp
	./tools/build bootsect head temp > image

./tools/build: ./tools/build.c
	$(CC) -o ./tools/build ./tools/build.c

clean:
	rm -f *.o *.s
	rm bootsect
	rm head
	rm temp
	rm ./tools/build
	rm image
