# -*- 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.8 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  b4d586f70986ac9d2337b90d3782218ba9c4e22e \
                    sha256  78f6a4ab1a5e3e16d300ec92622f6f42269cee460671e307fb16478406d8bb54 \
                    size    901180

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
}

# dns_cache.h:42:8: error: no template named 'unordered_map' in namespace 'std'
patchfiles-append   patch-dns-cache-unordered-map.diff

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

compiler.cxx_standard   2017

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}
}
