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

name                boswars
version             2.7
revision            2
categories          games
maintainers         nomaintainer
license             GPL-2

description         Bos Wars is a futuristic real time strategy game.
long_description    Bos Wars is a futuristic real time strategy game (RTS). \
                    Bos Wars has a dynamic rate based economy. Energy is \
                    produced by power plants and magma gets pumped from hot \
                    spots. Buildings and mobile units are also built at a \
                    continuous rate. Control of larger parts of the map \
                    creates the potential to increase your economy \
                    throughput. Holding key points like roads and passages \
                    allow for different strategies.

homepage            https://www.boswars.org/
master_sites        ${homepage}dist/releases:boswars \
                    http://dev.gentoo.org/~hasufell/distfiles:images

set imagefile       boswars-${version}-fixed-images-for-libpng-1.6.tar.xz

distname            ${name}-${version}-src
distfiles           ${distname}${extract.suffix}:boswars \
                    ${imagefile}:images

checksums           ${distname}${extract.suffix} \
                    rmd160  8a22afb974452d5290e4023f801752b8f2defe04 \
                    sha256  dc3718f531e9ea413cf37e1333b62a4c5e69f1405502d9c59b9e424635135e3e \
                    size    77280735 \
                    ${imagefile} \
                    rmd160  4354ab05348d2827ec17eeac472b03e854bcdaa7 \
                    sha256  87f3ee7f4045c3acfacd884348a2b376e710b42aa0f40acbc212732d0bee9a24 \
                    size    552956

depends_extract-append port:xz

depends_build       port:pkgconfig \
                    port:scons

depends_lib         port:libogg \
                    port:libpng \
                    port:libsdl \
                    port:libtheora \
                    port:libvorbis \
                    port:zlib

lua.version         5.1

license_noconflict  scons

extract.only        ${distname}${extract.suffix}

# Image files shipped with boswars are built with libpng15.
# Replace them with fixed images built with libpng16.

post-extract {
    system -W ${worksrcpath} "${prefix}/bin/xz -dc '${distpath}/${imagefile}' | ${portutil::autoconf::tar_command} --strip-components 1 -xf -"
}

pre-patch {
    xinstall ${filespath}/build_options.py ${worksrcpath}
}

patchfiles          patch-SConstruct.diff \
                    patch-engine_video_graphic.cpp.diff

post-patch {
    reinplace "s|__PREFIX__|${prefix}|g" ${worksrcpath}/build_options.py
    reinplace "s|__CC__|${configure.cc}|g" ${worksrcpath}/build_options.py
    reinplace "s|__CXX__|${configure.cxx}|g" ${worksrcpath}/build_options.py
}

use_configure       no
universal_variant   no

build.cmd           ${prefix}/bin/scons
build.target

destroot {
    # Path to the boswars resource directory ${prefix}/share/boswars.
    set share ${prefix}/share/boswars

    # Rename the boswars binary to boswars-bin and install it in destroot so a
    # helper script can be used which automatically sets the path to the
    # boswars files.
    move ${worksrcpath}/build/boswars-release ${destroot}${prefix}/bin/boswars-bin
    # Copy the helper script to ${prefix}/bin.
    xinstall ${filespath}/boswars ${destroot}${prefix}/bin
    # Set the correct path to the boswars files in the boswars helper script.
    reinplace "s|__BOSWARS__|${share}|g" ${destroot}${prefix}/bin/boswars

    # Create the resource directory in destroot.
    xinstall -d ${destroot}${share}
    # Install the boswar files into ${prefix}/share/boswars:
    set files {campaigns doc graphics intro languages maps scripts sounds \
               units}
    foreach file $files {
        move ${worksrcpath}/$file ${destroot}${share}/${file}
    }
}

notes "
Attention! Changing display mode to OpenGL in the settings\
menu may not work and cause an application crash! If this\
happens remove ~/Library/boswars/preferences.lua to reset\
the setting.
"

livecheck.type      regex
livecheck.url       ${homepage}download.shtml
livecheck.regex     ${name}-(\[0-9.\]+)-src${extract.suffix}
