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

github.setup        elasota Aerofoil 1.1.2
revision            1
set src_distfile    ${distfiles}
set dat_distname    ${distname}-win64
set dat_distfile    ${dat_distname}.zip
checksums           ${src_distfile} \
                    rmd160  2382b9a93d340e381a6c444700b0a2e4602bcfad \
                    sha256  94f87e57ab8853730e7cc18cf971fb469129f34a2decfe9f8e961caaaf107e30 \
                    size    33306728 \
                    ${dat_distfile} \
                    rmd160  d0be9c700c4db859319851995be47b7ff84e850a \
                    sha256  a407f6e70e79941198ce36ae4fda8d000c7f10c8a0b52b1fd740e70b2c4c0a99 \
                    size    9503855

categories          games
platforms           macosx
maintainers         {ryandesign @ryandesign} openmaintainer
license             GPL-2+

description         a port of John Calhoun's Glider PRO

long_description    ${name} is {*}${description}, the classic 1994 \
                    paper airplane game for Macintosh.

homepage            https://galeforcegames.itch.io/aerofoil
github.tarball_from archive
master_sites        ${github.master_sites}:src \
                    ${github.homepage}/releases/download/${github.version}:dat
distfiles           ${src_distfile}:src \
                    ${dat_distfile}:dat

depends_extract-append \
                    bin:unzip:unzip

depends_lib-append  port:libsdl2 \
                    port:zlib

extract.only        ${src_distfile}
post-extract {
    # The programs that convert the game data from the form in the
    # repository to the form needed by the game only work on Windows so
    # we have to get the converted files from the Windows binary.
    # https://github.com/elasota/Aerofoil/issues/8#issuecomment-1069795648
    system -W ${workpath} "unzip -q [shellescape ${distpath}/${dat_distfile}] Aerofoil/Packaged/*"
}

patchfiles          Aerofoil.patch \
                    stdlib.patch \
                    zlib.patch

compiler.cxx_standard 2011

configure.args      -DPLATFORM=MAC

post-build {
    # If someone knows a less cumbersome way to make an icns from an
    # appiconset let me know. The app portgroup should probably be
    # enhanced to be able to work with iconsets and appiconsets.
    file mkdir ${build.dir}/${name}.iconset
    foreach png [glob ${worksrcpath}/AerofoilMac/AerofoilMac/Assets.xcassets/AppIcon.appiconset/*.png] {
        set size [file rootname [file tail ${png}]]
        copy ${png} ${build.dir}/${name}.iconset/icon_${size}x${size}.png
    }
    system -W ${build.dir} "iconutil -c icns ${name}.iconset"
}

app.executable      ${build.dir}/AerofoilMac
app.icon            ${build.dir}/${name}.icns
app.identifier      com.madthijs.AerofoilMac

destroot {
    move ${workpath}/Aerofoil/Packaged ${destroot}${applications_dir}/${app.name}.app/Contents/Resources/
    copy ${worksrcpath}/Documentation ${destroot}${prefix}/share/doc/${name}
}

if {${os.platform} eq "darwin" && ${os.major} < 14} {
    # error: unknown type name 'NS_ASSUME_NONNULL_BEGIN'
    # error: unknown type name 'NS_ASSUME_NONNULL_END'
    known_fail              yes
    pre-fetch {
        ui_error "${subport} @${version} requires OS X 10.10 or greater."
        return -code error "incompatible OS X version"
    }
}
