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

github.setup        transmission transmission 4.1.3
revision            0
name                ${github.project}-gtk
conflicts           ${github.project}-qt
categories          net x11 p2p
platforms           {darwin >= 9}
license             {GPL-2 OpenSSLException}
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Lightweight BitTorrent client
long_description    Transmission is a free, lightweight BitTorrent client. \
                    It features a simple, intuitive interface on top of \
                    an efficient, cross-platform back-end. Transmission is open \
                    source (MIT license) and runs on Mac OS X (Cocoa interface), \
                    Linux/NetBSD/FreeBSD/OpenBSD (GTK+ interface) and BeOS \
                    (native interface). This is the GTK+ version.

homepage            https://transmissionbt.com

checksums           rmd160  5e3a1af36cb50b42253424ba2d1fd7e757a62e0b \
                    sha256  ce7d2d8b101f7eb54bc3cf0bc55f52f7ebd4a25fa48e00bdca9a7e0fc02617da \
                    size    11845312

github.tarball_from releases
use_xz              yes

# Do not remove this as it allows transmission and this port to share files
dist_subdir         transmission

depends_build-append \
                    port:gettext \
                    port:intltool \
                    port:libtool \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:curl \
                    port:gettext-runtime \
                    port:libb64 \
                    port:libdeflate \
                    port:libevent \
                    port:libnatpmp \
                    port:libpsl \
                    port:miniupnpc \
                    port:zlib

# TODO: consider switching away from bundled deps.
# set libfmt_v        12
# cmake.prefix_path-append \
#                     ${prefix}/lib/libfmt${libfmt_v}/cmake
# depends_lib-append  port:fast-float \
#                     port:libfmt${libfmt_v} \
#                     path:lib/pkgconfig/RapidJSON.pc:rapidjson \
#                     port:utfcpp

if {[variant_isset gtk3] || [variant_isset gtk4]} {
    depends_run-append \
                    port:adwaita-icon-theme \
                    port:desktop-file-utils
}

configure.args-append \
                    -DENABLE_CLI=ON \
                    -DENABLE_DAEMON=ON \
                    -DENABLE_GTK=OFF \
                    -DENABLE_MAC=OFF \
                    -DENABLE_NLS=ON \
                    -DENABLE_QT=OFF \
                    -DENABLE_TESTS=OFF \
                    -DENABLE_UTILS=ON \
                    -DENABLE_UTP=ON \
                    -DINSTALL_DOC=OFF \
                    -DUSE_SYSTEM_B64=ON \
                    -DUSE_SYSTEM_DEFLATE=ON \
                    -DUSE_SYSTEM_DHT=OFF \
                    -DUSE_SYSTEM_EVENT2=ON \
                    -DUSE_SYSTEM_MINIUPNPC=ON \
                    -DUSE_SYSTEM_NATPMP=ON \
                    -DUSE_SYSTEM_PSL=ON \
                    -DUSE_SYSTEM_UTP=OFF \
                    -DWITH_APPINDICATOR=OFF \
                    -DWITH_CRYPTO="openssl"

compiler.c_standard     2011
compiler.cxx_standard   2020

default_variants    +gtk4

# transmission-gtk(47187) malloc: *** error for object 0x33480a4: Non-aligned pointer being freed
legacysupport.redirect_bins transmission-cli transmission-create transmission-daemon transmission-edit transmission-gtk transmission-remote transmission-show

variant gtk3 description "Build Gtk3 front-end" {
    depends_lib-append      path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                            port:gtkmm3 \
                            port:libnotify

    configure.args-replace  -DENABLE_GTK=OFF -DENABLE_GTK=ON
    configure.args-append   -DUSE_GTK_VERSION=3

    post-activate {
        system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
        system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
    }
}

variant gtk4 description "Build Gtk4 front-end" {
    depends_lib-append      path:lib/pkgconfig/gtk4.0.pc:gtk4 \
                            port:gtkmm4 \
                            port:libnotify

    configure.args-replace  -DENABLE_GTK=OFF -DENABLE_GTK=ON
    configure.args-append   -DUSE_GTK_VERSION=4

    post-activate {
        system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
        system "${prefix}/bin/gtk4-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
    }
}
