PROJECT = xa-004
EXEC = xa-004-bxinvitro
CPPC = g++
CC = gcc

# GUI --------------------------------------------------------------------------
GUIOPT = -DUSE_GUI `fltk-config --cxxflags`
GUILIB = `fltk-config --ldflags`

# Compile flags ----------------------------------------------------------------
FLAGS = -O2 -s -Wall
#FLAGS = -Wall -g -DDEBUG
#-DMOUSEPOS
#FLAGS = -Os -s

# Detect OS --------------------------------------------------------------------
ifneq ($(strip $(shell $(CC) -v 2>&1 |grep "Linux")),)
	LIB = `sdl-config --libs` -lSDL_mixer -lGL -lGLU -lpng $(GUILIB)
	INC = `sdl-config --cflags` $(GUIOPT)
endif

ifneq ($(strip $(shell $(CC) -v 2>&1 |grep "Apple")),)
	LIB = -framework SDL -framework Cocoa -framework OpenGL -lpng -L/sw/lib \
 			-lSDL_mixer $(GUILIB)
	INC = -I/sw/include $(GUIOPT)
	OSXMAIN = ds/macosx_sdl.m
endif

# Targets ----------------------------------------------------------------------
OBJECTS = $(patsubst %.cpp,%.o,$(wildcard *.cpp)) \
	$(patsubst ds/%.cpp,ds/%.o,$(wildcard ds/*.cpp)) \
	$(patsubst tools/%.cpp,tools/%.o,$(wildcard tools/*.cpp)) \
	$(patsubst scene/%.cpp,scene/%.o,$(wildcard scene/*.cpp))

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