# -*- 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           boost 1.0
PortGroup           fuse 1.0
PortGroup           github 1.0
PortGroup           openssl 1.0

# Keep this in sync with boost version used for libtorrent-rasterbar
boost.version       1.81
boost.depends_type  build

github.setup        johang btfs 3.1 v
revision            0
categories          fuse net
license             GPL-3
maintainers         {i0ntempest @i0ntempest} openmaintainer

description         Bittorrent filesystem based on FUSE
long_description    With ${name}, you can mount any .torrent file or magnet link and then use it \
                    as any read-only directory in your file tree. The contents of the files will \
                    be downloaded on-demand as they are read by applications.

checksums           rmd160  f34ad8ce516fbb71966941bdb030116bb237d184 \
                    sha256  c363f04149f97baf1c5e10ac90677b8309724f2042ab045a45041cfb7b44649b \
                    size    24847
github.tarball_from archive

depends_lib-append  port:curl \
                    port:libtorrent-rasterbar

patch.args          -p1
# Revert upgrade to fuse 3
patchfiles-append   patch-revert-e0659b09a9e4f8c5f04382e33d0c2940940bb9dd.diff

patchfiles-append   patch-83.diff
          
post-patch {
    # Do not install btplay script - requires fusermount, unusable on macos
    reinplace "s|scripts/Makefile ||" ${worksrcpath}/configure.ac
    reinplace "s|scripts ||" ${worksrcpath}/Makefile.am
    reinplace "s|-std=c++14|-std=gnu++14|" ${worksrcpath}/src/Makefile.am
    reinplace "s|__APPLE__|__IGNORE__|" ${worksrcpath}/src/btfs.cc
}

use_autoreconf      yes

configure.args-append \
                    --disable-silent-rules

compiler.cxx_standard \
                     2014

# btfs.cc:1007:29: error: invalid conversion from 'int (*)(const char*, const char*, char*, size_t)' {aka 'int (*)(const char*, const char*, char*, long unsigned int)'}
# to 'int (*)(const char*, const char*, char*, size_t, uint32_t)' {aka 'int (*)(const char*, const char*, char*, long unsigned int, unsigned int)'} [-fpermissive]
if {[string match *gcc* ${configure.compiler}]} {
    configure.cxxflags-append \
                     -fpermissive
}

variant fs_link description "Link ${name} to a .fs bundle in /Library/Filesystems" {
    post-destroot {
        set dir /Library/Filesystems/${name}.fs/Contents/Resources
        xinstall -d ${destroot}${dir}
        ln -s ${prefix}/bin/${name} ${destroot}${dir}/mount_${name}
    }

    destroot.violate_mtree \
                    yes

    notes-append "
        With +fs_link, you may use \'mount -t ${name}\' and use ${name} in /etc/fstab.
    "
}
