# -*- 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                openttd

categories          games aqua
platforms           macosx

maintainers         {cal @neverpanic} openmaintainer


if {${name} eq ${subport}} {
    PortGroup           cmake 1.1

    version             14.1
    revision            0

    checksums           rmd160  ac02ce0fb6726b721be712703054a6799baf523a \
                        sha256  2c14c8f01f44148c4f2c88c169a30abcdb002eb128a92b9adb76baa76b013494 \
                        size    8015032

    license             GPL-2

    description         OpenTTD is an open source simulation game based upon Transport Tycoon Deluxe
    long_description    \
        OpenTTD is an open source simulation game based upon the popular Microprose \
        game \"Transport Tycoon Deluxe\", written by Chris Sawyer. It attempts to \
        mimic the original game as closely as possible while extending it with new \
        features.

    homepage            https://www.openttd.org/
    master_sites        https://cdn.openttd.org/openttd-releases/${version}
    distfiles           openttd-${version}-source.tar.xz
    use_xz              yes

    depends_build-append \
                        port:pkgconfig

    depends_lib         port:zlib \
                        port:lzo2 \
                        port:xz \
                        port:libpng \
                        port:freetype \
                        port:fontconfig \
                        port:libiconv

    depends_run         port:openttd-opengfx \
                        port:openttd-opensfx \
                        port:openttd-openmsx

    patchfiles          patch-cmake-PackageBundle.diff

    compiler.cxx_standard   2017

    configure.args-append \
                        -DOPTION_USE_ASSERTS=Off \
                        -DCMAKE_INSTALL_PREFIX=${applications_dir}/OpenTTD.app/Contents/Resources/

    post-destroot {
        xinstall -m 0644 ${worksrcpath}/os/macosx/openttd.icns \
            ${destroot}${applications_dir}/OpenTTD.app/Contents/Resources/OpenTTD.icns

        xinstall -m 0644 ${cmake.build_dir}/Info.plist.in \
            ${destroot}${applications_dir}/OpenTTD.app/Contents/Info.plist
        reinplace "s|#CPACK_PACKAGE_VERSION#|${version}|g" \
            ${destroot}${applications_dir}/OpenTTD.app/Contents/Info.plist
    }

    livecheck.type      regex
    livecheck.url       ${homepage}
    livecheck.regex     {Download stable \((\d+(\.\d+)+)\)}
}

subport openttd-opengfx {
    version             7.1
    revision            0
    checksums           rmd160  2fec54ccdd6dad5e5f1917e581cde5c075824fa3 \
                        sha256  928fcf34efd0719a3560cbab6821d71ce686b6315e8825360fba87a7a94d7846 \
                        size    3547160

    supported_archs     noarch
    platforms           any
    license             GPL-2

    description         OpenGFX is a free set of graphics for OpenTTD.
    long_description    \
        The OpenGFX project for OpenTTD: a free replacement of the base \
        graphics so that OpenTTD can be shipped finally fully functional \
        without the need for additional downloads.

    homepage            https://github.com/OpenTTD/OpenGFX
    master_sites        https://cdn.openttd.org/opengfx-releases/${version}
    distfiles           opengfx-${version}-all.zip
    worksrcdir          opengfx-${version}
    use_zip             yes

    use_configure       no
    build               {}
    destroot {
        set target ${destroot}${applications_dir}/OpenTTD.app/Contents/Resources/baseset/
        xinstall -d -m 755 ${target}
        xinstall -m 644 \
            ${workpath}/opengfx-${version}.tar \
            ${target}
    }

    livecheck.url       https://www.openttd.org/downloads/opengfx-releases/latest
    livecheck.regex     {Latest stable release in opengfx is (\d+(\.\d+)+),}
}

subport openttd-opensfx {
    version             1.0.3
    revision            0
    checksums           rmd160  1e0296baeab666f20365b67876e507e4ed6589cd \
                        sha256  e0a218b7dd9438e701503b0f84c25a97c1c11b7c2f025323fb19d6db16ef3759 \
                        size    11566000

    supported_archs     noarch
    platforms           any
    # actually CC Sampling Plus 1.0
    license             Permissive

    description         OpenSFX is a free set of sounds for OpenTTD.
    long_description    \
        The OpenSFX project for OpenTTD: a free replacement of the base sounds \
        so that OpenTTD can be shipped finally fully functional without the \
        need for non-free files.

    homepage            https://github.com/OpenTTD/OpenSFX
    master_sites        https://cdn.openttd.org/opensfx-releases/${version}
    distfiles           opensfx-${version}-all.zip
    worksrcdir          opensfx-${version}
    use_zip             yes

    use_configure       no
    build               {}
    destroot {
        set target ${destroot}${applications_dir}/OpenTTD.app/Contents/Resources/baseset/
        xinstall -d -m 755 ${target}
        xinstall -m 644 \
            ${workpath}/opensfx-${version}.tar \
            ${target}
    }

    livecheck.url       https://www.openttd.org/downloads/opensfx-releases/latest
    livecheck.regex     {Latest stable release in opensfx is (\d+(\.\d+)+),}
}

subport openttd-openmsx {
    version             0.4.2
    revision            0
    checksums           rmd160  9079e1942b9fb19ddc31a313a7d86e50d1aac772 \
                        sha256  5a4277a2e62d87f2952ea5020dc20fb2f6ffafdccf9913fbf35ad45ee30ec762 \
                        size    140204

    supported_archs     noarch
    platforms           any
    license             GPL-2

    description         OpenMSX is a free set of music for OpenTTD.
    long_description    \
        The OpenMSX project for OpenTTD: a free replacement of the base music \
        so that OpenTTD can be shipped finally fully functional without the \
        need for non-free files.

    homepage            https://github.com/OpenTTD/OpenMSX
    master_sites        https://cdn.openttd.org/openmsx-releases/${version}
    distfiles           openmsx-${version}-all.zip
    worksrcdir          openmsx-${version}
    use_zip             yes

    use_configure       no
    build               {}
    destroot {
        set target ${destroot}${applications_dir}/OpenTTD.app/Contents/Resources/baseset/
        xinstall -d -m 755 ${target}
        xinstall -m 644 \
            ${workpath}/openmsx-${version}.tar \
            ${target}
    }

    livecheck.url       https://www.openttd.org/downloads/openmsx-releases/latest
    livecheck.regex     {Latest stable release in openmsx is (\d+(\.\d+)+),}
}
