# Copyright (C) Chris Wellons
# 
# This makefile should be used with the GNU version of make. Other
# versions may not handle the file correctly. It may be avaliable as
# gmake on some systems.

CXXFLAGS = -O2 -g -W -Wall

# Objects
mainobj   = bjack.o shoe.o hand.o
sharedobj = neuron.o layers.o nnetwork.o nncommon.o
objects   = $(sharedobj) $(mainobj)

# Project files
solutions = bjack
junktext  = sumlist.txt targeterr.txt err.txt win.txt poker_nn.txt \
            bjack_brain.txt
nnsources = neuron.cpp layers.cpp nnetwork.cpp nncommon.cpp
nnheaders = neuron.h   layers.h   nnetwork.h nncommon.h
bjacksrc  = shoe.cpp hand.cpp bjack.cpp
bjackhead = shoe.h hand.h
sources   = $(nnsources) $(bjacksrc)
headers   = $(nnheaders) $(bjackhead)
distfiles = $(sources) $(headers) Makefile

all : $(solutions)

# Project solutions
bjack : bjack.o shoe.o hand.o $(sharedobj)
	$(CXX) $(CXXFLAGS) $^ -o $@

# Build all of the objects
shoe.o : shoe.cpp shoe.h
hand.o : hand.cpp hand.h shoe.h
bjack.o : bjack.cpp nnetwork.h nncommon.h
nncommon.o : nncommon.cpp nncommon.h
layers.o: layers.cpp neuron.h layers.h
neuron.o: neuron.cpp neuron.h
nnetwork.o: nnetwork.cpp layers.h neuron.h nnetwork.h

# Phony targets
.PHONY : clean tar zip dir single

clean :
	$(RM) $(objects) $(solutions) $(junktext) proj3_group26.cpp

# This will produce the single source file as required for the project
# submission. This file should be able to compile all by itself (with
# "g++ proj3_group2.cpp" for example). The files must be carefully
# listed in order for this to work.
single : $(headers) $(sources)
	awk '!/#include "[^"]+"/ {print}' \
            $(headers) $(sources) > proj3_group26.cpp
