sources = $(wildcard *.c)
headers = $(wildcard *.h)
tests = test/test-level-nocurses test/test-level-curses test/test-command-nocurses test/test-command-curses test/test-utils test/test-character-nocurses test/test-character-curses
executable = game-nocurses game-curses test/test-list

# Declare targets which do not use dependences for determining whether 
# to recompile or not
.PHONY: all clean doc

# Default target: compile everything
all : check doc ${executable}

# Main targets: compile the game
# Using only stdio library for I/O
game-nocurses : ${sources}
	$(CC) -o $@ $^ -lm

# Using the ncurses library for a more friendly I/O (much better)
game-curses : ${sources}
	$(CC) -DCURSES -o $@ $^ -lncurses -lm

# Test targets: compile the tests
./test/test-level-nocurses : level.c items.c utils.c printer.c monsters.c character.c
	$(CC) -DDEBUG -DTEST_LEVEL -o $@ $^ -lncurses -lm

./test/test-level-curses : level.c items.c utils.c printer.c monsters.c character.c
	$(CC) -DCURSES -DTEST_LEVEL -o $@ $^ -lncurses -lm

./test/test-command-nocurses : commands.c printer.c
	$(CC) -DDEBUG -DTEST_COMMANDS -o $@ $^

./test/test-command-curses : commands.c printer.c
	$(CC) -DCURSES -DTEST_COMMANDS -o $@ $^ -lncurses

./test/test-utils : utils.c
	$(CC) -DTEST_UTILS -o $@ $^

./test/test-list : list.c utils.c
	$(CC) -DTEST_LISTS -o $@ $^

./test/test-character-nocurses : character.c printer.c utils.c items.c
	$(CC) -DDEBUG -DTEST_CHARACTER -o $@ $^

./test/test-character-curses : character.c printer.c utils.c items.c
	$(CC) -DCURSES -DTEST_CHARACTER -o $@ $^ -lncurses

# Build the documentation (html and pdf) with doxygen (you need to have this
# program installed to run this target, of course)
doc: ${sources} ${headers}
	doxygen doxy.conf

# Run the various tests (building them if necessary)
# Only tests for features that have been modified are actually run
check : ${tests}
	for i in $? ; do echo $${i} ; ./$${i} ./test_level.txt ; echo '' ; done
	touch check

# Remove files that can be regenerated
# Run this command before zipping and sending the program to other people!
clean : 
	rm -f ${executable}
	rm -f *.o
	rm -rf test
	rm -rf doc
	mkdir doc
	mkdir test

