#   Speedhack competition entry
#  Copyright (c) 2005, Miguel A. Gavidia
#  All rights reserved.

#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions
#  are met:

#    * Redistributions of source code must retain the above 
#       copyright notice, this list of conditions and the following 
#       disclaimer.
#    * Redistributions in binary form must reproduce the above 
#       copyright notice, this list of conditions and the following 
#       disclaimer in the documentation and/or other materials 
#       provided with the distribution.
#    * Neither the name of the "THE CHASM" nor the names of its 
#       contributors may be used to endorse or promote products 
#       derived from this software without specific prior written 
#       permission.

#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
#   HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
#   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
#   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
#   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#   IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
#   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
#   DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
#   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
#   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
#   OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
#   ARISING IN ANY WAY OUT OF THE USE OF THIS 
#   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
#   SUCH DAMAGE.

#Compiler and flags
CC=g++
CFLAGS=-O2 -W -Wall -Iinclude -fexpensive-optimizations
LDFLAGS=
LIBFLAGS=`allegro-config --libs`

#Remove
RM=-rm -f

#Demo name and files
EX_NAME=speedhack
EX_SOURCES=src/Alleg_def.cpp src/Main.cpp src/line.cpp src/map.cpp src/object.cpp src/tile.cpp src/editor.cpp src/game.cpp src/player.cpp src/npc.cpp src/item.cpp
EX_OBJECTS=$(subst src, obj,$(EX_SOURCES:.cpp=.o))
EX_DIRS=obj

#Operating System Checks to change certain flags and variables
ifeq "$(findstring Windows, $(shell ver))" "Windows"
LIBFLAGS=-lalleg
EX_NAME=speedhack.exe
EX_DIRS=obj
endif

ifeq "$(findstring linux, $(shell echo $$OSTYPE))" "linux"
LIBFLAGS=`allegro-config --libs`
EX_NAME=speedhack
EX_DIRS=obj
endif

all: demo
	@echo 
	@echo *****************************[Compilation complete]*****************************
	@echo If you desire to run this fullscreen pass the argument "-fs" in the command line
	@echo Done.
	
.PHONY: all clean demo docs-html

clean: removefiles
	@echo Removing unused directories
	-rmdir $(EX_DIRS)
	@echo All clean
	@echo Finished.
	
removefiles:
	@echo Removing object files
	$(RM) $(EX_OBJECTS)
	@echo Removing Demo
	$(RM) $(EX_NAME)
	
demo: demodir $(EX_NAME)

$(EX_NAME): $(EX_SOURCES) $(EX_OBJECTS)
	$(CC) $(CFLAGS) $(LDFLAGS) $(EX_OBJECTS) -o $@ $(LIBFLAGS)
	
obj/%.o: src/%.cpp
	$(CC) $(CFLAGS) -Iinclude -c -ansi $< -o $@

demodir:
	@-mkdir $(EX_DIRS)