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

# clock_gettime in game_base
legacysupport.newest_darwin_requires_legacy 15

github.setup            JFreegman toxic 0.16.0 v
revision                0
categories              net security
maintainers             {@barracuda156 gmail.com:vital.had} openmaintainer
license                 GPL-3
description             An ncurses-based Tox client
long_description        Toxic is a Tox-based instant messaging and video chat client.
homepage                https://toktok.ltd
checksums               rmd160  84c845622d9073da19a9138f524adfdf179f1837 \
                        sha256  9b58f87941c5638e6169f972292351205bb6335bde8121c103d7dc6fc5174ac7 \
                        size    1246725
github.tarball_from     archive

depends_build-append    path:bin/pkg-config:pkgconfig
depends_lib-append      path:lib/pkgconfig/glib-2.0.pc:glib2 \
                        port:curl \
                        port:desktop-file-utils \
                        port:freealut \
                        port:libconfig-hr \
                        port:libnotify \
                        port:libpng \
                        port:ncurses \
                        port:openal-soft \
                        port:qrencode \
                        port:toxcore \
                        port:xorg-libX11

patchfiles              0001-Makefile-add-PPC.patch \
                        0002-Config-make-paths-sane.patch \
                        0003-Darwin.mk-do-not-hardcode-flags-to-unbreak-older-mac.patch \
                        0004-Fix-macOS-linking.patch
if {${os.platform} eq "darwin" && ${os.major} < 11} {
    patchfiles-append   0005-Remove-hardcoded-osx_video.patch
}

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/cfg/global_vars.mk
    platform darwin {
        reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/cfg/systems/Darwin.mk
        reinplace "s|@LIBS@|-lobjc -lresolv -lX11|" ${worksrcpath}/cfg/systems/Darwin.mk
        if {${os.major} > 10} {
            reinplace "s|@FRAMEWORKS@|-framework Foundation -framework CoreFoundation -framework AVFoundation -framework QuartzCore -framework CoreMedia|" ${worksrcpath}/cfg/systems/Darwin.mk
        } else {
            # Remove unsupported stuff:
            reinplace "s|@FRAMEWORKS@|-framework Foundation -framework CoreFoundation -framework QuartzCore|" ${worksrcpath}/cfg/systems/Darwin.mk
            reinplace "s|osx_video.m||" ${worksrcpath}/cfg/systems/Darwin.mk
            reinplace "s|osx_video.o||" ${worksrcpath}/cfg/systems/Darwin.mk
        }
    }
}

compiler.c_standard     2011

build.env-append        DESTDIR=${destroot}${prefix} \
                        DISABLE_AV=1 \
                        DISABLE_DESKTOP_NOTIFY=0 \
                        DISABLE_GAMES=0 \
                        DISABLE_QRCODE=0 \
                        DISABLE_QRPNG=0 \
                        DISABLE_SOUND_NOTIFY=0 \
                        DISABLE_X11=0 \
                        ENABLE_ASAN=0 \
                        ENABLE_PYTHON=0 \
                        ENABLE_RELEASE=1
build.target

notes "
Running Toxic for the first time creates an empty file called toxic.conf\
in ~/Library/Application Support/tox. Adding options to this file allows you\
to enable auto-logging, change the time format and much more.\
You can view a config file example here:\
https://github.com/TokTok/toxic/blob/master/misc/toxic.conf.example
"

destroot.env            DESTDIR=${destroot}${prefix} \
                        DISABLE_AV=1 \
                        DISABLE_DESKTOP_NOTIFY=0 \
                        DISABLE_GAMES=0 \
                        DISABLE_QRCODE=0 \
                        DISABLE_QRPNG=0 \
                        DISABLE_SOUND_NOTIFY=0 \
                        DISABLE_X11=0 \
                        ENABLE_ASAN=0 \
                        ENABLE_PYTHON=0 \
                        ENABLE_RELEASE=1
destroot.target         install

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}
