# defines
.SUFFIXES: .x .asm
MAKEFILE=makefile

# uncomment the next line to rebuild everything if makefile changes
#MAKEDEP=$(MAKEFILE)

# chose ELF, COFF, or PE in the next line
LSCRIPT	=../ldscript/coffuser.ld

INCDIR	=../inc
AFLAGS	=-f coff -dUNDERBARS=1 -i $(INCDIR)/
CFLAGS	=-g -Wall -W -O2 -I$(INCDIR) -fno-builtin -nostdinc
LFLAGS	=-g -T$(LSCRIPT)
LIBS	=../tinylib/libc.a

# targets
all:	hello.x protect.x time.x echo.x tetris.x invade.x

clean:
	deltree /y *.o *.x *.sym *.lst

# implicit rules
.c.o:
	gcc $(CFLAGS) -c -o$@ $<

.asm.o:
	nasm $(AFLAGS) -o$@ $<

.o.x:
	ld $(LFLAGS) -o $@ ustart.o $< $(LIBS)
	objdump --line-numbers --source $@ >x
	move /y x $*.lst
	nm --line-numbers $@ | sort >x
	move /y x $*.sym
	strip $@

# dependencies
ustart.o: ustart.asm $(MAKEDEP)

hello.o: hello.c $(LIBS) $(LSCRIPT) $(MAKEDEP)

protect.o: protect.c $(LIBS) $(LSCRIPT) $(MAKEDEP)

time.o: time.c $(LIBS) $(LSCRIPT) $(MAKEDEP)

echo.o: echo.c $(LIBS) $(LSCRIPT) $(MAKEDEP)

tetris.o: tetris.c $(LIBS) $(LSCRIPT) $(MAKEDEP)

invade.o: invade.c $(LIBS) $(LSCRIPT) $(MAKEDEP)

hello.x: ustart.o hello.o $(LIBS) $(LSCRIPT) $(MAKEDEP)

protect.x: ustart.o protect.o $(LIBS) $(LSCRIPT) $(MAKEDEP)

time.x: ustart.o time.o $(LIBS) $(LSCRIPT) $(MAKEDEP)

echo.x: ustart.o echo.o $(LIBS) $(LSCRIPT) $(MAKEDEP)

tetris.x: ustart.o tetris.o $(LIBS) $(LSCRIPT) $(MAKEDEP)
