# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                crafty
categories          games
version             25.2
revision            1
platforms           darwin
supported_archs     x86_64
license             Restrictive Noncommercial
maintainers         {khindenburg @kurthindenburg} openmaintainer
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            https://web.archive.org/web/20220407202829/https://craftychess.com/
master_sites        macports_distfiles

set dist_srczip     ${name}-${version}.zip
set dist_book1      book.bin

distfiles           ${dist_srczip} \
                    ${dist_book1}

# fix mistake on checksums update on book.bin
dist_subdir   ${name}/${version}_1

checksums           ${dist_srczip} \
                    rmd160  2ccafc543f64fac628f6262a57fa4f80c7527b19 \
                    sha256  337e00bab79c33739fbaa71cd26c65f986886ee0d8ce181f2cb62f2efd317710 \
                    size    433320 \
                    ${dist_book1} \
                    rmd160  d316103399d48bc44237163a5e4cba76251c2342 \
                    sha256  f95c827d65a12a34879e50554de687ee91f3ca42580ab65abfa77638f27c3983 \
                    size    1704244

use_zip             yes
extract.mkdir       yes
extract.only        ${dist_srczip}
fetch.ignore_sslcert yes

patchfiles          patch-Makefile.diff \
                    patch-chess.h.diff \
                    patch-option.c.diff

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|" ${worksrcpath}/chess.h
    reinplace "s|@@PREFIX@@|${prefix}|" ${worksrcpath}/option.c

    reinplace "s|@@CC@@|${configure.cc}|g" ${worksrcpath}/Makefile
    reinplace "s|@@CXX@@|${configure.cxx}|g" ${worksrcpath}/Makefile
    reinplace "s|@@CFLAGS@@|${configure.cflags} [get_canonical_archflags cc]|g" ${worksrcpath}/Makefile
    reinplace "s|@@CXFLAGS@@|${configure.cxxflags} [get_canonical_archflags cxx]|g" ${worksrcpath}/Makefile
    reinplace "s|@@LDFLAGS@@|${configure.ldflags} [get_canonical_archflags ld]|g" ${worksrcpath}/Makefile
}

use_configure       no

# asm errors building +universal
#variant universal {}

build.target        unix-gcc

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} \
              ${destroot}${prefix}/share/${name}/

    file copy ${worksrcpath}/${name}.hlp ${destroot}${prefix}/share/${name}

    # create endgame tablebase folder
    xinstall -m 755 -d ${destroot}${prefix}/share/${name}/TB

}
destroot.keepdirs   ${destroot}${prefix}/share/${name}/TB

livecheck.type      none
