# -*- 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                bsd-games
version             3.3
revision            1
categories          games
license             BSD
maintainers         {makr @mohd-akram} openmaintainer

description         Classic text mode games from UNIX folklore

long_description    {*}${description}

homepage            https://bsd-games.sourceforge.net

master_sites        sourceforge

checksums           rmd160  50703d26b0b9bb8135c1ed0d6ceea91f91c7109d \
                    sha256  78bfdf7f4e1f61ed42ad1209ef52520b89a583bd511e9606b8162f813078048d \
                    size    268373

depends_build       port:pkgconfig

depends_lib         port:ncurses

post-patch {
    reinplace \
        "s|snprintf\[\[:space:]]*(ArrayBlock\[\[:space:]]*(\\(\[^)]*\\))|snprintf(\\1, ArraySize(\\1)|g" \
        {*}[glob ${worksrcpath}/*/*.c]
    reinplace "s|/var/|${prefix}/var/|g" {*}[glob ${worksrcpath}/*/*.6]
}

configure.args      --localstatedir=${prefix}/var/lib

destroot.args       INSTALL_SCORE=:
destroot.keepdirs   ${destroot}${prefix}/var/lib/bsdgames

post-activate {
    foreach {game} {adventure atc battlestar drop4 robots snake spirhunt} {
        set scores ${prefix}/var/lib/bsdgames/${game}.scores
        if {![file exists ${scores}]} {
            xinstall -m 664 -g everyone /dev/null ${scores}
        }
    }
}