# -*- 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           github 1.0

name                scummvm
categories          emulators games
maintainers         nomaintainer
license             {GPL-2 BSD}
description         cross-platform interpreter for several adventure engines
long_description    \
    ScummVM is a cross-platform interpreter for several point-and-click \
    adventure engines. A current list of playable games is available at \
    <https://www.scummvm.org/compatibility/>.

homepage            https://www.scummvm.org

if {${subport} eq ${name}} {
    github.setup        scummvm scummvm 2.9.0 v
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    revision            2
    checksums           sha256  d5b33532bd70d247f09127719c670b4b935810f53ebb6b7b6eafacaa5da99452 \
                        rmd160  f8a458600bcda76c7c7f9f89c31715cefefecf5c \
                        size    219893788

    conflicts           ${name}-devel
    long_description ${description}: \
        This port follows the release version of ${name}, which is typically updated every \
        6 months. If for some reason this port does not build or function as desired, try \
        the ${name}-devel port.

    master_sites        https://downloads.scummvm.org/frs/${name}/${version}
    use_xz              yes

    patchfiles-append   patch-scummvm-sdl2net-includes.diff \
                        remove-date-time-from-version.patch

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

subport ${name}-devel {
    github.setup        scummvm scummvm d52e078a82bbe0a569669b3f94a853ecc7776992
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    version             20231109
    revision            1
    checksums           rmd160  714933a6171cc1e1d9284b06a91815994e41fd5d \
                        sha256  e0e28234caf26c25b076449e36f647d045eac4ae0dd573a39ea03dd455ddc2d3 \
                        size    241152219

    conflicts           ${name}
    long_description ${description}: \
        This port follows the master version of ${name}, which is typically updated every few weeks.

    patchfiles-append   patch-scummvm-sdl2net-includes.diff \
                        remove-date-time-from-version.patch

    # ./common/ustr.h:62:12: error: constexpr constructor never produces a constant expression
    compiler.blacklist-append {clang < 801}

    livecheck.type      none
}

depends_lib-append  port:libsdl2 \
                    port:libsdl2_net \
                    port:libmad \
                    port:libogg \
                    port:libvorbis \
                    port:libpng \
                    port:flac \
                    port:libtheora \
                    port:fluidsynth \
                    port:faad2 \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:freetype \
                    port:bzip2 \
                    port:curl \
                    port:expat \
                    port:gettext \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:libedit \
                    port:libffi \
                    port:libiconv \
                    port:libsndfile \
                    port:ncurses \
                    port:pcre \
                    port:portaudio \
                    port:readline \
                    port:zlib

configure.args-append  \
                    --enable-release \
                    --enable-plugins \
                    --default-dynamic \
                    --enable-sdlnet \
                    --enable-cloud \
                    --enable-libcurl \
                    --enable-theoradec \
                    --enable-jpeg \
                    --enable-readline \
                    --enable-all-engines \
                    --enable-verbose-build

# libcurl needs --enable-cloud as well otherwise link errors
# also connected to --enable-sdlnet

if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
    configure.ldflags-append -stdlib=${configure.cxx_stdlib}
}

# some plugins fail to link unless these are manually added
configure.ldflags-append -lSDL2 -lfreetype

# Fix build on G3
platform powerpc {
    if {[catch {sysctl hw.vectorunit} result] || $result == 0} {
        configure.ldflags-append -force_cpusubtype_ALL
        archive_sites
    }
}

# Leopard build, at least, fails without c++11
compiler.cxx_standard   2011
