# -*- 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

# Note - releases for libtorrent are provided at https://github.com/rakshasa/rtorrent
# rather than at the projects own repo, https://github.com/rakshasa/libtorrent
github.setup        rakshasa rtorrent 0.16.14 v
github.tarball_from releases
name                libtorrent
distname            libtorrent-${github.version}
homepage            https://github.com/rakshasa/libtorrent
revision            0

conflicts           libtorrent-devel
categories          net
maintainers         nomaintainer
license             {GPL-2+ OpenSSLException}

description         BitTorrent library

long_description    libTorrent is a BitTorrent library written in C++ for \
                    *nix. It is designed to avoid redundant copying and \
                    storing of data that other clients and libraries suffer from.

checksums           rmd160  7deecc5a2241ddb65757aeaf3fcddea77c11a793 \
                    sha256  289f1992d8c633f82faa3ed47b2eeb9482c290c0c82b8bf6daa1d3784f68c86a \
                    size    910536

use_autoreconf      yes

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

depends_lib-append  port:curl \
                    path:lib/libssl.dylib:openssl

# malformed object (unknown load command 2)
if {${os.platform} eq "darwin" && ${os.major} <= 10} {
    depends_build-append port:cctools
}

# system/thread.cc:155:7: error: 'notify_all' is
# unavailable: introduced in macOS 11.0
if {${os.platform} eq "darwin" && ${os.major} < 20} {
    if {[string match *clang* ${configure.compiler}]} {
        configure.cxxflags-append \
                    -D_LIBCPP_DISABLE_AVAILABILITY
    }
}

# http_stack.cc:17:13: error: aligned allocation function of type 'void
# *(std::size_t, std::align_val_t)' is only available on macOS 10.13 or newer
if {${os.platform} eq "darwin" && ${os.major} < 17} {
    if {[string match *clang* ${configure.compiler}]} {
        configure.cxxflags-append \
                    -fno-aligned-allocation
    }
}

# Starting with version 0.16.13, a compiler that supports C++20 is mandatory
compiler.cxx_standard   2020

configure.args      --disable-debug \
                    --with-kqueue \
                    --enable-ipv6

post-destroot {
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} AUTHORS COPYING README.md ${destroot}${docdir}
}
