# $Id: Portfile 92184 2012-04-21 10:50:23Z pmq@macports.org $

PortSystem          1.0

name                crafty
categories          games
version             23.4
platforms	    darwin
maintainers	    pmq
description         Crafty is a chess program, that can be interfaced with xboard.

long_description    \
    Crafty is the derivative of Cray Blitz, a computer chess program. It is \
    a very strong one, and its current peak ICC ratings are 3286 (bullet), \
    3388 (blitz) and 2792 (standard). It can be used with xboard just like \
    gnuchess.

homepage            http://www.cis.uab.edu/hyatt/hyatt.html
master_sites        ftp://ftp.cis.uab.edu/pub/hyatt/source:src \
		    ftp://ftp.cis.uab.edu/pub/hyatt/documentation:doc \
		    ftp://ftp.cis.uab.edu/pub/hyatt/book:book

set dist_srczip	    ${name}-${version}.zip
set dist_book1	    book.bin
set dist_book2 	    bookc.bin
set dist_book3 	    books.bin
set dist_ascii	    ${name}.doc.ascii
set dist_ps	    ${name}.doc.ps
set dist_man	    ${name}.man
dist_subdir	    ${name}/${version}

distfiles	    ${dist_srczip}:src \
		    ${dist_book1}:book \
		    ${dist_book2}:book \
		    ${dist_book3}:book \
		    ${dist_ascii}:doc \
		    ${dist_ps}:doc \
		    ${dist_man}:doc

checksums \
	${dist_srczip} \
	rmd160  c21292abd1f14b72f83b727884b4f2e534604aee \
	sha256  f49e119b9e843bd1f99b895919b4361ba0d6ae4349e2751a864872d6dd250e66 \
	${dist_book1} \
	rmd160  0254f07781ea9a096feae892bd7343e401e4b413 \
	sha256  67a41dda9a477912b570cc5583fe5fac4f93fb2dba9db436f77f5f95217279b2 \
	${dist_book2} \
	rmd160  532ec57508ebd3bb6db052d853d1be549faeb859 \
	sha256  746a343dc9cda2bcf9ded95aa5b9503c8d629d3463ee7709bd06bd852932fc41 \
	${dist_book3} \
	rmd160  b2b5d8f9b2be351373b734e9f3ca3d34c2aa2438 \
	sha256  c81be5033aeb43decfa82604eebf7f16026131e9aedd7d1f0aa1b5e19863a744 \
	${dist_ascii} \
	rmd160  f0c8304efcaa93a14a37da96d22bb25cda8d1bf5 \
	sha256  be291c0f4c7e7d64404ec58b9e92c2455c4342d3c96c721ba21a80fce8332e83 \
	${dist_ps} \
	rmd160  10001918bfc54a9c456b4572037b9fa640491d7b \
	sha256  887eb54de05f3371ef95adc38629a0f1f2cad66d1ca1b14fc426b87f5b13a9ab \
	${dist_man} \
	rmd160  ccfedc1511a0ae523e16f94d9818abb29b1ea188 \
	sha256  7c6c217431abb178ed53a6f9f949a2412a9bf30be856077b30dfbc13d426ca0e

depends_build	    bin:unzip:unzip

extract {
    file mkdir work

    # extract the src zip
    system "cd ${workpath} && unzip ${distpath}/${dist_srczip}"
    reinplace "s|IPHONE|__APPLE__|g" ${worksrcpath}/chess.h
    reinplace -E "s|BOOKDIR \+\".\"|BOOKDIR \"${prefix}/share/crafty\"|g" ${worksrcpath}/chess.h
}

use_configure	    no

build.target	    darwin
# in a next version, point crafty to the default location for books
# for the moment use the classic bookpath switch when launching it
# should you want to use endgame tables, put them into the TBDIR
# build.args	    -DBOOKDIR=${prefix}/share/${name}/ \
#		    -DTBDIR=${prefix}/share/${name}/TB/

destroot {
    # copy the executable
	xinstall -m 755 -d ${destroot}${prefix}/bin
    file copy ${worksrcpath}/${name} ${destroot}${prefix}/bin/

    # copy the book files
    xinstall -m 755 -d ${destroot}${prefix}/share/${name}
    file copy ${distpath}/${dist_book1} \
    	      ${distpath}/${dist_book2} \
	      ${distpath}/${dist_book3} \
	${destroot}${prefix}/share/${name}/

    # copy the docs
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    file copy ${distpath}/${dist_ascii} \
    	      ${distpath}/${dist_ps} \
	${destroot}${prefix}/share/doc/${name}

    # copy the manpage, renaming the extension
    file copy ${distpath}/${dist_man} \
    	${destroot}${prefix}/share/man/man1/${name}.1
}
