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

openssl.branch      1.1

name                retroshare-qt4
github.setup        RetroShare RetroShare 0.6.4 v
revision            1
# This is a legacy version aimed at systems which lack support for Qt5–Qt6.
platforms           {darwin < 17}
categories          www security p2p
# See: https://github.com/RetroShare/RetroShare/blob/master/.reuse/dep5
license             {AGPL-3 LGPL-3 GPL-3}
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer

description         RetroShare is a Free and Open Source cross-platform, \
                    Friend-2-Friend and secure decentralised communication platform
long_description    {*}${description}
homepage            https://retroshare.cc
checksums           rmd160  4025206f4b940b5a81e120ef526509778cfca350 \
                    sha256  84355c0f3be5ec1dfa7253e327ea1254f76f47739c233cfb8d0983ebd1a61f4a \
                    size    20018361
github.tarball_from archive

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  path:lib/pkgconfig/gnutls.pc:gnutls \
                    port:bzip2 \
                    port:gpgme \
                    port:libassuan \
                    port:libgpg-error \
                    port:libmicrohttpd \
                    port:miniupnpc \
                    port:sqlite3 \
                    port:zlib

patchfiles-append   0001-Fix-broken-linking-and-settings.patch \
                    0002-bdthreads.cc-fix-pointer-comparison.patch \
                    0003-Add-missing-headers.patch

# Backport of https://github.com/RetroShare/libretroshare/commit/f1b89c4f87d77714571b4135c301bf0429096a20
patchfiles-append   0004-fix-miniupnpc-18.patch

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" \
                    ${worksrcpath}/libresapi/src/libresapi.pro \
                    ${worksrcpath}/libretroshare/src/libretroshare.pro \
                    ${worksrcpath}/retroshare.pri \
                    ${worksrcpath}/retroshare-gui/src/retroshare-gui.pro \
                    ${worksrcpath}/retroshare-nogui/src/retroshare-nogui.pro
    reinplace "s|@TARGET@|${macosx_deployment_target}|g" \
                    ${worksrcpath}/retroshare.pri
}

compiler.cxx_standard 2011

# RetroShare can be configured to use either miniupnpc or libupnp. Having both active breaks linking. To be on a safe side, also deactivate gupnp.
# Our libretroshare port tracks the upstream. It may not be compatible with a legacy or even current release of RetroShare.
conflicts_build     gupnp libupnp libretroshare

configure.pre_args-append \
                    "CONFIG+=rs_v07_changes" \
                    "CONFIG+=no_sqlcipher"

# api/ApiServerMHD.cpp: error: invalid conversion from 'int (*)(void*, MHD_ValueKind, const char*, const char*)' to 'MHD_KeyValueIterator' {aka 'MHD_Result (*)(void*, MHD_ValueKind, const char*, const char*)'} [-fpermissive]
if {[string match *gcc* ${configure.compiler}]} {
    configure.cxxflags-append \
                    -fpermissive
}

destroot {
    set docdir ${prefix}/share/doc/retroshare/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} LICENSE.txt README.md TODO.txt ${destroot}${docdir}
    move ${worksrcpath}/retroshare-gui/src/retroshare.app ${destroot}${applications_dir}/retroshare.app
}
