# Our code tries to conform to Single Unix Specification v4.
# See feature_test_macros man page.

CC         = $(CXX)		# Make sure we link C++ properly...
CPPFLAGS   = -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600
CXXFLAGS_common = -MMD -Os -std=gnu++98 -Wall -Weffc++ -Iinclude/
CXXFLAGS        = -g $(CXXFLAGS_common)
LDFLAGS    =
ASFLAGS    =
TARGETS    = mcp example-player my-player

SRC_common = state.cc
SRC_intern = state-internal-$(shell uname -s)-$(shell uname -m).s
SRC_mcp    = mcp.cc
SRC_ep     = example-player.cc
# my-player is not allowed to link to state-internal-*.s !
SRC_mp     = my-player.cc

SRC_all    = $(SRC_ep) $(SRC_mcp) $(SRC_common) $(SRC_mp)

all: $(TARGETS)
.PHONY: run clean distclean help

mcp:            $(SRC_mcp:.cc=.o) $(SRC_intern:.s=.o) $(SRC_common:.cc=.o)
example-player: $(SRC_ep:.cc=.o)  $(SRC_common:.cc=.o)
my-player:      $(SRC_mp:.cc=.o)  $(SRC_common:.cc=.o)


demo: mcp example-player example-player
	./$+

run: mcp my-player example-player
	./$+

fight: mcp my-player my-player
	./$< -t 60 -T 61 -m 1024 -M 1024 $(filter-out $<,$+)

clean:
	rm -f $(TARGETS) $(wildcard *.[do])

distclean: clean
	rm -f core *~ include/*~ *.s

#$(SRC_intern): state-internal.cc
#	$(CXX) $(CPPFLAGS) $(CXXFLAGS_common) -S $< -o $@

help:
	@echo "make all         Build everything."
	@echo "make demo        Two example (keyboard) players play against each other."
	@echo "make run         The keyboard player plays against your player."
	@echo "make fight       Two instances of your player play with contest rules."

# Rebuild everything when the Makefile was changed.
$(SRC_all:.cc=.o): Makefile

# Include dependency information.
-include $(SRC_all:.cc=.d)

# EOF
