# -*- 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                neverball
version             1.6.0
revision            2
categories          games
platforms           darwin
maintainers         nomaintainer
license             GPL-2+

description         Tilt the floor to roll a ball through an obstacle course.
long_description    \
        Tilt the floor to roll a ball through an obstacle \
        course before time runs out. Neverball is part puzzle \
        game, part action game, and entirely a test of skill.

# Note: https://github.com/Neverball/neverball
homepage            https://neverball.org/
master_sites        ${homepage}

checksums           rmd160  3489fcec1efe38c0faac62fe08573117a0f63c9f \
                    sha256  73fe63cca4f96e2d355480d03bc0b2904e83a0abdf65fe8c52db5cc3cca88fa0 \
                    size    37772911

depends_lib         port:libsdl2 \
                    port:libpng \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libvorbis \
                    port:libsdl2_ttf \
                    port:physfs \
                    port:libiconv \
                    port:gettext

patchfiles          patch-Makefile.diff

post-patch {
    reinplace "s|@CPPFLAGS@|${configure.cppflags}|g" ${worksrcpath}/Makefile
}

use_configure       no

build.args          CC="${configure.cc} [get_canonical_archflags]" \
                    DATADIR=${prefix}/share/games/${name}

destroot {
    xinstall -d -m 755 ${destroot}${prefix}/share/games
    file copy ${worksrcpath}/data ${destroot}${prefix}/share/games/${name}
    fs-traverse item ${destroot}${prefix}/share/games/${name} {
        if {[file isfile ${item}]} {
            switch [file extension ${item}] {
                .map {
                    delete ${item}
                }
                .sol {
                    file attributes ${item} -permissions 0644
                }
            }
        }
    }
    xinstall -s -m 755 -W ${worksrcpath} neverball neverputt ${destroot}${prefix}/bin
}

platform macosx {
    post-destroot {
        xinstall -d -m 755 \
            ${destroot}${applications_dir}/Neverball.app/Contents/MacOS \
            ${destroot}${applications_dir}/Neverputt.app/Contents/MacOS
        ln -s ${prefix}/bin/neverball \
            ${destroot}${applications_dir}/Neverball.app/Contents/MacOS/Neverball
        ln -s ${prefix}/bin/neverputt \
            ${destroot}${applications_dir}/Neverputt.app/Contents/MacOS/Neverputt
    }
}

livecheck.type      regex
livecheck.url       https://neverball.org/download.php
livecheck.regex     (\[0-9.\]+)${extract.suffix}
