PROJECT = xa-005-spike
EXEC = $(PROJECT)
CPPC = g++
CC = gcc

# GUI --------------------------------------------------------------------------
# GUI seems to freeze or crash on OSX :(, too close to release now, disabled.
# Comment these if you want to compile on OSX
GUIOPT = -DUSE_GUI `fltk-config --cxxflags`
GUILIB = `fltk-config --ldstaticflags`

# Compile flags ----------------------------------------------------------------
FLAGS = -O2 -s -Wall -DNOFILE
#FLAGS = -Wall -g -DDEVEL -DFILE_USAGE_LOG

# Use for OSX
#FLAGS = -Wall -O2 -DNOFILE

# Detect OS --------------------------------------------------------------------
ifneq ($(strip $(shell $(CC) -v 2>&1 |grep "Linux")),)
	LIB = `sdl-config --libs` -lGL -lGLU -lfmod-3.74 $(GUILIB)
	INC = `sdl-config --cflags` -Iio/loaders/zlib -Iio/loaders/png $(GUIOPT)
endif

ifneq ($(strip $(shell $(CC) -v 2>&1 |grep "Apple")),)
	LIB = -framework Cocoa -framework Carbon -framework OpenGL /usr/lib/libfmod.a -L/sw/lib -lSDL $(GUILIB)
	INC = -Iio/loaders/zlib -Iio/loaders/png -I/sw/include $(GUIOPT)
	OSXMAIN = ds/io/macosx/macosx_sdl.m
endif

# Targets ----------------------------------------------------------------------
OBJECTS = $(patsubst %.cpp,%.o,$(wildcard *.cpp)) \
	$(patsubst handlers/%.cpp,handlers/%.o,$(wildcard handlers/*.cpp)) \
	$(patsubst handlers/utils/%.cpp,handlers/utils/%.o,$(wildcard handlers/utils/*.cpp)) \
	$(patsubst ds/%.cpp,ds/%.o,$(wildcard ds/*.cpp)) \
	$(patsubst ds/utils/%.cpp,ds/utils/%.o,$(wildcard ds/utils/*.cpp)) \
	$(patsubst ds/io/%.cpp,ds/io/%.o,$(wildcard ds/io/*.cpp)) \
	$(patsubst ds/io/loaders/%.cpp,ds/io/loaders/%.o,$(wildcard ds/io/loaders/*.cpp)) 
LIBOBJECTS = $(patsubst ds/io/loaders/zlib/%.c,ds/io/loaders/zlib/%.o,$(wildcard ds/io/loaders/zlib/*.c)) \
	$(patsubst ds/io/loaders/png/%.c,ds/io/loaders/png/%.o,$(wildcard ds/io/loaders/png/*.c))

%.o: %.cpp
	@echo "CC	$?"
	@$(CPPC) $(FLAGS) $(INC) -c $? -o $@
	
%.o: %.c
	@echo "CC	$?"
	@$(CC) $(INC) -O2 -s -c $? -o $@
	
all: $(OBJECTS) $(LIBOBJECTS)
	@echo "LD	$(EXEC)"
	@$(CPPC) $(FLAGS) $(OBJECTS) $(LIBOBJECTS) $(OSXMAIN) -o $(EXEC) $(LIB) $(INC)
	@rm -f $(EXEC)~
	@wc -c $(EXEC)
		
clean:
	@echo "RM	$(OBJECTS) $(LIBOBJECTS)"
	@rm -f $(OBJECTS) $(LIBOBJECTS) &> /dev/null

pclean:
	@echo "RM	$(OBJECTS)"
	@rm -f $(OBJECTS) &> /dev/null
