#! /usr/bin/make -f

SHELL = /bin/bash

VERSION = 1.02
PGNBOOK := book_$(VERSION).pgn

%:
	dh $@

override_dh_auto_build:
	dh_testdir $(PGNBOOK)
	# Spam only if stdout is a tty
	@ if /usr/bin/tty -s 0>&1; then ( \
	   echo "---------------------------------------------------------------"; \
	   echo "Building book, this may take some time. There will be a counter"; \
	   echo "running to keep you entertained. The PGN file seems to contain "; \
	   echo -n "`grep -c '^\[White' $(PGNBOOK) 2> /dev/null` games. "        ; \
	   echo "The actual count will probably be a little less"                ; \
	   echo "because gnuchess only accepts games played by some hardcoded"   ; \
	   echo "list of players."                                               ; \
	   echo "---------------------------------------------------------------"; \
	   /usr/games/gnuchess --addbook $(PGNBOOK) ); \
	else ( \
	   echo "Building book."; \
	   /usr/games/gnuchess --addbook $(PGNBOOK) &> /dev/null ); \
	fi

get-orig-source:
	wget http://ftp.gnu.org/pub/gnu/chess/$(PGNBOOK).gz
	gunzip $(PGNBOOK).gz
	mkdir gnuchess-book-$(VERSION)
	mv $(PGNBOOK) gnuchess-book-$(VERSION)
	tar czf gnuchess-book_$(VERSION).orig.tar.gz gnuchess-book-$(VERSION)
	rm -rf gnuchess-book-$(VERSION)/
