# -*- 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
PortGroup           cmake         1.1
PortGroup           github        1.0
PortGroup           legacysupport 1.1

github.setup        CorsixTH CorsixTH 0.70.0 v
name                corsixth
revision            1
categories          games
installs_libs       no
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

description         Open-source clone of Theme Hospital
long_description    \
    A reimplementation of the 1997 Bullfrog business sim Theme Hospital. As \
    well as faithfully recreating the original, CorsixTH adds support for \
    modern operating systems, high resolutions and much more.

checksums           rmd160  9bd30205d998c7c82b3692ca872c749a1ed42b18 \
                    sha256  e8f9803f6f64d23f057506202fbf275fe136c3245bab4bc19ff4c63691459cb7 \
                    size    4414049
github.tarball_from archive

legacysupport.use_mp_libcxx \
                    yes
# std::filesystem
legacysupport.newest_darwin_requires_legacy \
                    18

compiler.cxx_standard \
                    2017

# https://github.com/CorsixTH/CorsixTH/issues/3484
patchfiles-append   patch-cmakelists.txt.diff

post-patch {
    # https://github.com/CorsixTH/CorsixTH/issues/3485
    if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
        reinplace "s| @ATOMIC@| -latomic|" ${worksrcpath}/CorsixTH/CMakeLists.txt
    } else {
        reinplace "s| @ATOMIC@||" ${worksrcpath}/CorsixTH/CMakeLists.txt
    }
}

cmake.install_prefix \
                    ${applications_dir}

# MacPorts has broken this by switching to lua54: the way MacPorts handles lua stuff implies
# that lua port sets default lua ver. That is what CMake picks by default, and currently lua == lua53.
depends_lib-append  port:bzip2 \
                    path:lib/libavcodec.dylib:ffmpeg \
                    path:lib/pkgconfig/freetype2.pc:freetype \
                    port:libiconv \
                    port:libpng \
                    port:libsdl2 \
                    port:libsdl2_mixer \
                    port:lua53 \
                    port:lua53-lpeg \
                    port:lua53-luafilesystem \
                    port:rtmidi \
                    port:zlib

# Default anyway, but to be on a safe side:
configure.args-append \
                    -DWITH_LUAJIT=OFF

notes "
    CorixTH is now available in your Applications/MacPorts directory (${applications_dir})

    You will also need a copy of the game data from the original Theme Hospital game.
"

github.livecheck.regex \
                    {([0-9.]+)}
