CFLAGS=-O3 -Wall
DISTFILES=oware.c oware.h turn.c comp.c Makefile HEADER.html

all: turn comp origcomp

turn: turn.o oware.o
	gcc -O -Wall turn.o oware.o -o turn

comp: comp.o oware.o
	gcc -O -Wall comp.o oware.o -o comp

origcomp: origcomp.o oware.o
	gcc -O -Wall origcomp.o oware.o -o origcomp

alphabetacomp: alphabetacomp.o oware.o
	gcc -O -Wall alphabetacomp.o oware.o -o alphabetacomp

sorthousescomp: sorthousescomp.o oware.o
	gcc -O -Wall sorthousescomp.o oware.o -o sorthousescomp

optcomp: optcomp.o oware.o
	gcc -O -Wall optcomp.o oware.o -o optcomp

optcomp3: optcomp.o oware.o
	gcc -O3 -Wall optcomp.o oware.o -o optcomp3

turn.o: turn.c oware.h

comp.o: comp.c oware.h

origcomp.o: origcomp.c oware.h

alphabetacomp.o: alphabetacomp.c oware.h

sorthousescomp.o: sorthousescomp.c oware.h

optcomp.o: optcomp.c oware.h

oware.o: oware.h oware.c

dist: $(DISTFILES)
	rm -rf oware oware.zip
	mkdir oware
	cp -rp $(DISTFILES) oware
	zip -9r oware.zip oware

bench: comp
	LC_NUMERIC=en_US.utf8 perf stat -B -e cycles:u -e instructions:u -e branches:u -e branch-misses:u ./comp 12 0 14 9 8 7 5 0 0 1 0 0 0 4 0

#LC_NUMERIC=en_US.utf8 perf stat -B -e cycles:u -e instructions:u -e branches:u -e branch-misses:u comp 12 0 14 9 8 7 5 0 0 1 0 0 0 4 0
#Position:
#    4  0  0  0  1  0
#  0                  0
#    0 14  9  8  7  5
#Best move (1-6): 5  Value: -1
#
# Performance counter stats for 'comp 12 0 14 9 8 7 5 0 0 1 0 0 0 4 0':
#
#   344,306,194,571      cycles:u
#   711,065,944,240      instructions:u            #    2.07  insn per cycle
#   123,045,591,793      branches:u
#     4,643,565,058      branch-misses:u           #    3.77% of all branches
#
#     102.935136358 seconds time elapsed

origbench: origcomp
	LC_NUMERIC=en_US.utf8 perf stat -B -e cycles:u -e instructions:u -e branches:u -e branch-misses:u ./origcomp 12 0 14 9 8 7 5 0 0 1 0 0 0 4 0

alphabetabench: alphabetacomp
	LC_NUMERIC=en_US.utf8 perf stat -B -e cycles:u -e instructions:u -e branches:u -e branch-misses:u ./alphabetacomp 12 0 14 9 8 7 5 0 0 1 0 0 0 4 0

sorthousesbench: sorthousescomp
	LC_NUMERIC=en_US.utf8 perf stat -B -e cycles:u -e instructions:u -e branches:u -e branch-misses:u ./sorthousescomp 12 0 14 9 8 7 5 0 0 1 0 0 0 4 0

optbench: optcomp
	LC_NUMERIC=en_US.utf8 perf stat -B -e cycles:u -e instructions:u -e branches:u -e branch-misses:u ./optcomp 12 0 14 9 8 7 5 0 0 1 0 0 0 4 0

optbench3: optcomp3
	LC_NUMERIC=en_US.utf8 perf stat -B -e cycles:u -e instructions:u -e branches:u -e branch-misses:u ./optcomp3 12 0 14 9 8 7 5 0 0 1 0 0 0 4 0

clean:
	rm -rf *.o comp origcomp alphabetacomp sorthousescomp optcomp optcomp3