##############################################################
#  Makefile for LD #11 - Minimalist
#  
#  usage:  	make  			- create binaries and oracleseye
#  		make docs	 	- create documentation files
#  		make all		- create binaries and docs
#  		make clean		- delete binaries
#  		make veryclean		- delete binaries and docs
# 
##############################################################

LIB_INSTALL_DIR := ${CURRENT_BUILD_DIR}/lib

DEBUG 		:= YES

DEBUG_CFLAGS 	:= -fno-stack-protector -Wall -Wno-unknown-pragmas -Wno-format -g -DDEBUG $(shell ${LIB_INSTALL_DIR}/bin/sdl-config --cflags) 
RELEASE_CFLAGS	:= -fno-stack-protector -Wall -Wno-unknown-pragmas -Wno-format -O2 $(shell ${LIB_INSTALL_DIR}/bin/sdl-config --cflags) 
CFLAGS       := ${RELEASE_CFLAGS}
ifeq (YES, ${DEBUG})
   CFLAGS       := ${DEBUG_CFLAGS}
endif

LIBS		:=  -static-libgcc -L. -L${LIB_INSTALL_DIR}/lib $(shell ${LIB_INSTALL_DIR}/bin/sdl-config --libs) -lSDL_image -lSDL_mixer #-L/usr/X11R6/lib -lX11

OBJS= main.o game.o inputsystem.o   \
	tinystr.o tinyxmlerror.o tinyxmlparser.o tinyxml.o 
	#entity.o point.o 

CC=g++

PROJNAME	:= ld11-minimalist.bin

# NOTE: 'all' doesn't build docs because it would be annoying to have the docs
#  built each time you recompile.
			
all:	$(PROJNAME)
	${MAKE} ${PROJNAME}

${PROJNAME}: libstdc++.a $(OBJS)
	@echo "********"
	@echo "Linking files together"
	@echo "********"
	$(CC) $(OBJS) ${LIBS} -o ${PROJNAME}

libstdc++.a: 
	ln -s `$(CC) -print-file-name=libstdc++.a`

main.o: main.cpp 
	@echo "------------------------------------------COMPILING MAIN"
	$(CC) -c main.cpp ${CFLAGS} 

%.o: %.cpp %.h
	@echo "------------------------------------------COMPILING $@"
	$(CC) -c $< ${CFLAGS} 
docs:
	doxygen Doxyfile

resources:
	@echo "Nothing to do yet for resources."

clean: 
	rm -f ${PROJNAME} $(OBJS) 
	rm -f libstdc++.a

veryclean:
	rm -f ${PROJNAME} $(OBJS) 
	rm -f ${CURRENT_BUILD_DIR}/documentation/html/*
	rm -rf ${LIB_INSTALL_DIR}/*
	for i in $(BUILD_SUBDIRS); do ( cd $$i ; ${MAKE} clean ) ; done
