ifeq ($(OSTYPE),cygwin)
eext = .exe
# Most of the time we want to use MingW to avoid dependency on cygwin
# DLL, but here we especially want to avoid it because it has very
# poor thread performance, at least when I tried on 2019-11-29.
cc = x86_64-w64-mingw32-g++
cflags = -std=c++11 -Wall -Werror -pedantic -O3
lflags = -static
else
eext =
cc = g++
cflags = -std=c++11 -Wall -Werror -pedantic -O3
lflags = -lpthread
endif

solve = solve$(eext)
list_blocks = list_blocks$(eext)
trace_moves = trace_moves$(eext)

all: $(solve) $(list_blocks) $(trace_moves)

$(solve): main.o state.o ai.o
	$(cc) $^ $(lflags) -o $@

$(list_blocks): list_blocks.o state.o
	$(cc) $^ $(lflags) -o $@

$(trace_moves): trace_moves.o state.o
	$(cc) $^ $(lflags) -o $@

main.o: main.cc state.h ai.h
	$(cc) $(cflags) -c $< -o $@

list_blocks.o: list_blocks.cc state.h
	$(cc) $(cflags) -c $< -o $@

trace_moves.o: trace_moves.cc state.h
	$(cc) $(cflags) -c $< -o $@

ai.o: ai.cc ai.h state.h
	$(cc) $(cflags) -c $< -o $@

state.o: state.cc state.h
	$(cc) $(cflags) -c $< -o $@

ai.h: state.h


thread_pool.o: thread_pool.cc thread_pool.h
	$(cc) $(cflags) -c $< -o $@

thread_pool_test.o: thread_pool_test.cc thread_pool.h
	$(cc) $(cflags) -c $< -o $@

thread_pool_test$(eext): thread_pool_test.o thread_pool.o
	$(cc) $^ $(lflags) -o $@


clean:
	-rm -f *.o $(solve) $(list_blocks) $(trace_moves)

backup:
	-rm -f backup.tar.gz
	tar czf backup.tar.gz *.rb *.cc *.h *.sh *.pl Makefile *.txt
