TARGET = main

CC = g++

.SUFFIXES: .cpp .o .vsm

OBJS = main.o ctexture.o sps2wrap.o vu1code.o 

LIBS = -lm -lsps2util

CFLAGS = -g -Wall -Werror -ffast-math -fsingle-precision-constant

$(TARGET): $(OBJS)
	$(CC) -o $@ $(OBJS) $(LIBS)

.cpp.o:
	$(CC) -c $< $(CFLAGS) -o $@

# Rule for compiling .vsm -> .o	
.vsm.o:
		# Compile to object format
	ee-dvp-as -o $*.vo_ $*.vsm
		# Generate raw binary file (discards all symbols)
	objcopy -Obinary $*.vo_ $*.bin_
		# Convert to a format that as can assemble
	./bin2as $* $*.bin_ > $*.a_
		# Assemble to an object format that gcc/g++ can link
	as -mcpu=r5900 -KPIC -mips2 -o $*.o $*.a_
		# Remove all temporary files
	rm $*.vo_ $*.bin_ $*.a_

*.vsm: bin2as
bin2as:  bin2as.cpp
	cc -o bin2as bin2as.cpp

# create the dependancy file	
depend:
	$(CC) $(CFLAGS) -MM *.cpp > .depend

clean:
	rm -f $(TARGET)
	rm -f $(OBJS)
	rm -f .depend

#include the dependencies into the build
-include .depend