# -*- 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                glob2
version             0.9.4.4
revision            2
checksums           rmd160  c0f1c2534eeb95bb901bc61a462495183f191be2 \
                    sha256  0f4d898ec6b05ce27b4a12ef242cc26571304b90d2509932a4743c71311314b8 \
                    size    11338986

# Build system is designed for Python 2; MacPorts SCons uses Python 3
# https://github.com/Globulation2/glob2/issues/24
# https://github.com/Globulation2/glob2/issues/76#issuecomment-1670894331
known_fail          yes

set branch          [join [lrange [split ${version} .] 0 2] .]
categories          games
license             GPL-3+
maintainers         {ryandesign @ryandesign} openmaintainer

description         Globulation 2 - a free and innovative strategy game

long_description    Globulation 2 is an innovative high quality Real-Time \
                    Strategy, which minimizes micro-management by \
                    automatically assigning tasks to the units. The player \
                    has to choose the number of units he wants for the \
                    different tasks, and the units will do their best to \
                    satisfy the requests. This allows to manage more units \
                    and to focus on the strategy. It can be played alone, \
                    through your Local Area Network, or through Internet \
                    thanks to Ysagoon Online Game, a meta-server. It also \
                    features a scripting language for versatile gameplay or \
                    tutorials and an integrated map editor.

homepage            https://globulation2.org/wiki/Main_Page
master_sites        http://dl.sv.nongnu.org/releases/glob2/${branch}/

depends_build       port:pkgconfig \
                    port:scons

depends_lib         port:boost \
                    port:freetype \
                    port:fribidi \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libiconv \
                    port:libogg \
                    port:libpng \
                    port:libsdl \
                    port:libsdl_image \
                    port:libsdl_net \
                    port:libsdl_ttf \
                    port:libvorbis \
                    port:portaudio \
                    path:lib/libspeex.dylib:speex \
                    port:tiff \
                    port:zlib

pre-patch {
    # Files missing in tarball; downloaded from
    # https://bitbucket.org/giszmo/glob2/src/7f98290bab5c5f5c4194b2aa7ae26c992ccef6d1/darwin/
    # with these changes to the Info.plist:
    # * CFBundleVersion changed from hardcoded outdated version to @VERSION@
    # * CFBundleShortVersionString added
    # * NSHighResolutionCapable added
    xinstall -d ${worksrcpath}/darwin
    xinstall -W ${filespath} -m 0644 Glob2.icns Info.plist ${worksrcpath}/darwin
    reinplace "s|@VERSION@|${version}|g" ${worksrcpath}/darwin/Info.plist
}

patchfiles-append   BuildProject.patch
patchfiles-append   bundle.patch
patchfiles-append   CoreFoundation.patch
patchfiles-append   iostream.patch
patchfiles-append   SConstruct.patch

use_configure       no

variant universal {}

build.cmd           ${prefix}/bin/scons
build.target
build.args          --portaudio=true \
                    CC="${configure.cc}" \
                    CXX="${configure.cxx}" \
                    CFLAGS="${configure.cflags} [get_canonical_archflags cc]" \
                    CXXFLAGS="${configure.cxxflags} [get_canonical_archflags cxx]" \
                    LINKFLAGS="${configure.ldflags} [get_canonical_archflags ld]"

# The SConscript makes a Mac app bundle when release=1, but incorrectly
# attempts to do so before building anything, which of course fails.
# So don't use release=1 in the build phase, but do use it in destroot.
destroot.target
destroot.args       {*}${build.args} \
                    release=1

post-destroot {
    move ${worksrcpath}/Glob2.app ${destroot}${applications_dir}

    # Using a symlink doesn't work because the app can't find its data files.
    set fp [open ${destroot}${prefix}/bin/glob2 w 0755]
    puts ${fp} "#!/bin/sh"
    puts ${fp} "exec \"${applications_dir}/Glob2.app/Contents/MacOS/glob2\" \"$@\""
    close ${fp}
}

livecheck.type      regex
livecheck.url       ${homepage}/wiki/Download_and_Install
livecheck.regex     /${name}-(\[0-9.\]+)${extract.suffix}
