##
# Makefile for Unix
#
CC  = arm-elf-gcc
LD  = arm-elf-g++
AS  = arm-elf-as
AR  = arm-elf-ar
CXX = arm-elf-g++

PRG = simple
#PRG2 = shapes
PRG3 = glxgears
PRG4 = texture
PRG8 = torus

LIBS = -L/home/gusarba/GP32/devel/gp32_SDK/lib -L../../bin -lm -lgcc -lc -lstdc++ -lKlimt -lmirkoSDK \
       -L/opt/gp-arm-elf/lib/gcc/arm-elf/3.4.1/ -L/opt/gp-arm-elf/arm-elf/lib/ -L/opt/gp-arm-elf/lib/
       #-L/usr/arm-elf/lib \
       #-L/usr/lib/gcc/arm-elf/3.4.0/ -lKlimt -lmirkoSDK -lgcc -lc -lstdc++ -lm
       #-L/usr/lib/gcc/arm-elf/3.4.0/ -lKlimt -lm -lmirkoSDK -lgcc -lstdc++ -lc

INCLUDES = -I/home/gusarba/GP32/devel/gp32_SDK/lib.src/include -I../../klimt/include

#CXXFLAGS = $(INCLUDES) -g -Wall -pipe -fPIC -funroll-all-loops -O2 -s -w -mtune=arm9tdmi -DGP32
CFLAGS = $(INCLUDES) -Wall -DGP32 -s -march=armv4t -marm -msoft-float -ffast-math \
		       -fshort-enums -mstructure-size-boundary=8 -O2

CXXFLAGS = $(CFLAGS) -fno-implicit-templates

#OBJS = simple.o shapes.o glxgears.o modfile1.o texture.o torus.o
OBJS = simple.o glxgears.o modfile1.o texture.o torus.o

all:	$(OBJS)
	$(CC) -c -o crt0.o crt0.S
	$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map -T lnkscript crt0.o -o $(PRG).elf simple.o $(LIBS)
	#$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map -T lnkscript crt0.o -o $(PRG2).elf shapes.o $(LIBS)
	$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map -T lnkscript crt0.o -o $(PRG3).elf glxgears.o $(LIBS)
	$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map -T lnkscript crt0.o -o $(PRG4).elf modfile1.o texture.o $(LIBS)
	$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map -T lnkscript crt0.o -o $(PRG8).elf $(PRG8).o $(LIBS)
	arm-elf-objcopy -O binary $(PRG).elf $(PRG).bin
	#arm-elf-objcopy -O binary $(PRG2).elf $(PRG2).bin
	arm-elf-objcopy -O binary $(PRG3).elf $(PRG3).bin
	arm-elf-objcopy -O binary $(PRG4).elf $(PRG4).bin
	arm-elf-objcopy -O binary $(PRG8).elf $(PRG8).bin
	b2fxec -a maulo -t KLCUBE $(PRG).bin $(PRG).fxe
	#b2fxec -a maulo -t SHAPES $(PRG2).bin $(PRG2).fxe
	b2fxec -a maulo -t GLXGEARS $(PRG3).bin $(PRG3).fxe
	b2fxec -a maulo -t TEXTURE $(PRG4).bin $(PRG4).fxe
	b2fxec -a maulo -t TORUS $(PRG8).bin $(PRG8).fxe

clean:
	rm -f Test.map *.o simple.fxe shapes.fxe glxgears.fxe texture.fxe torus.fxe *.bin *.elf 

