CC = gcc
CFLAGS	= -Wall -O2 -c
BOOT = boot
SECOND = second
TEST = test

all :${BOOT} ${SECOND}.bin ${BOOT}.bin
test	:${TEST}.bin

${SECOND}.bin: ${SECOND}.o calc.o
	ld -T ${SECOND}.ls -o $@ ${SECOND}.o calc.o -Map ${SECOND}.map
	#ld -Ttext 0x10000 -o $@ ${SECOND}.o calc.o -Map ${SECOND}.map

${BOOT}: ${BOOT}.o
	ld -T ${BOOT}.ls -o $@ ${BOOT}.o -Map ${BOOT}.map

stage3.bin: stage3.o vga.o
	ld -T stage3.ls -o $@ stage3.o vga.o -Map stage3.map

stage3.o: stage3.S
	${CC} ${CFLAGS} $<

vga.o: vga.c vga.h
	${CC} ${CFLAGS} $<

${SECOND}.o: ${SECOND}.S
	${CC} ${CFLAGS} $<

${BOOT}.o: ${BOOT}.S
	${CC} ${CFLAGS} $<

calc.o: calc.c realmode.h
	${CC} ${CFLAGS} $<

${BOOT}.bin:${BOOT} ${SECOND}.bin stage3.bin
	dd if=/dev/zero of=${BOOT}.bin bs=512 count=2880
	dd if=${BOOT} of=${BOOT}.bin conv=notrunc
	dd if=${SECOND}.bin of=${BOOT}.bin bs=512 seek=1 conv=notrunc
	dd if=stage3.bin of=${BOOT}.bin bs=512 seek=5 conv=notrunc
	cp ${BOOT}.bin /dev/fd2

${TEST}.bin:${SECOND}.bin
	dd if=/dev/zero of=${TEST}.bin bs=512 count=2880
	dd if=${SECOND}.bin of=${TEST}.bin conv=notrunc
#	cp ${TEST}.bin /dev/fd1
	

clean:
	rm -f *.o *.map ${BOOT} ${SECOND}.bin ${SECOND}.o ${SECOND}.map *.bin
