PLATFORM = Linux

ifeq ($(PLATFORM),Linux)
	TARGET_RELEASE = Example.elf
	TARGET_DEBUG = ExampleD.elf
	SYSLIBS = -lglut -lGLU -lGL	
	SYSLPATH = -L/usr/X11R6/lib
endif

ifeq ($(PLATFORM),OSX)
	TARGET_RELEASE = Example
	TARGET_DEBUG = ExampleD
	SYSLIBS = -framework GLUT -framework OpenGL -framework	Foundation -framework AppKit
	SYSLPATH =
endif

ifeq ($(PLATFORM),MinGW)
	TARGET_RELEASE = Example.exe
	TARGET_DEBUG = ExampleD.exe
	SYSLIBS = -lglut32 -lglu32 -lopengl32	
	SYSLPATH = -L../../../../gl
endif

OBJS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))

LIBRARIES = $(EXTRAIVLIBS) -lIvEngine -lIvMath -lIvUtility $(SYSLIBS)
IPATH = -I. -I../../.. -I../../../common/Includes

CC = g++

release: BUILD = Release
release: CFLAGS = -c -O $(IPATH)
release: $(TARGET_RELEASE)

debug: BUILD = Debug
debug: CFLAGS = -c -g $(IPATH)
debug: $(TARGET_DEBUG)

#------------------------------
# set based on build type

OBJSDIR = $(PLATFORM)$(BUILD)
LFLAGS = -L../../../../common/Libs/$(PLATFORM)$(BUILD) $(SYSLPATH)

vpath %.o $(OBJSDIR)

#-------------------------------

$(TARGET_RELEASE): $(OBJS)
	cd $(OBJSDIR) && $(CC) -o ../$(TARGET_RELEASE) $(LFLAGS) $(OBJS) $(LIBRARIES)

$(TARGET_DEBUG): $(OBJS)
	cd $(OBJSDIR) && $(CC) -o ../$(TARGET_DEBUG) $(LFLAGS) $(OBJS) $(LIBRARIES)

$(OBJS): $(OBJSDIR)

.cpp.o: 
	$(CC) $(CFLAGS) -DPLATFORM_$(PLATFORM) $< -o $(OBJSDIR)/$@

$(OBJSDIR):
	-mkdir -p $(OBJSDIR)

#-------------------------------

clean:
	-rm -f $(PLATFORM)Release/$(OBJS)
	-rm -f $(PLATFORM)Debug/$(OBJS)
	-rm -f $(TARGET_RELEASE) 
	-rm -f $(TARGET_DEBUG) 
