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

# strnlen
legacysupport.newest_darwin_requires_legacy 10

github.setup        love2d love 11.5
revision            0
checksums           rmd160  6b19dcc47fd4c7cacfb046084f5912330c9b1f57 \
                    sha256  6f55c265be5e03696c4770150c4388f5cffbdb3727606724cf88332baab429f7 \
                    size    3639331

set branch          [lindex [split ${version} .] 0]
name                love-${branch}
categories          devel
maintainers         {ryandesign @ryandesign} openmaintainer
license             zlib

description         2D game development framework (${branch}.x branch)

long_description    LÖVE is a 2D game development framework. This port tracks the \
                    ${branch}.x branch.

homepage            https://love2d.org
github.tarball_from archive
dist_subdir         love

use_autoreconf      yes
autoreconf.cmd      platform/unix/automagic
autoreconf.args     -${branch}
autoreconf.env      "ACLOCAL=${prefix}/bin/aclocal" \
                    "AUTOHEADER=${prefix}/bin/autoheader" \
                    "AUTOCONF=${prefix}/bin/autoconf" \
                    "AUTOMAKE=${prefix}/bin/automake" \
                    "LIBTOOLIZE=${prefix}/bin/glibtoolize"

set lua_version     5.1

depends_build-append \
                    port:autoconf \
                    port:automake \
                    port:libtool \
                    port:makeicns \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:freetype \
                    port:libmodplug \
                    port:libogg \
                    port:libsdl2 \
                    port:libtheora \
                    port:libvorbis \
                    port:lua[string map {. {}} ${lua_version}] \
                    port:mpg123 \
                    port:openal-soft \
                    port:zlib

depends_run-append  port:love_select

select.group        love
select.file         ${filespath}/${name}

patchfiles          compile-mac-files.patch \
                    icon.patch \
                    libtool-tag.patch \
                    no-release.patch \
                    no-module.patch

post-patch {
    set re [list \
        "s|\\$\\(MARKETING_VERSION\\)|${version}|g" \
        "s|\\$\\(PRODUCT_BUNDLE_IDENTIFIER\\)|org.love2d.love|g" \
    ]
    reinplace -E [join ${re} {;}] ${worksrcpath}/platform/xcode/macosx/love-macosx.plist
}

# macosx.mm:104:7: error: unexpected '@' in program on macOS <10.12
# successful build on a non-Xcode Clang
compiler.cxx_standard \
                    2011
compiler.blacklist  {clang < 900}

configure.args      --disable-sdlframework \
                    --disable-static \
                    --disable-silent-rules \
                    --enable-shared \
                    --enable-osx \
                    --with-lua=lua \
                    --with-luaversion=${lua_version}

destroot.target     install-exec install-man

post-destroot {
    move ${destroot}${prefix}/share/man/man1/love.1 ${destroot}${prefix}/share/man/man6/${name}.6
    set app ${destroot}${applications_dir}/${name}.app
    xinstall -d ${app}/Contents/MacOS ${app}/Contents/Resources
    ln -s ${prefix}/bin/${name} ${app}/Contents/MacOS/love
    xinstall -m 0644 ${worksrcpath}/platform/xcode/macosx/love-macosx.plist ${app}/Contents/Info.plist
    system -W "${worksrcpath}/platform/xcode/Images.xcassets/OS X AppIcon.appiconset" \
        "${prefix}/bin/makeicns -512 512.png -256 256.png -128 128.png -32 32.png -16 16.png -out [shellescape "${app}/Contents/Resources/OS X AppIcon.icns"]"
    system -W "${worksrcpath}/platform/xcode/Images.xcassets/GameIcon.iconset" \
        "${prefix}/bin/makeicns -512 icon_512x512.png -256 icon_256x256.png -128 icon_128x128.png -32 icon_32x32.png -16 icon_16x16.png -out [shellescape "${app}/Contents/Resources/GameIcon.icns"]"
    set fp [open ${app}/Contents/PkgInfo w]
    puts -nonewline ${fp} {APPLLoVe}
    close ${fp}
}

github.livecheck.regex "(${branch}\\..*)"