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

github.setup        Pingus pingus ad462706e5fc2cd5bf1cf99b2d90f88fe9e6de6e
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             0.8.0-20180714
revision            3
categories          games
maintainers         nomaintainer
license             GPL-3

description         A free Lemmings(tm) clone using SDL2.
long_description    {*}${description} It is a puzzle game where the player \
                    has to guide a group of penguins to safety.

fetch.type          git
post-extract {
    system -W ${worksrcpath} "git submodule update --init"
}

depends_build-append \
                    port:pkgconfig

depends_lib-append  port:libiconv \
                    port:libsdl2 \
                    port:libsdl2_image \
                    port:libsdl2_mixer \
                    port:libpng \
                    port:jsoncpp

compiler.cxx_standard   2014

configure.ldflags-append \
                    -liconv \
                    -framework CoreFoundation

cmake.out_of_source yes

configure.args-append -DCMAKE_INSTALL_PREFIX:PATH="${applications_dir}/Pingus.app/Contents/MacOS"

# boost no longer has the signals library
patchfiles-append   patch-pingus-no-boost-signals.diff

# error: 'shared_ptr' in namespace 'std' does not name a template type
patchfiles-append   patch-xdg-header.diff

platform darwin powerpc {
    patchfiles-append    patch-cmakelists-gnu14.diff
}

platform darwin 8 {
    patchfiles-append    patch-fix-build-tiger.diff
}

pre-destroot {
    xinstall -d ${destroot}${applications_dir}/Pingus.app/Contents/Resources \
                ${destroot}${applications_dir}/Pingus.app/MacOS
    file copy ${worksrcpath}/data/images/icons/pingus-icon.icns ${destroot}${applications_dir}/Pingus.app/Contents/Resources/pingus.icns
    file copy ${worksrcpath}/Info.plist "${destroot}${applications_dir}/Pingus.app/Contents/Info.plist"
}

post-destroot {
    file copy ${destroot}${applications_dir}/Pingus.app/Contents/MacOS/bin/pingus ${destroot}${applications_dir}/Pingus.app/Contents/MacOS/pingus
    reinplace "s|\"$@\"||g" ${destroot}${applications_dir}/Pingus.app/Contents/MacOS/pingus

    # Fix a locale-related crash, a persistent issue with gcc7 on Tiger
    platform darwin 8 {
        reinplace "s|#!/bin/sh|#!/usr/bin/env DYLD_LIBRARY_PATH=${prefix}/lib/libgcc /bin/sh|" ${destroot}${applications_dir}/Pingus.app/Contents/MacOS/pingus
    }
}
