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

github.setup        tuxera ntfs-3g 2022.10.3
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            0
categories          fuse
maintainers         nomaintainer
license             GPL-2+ LGPL-2
description         Safe read/write NTFS driver for FUSE
long_description    The NTFS-3G driver is an open source, freely available \
                    NTFS driver for FUSE with read and write support. It \
                    provides safe and fast handling of the Windows XP, Windows \
                    Server 2003, Windows 2000 and Windows Vista file systems. \
                    Most POSIX file system operations are supported, with the \
                    exception of full file ownership and access right support. \
                    Also included are ntfsprogs, a set of utilities to create \
                    and manipulate NTFS file systems.

homepage            https://www.tuxera.com/company/open-source/
distname            ntfs-3g_ntfsprogs-${version}
extract.suffix      .tgz

master_sites        https://tuxera.com/opensource/

checksums           rmd160  4f17aecd0a9e6ff1fd44e434d0484ac1e784ef1e \
                    sha256  f20e36ee68074b845e3629e6bced4706ad053804cbaf062fbae60738f854170c \
                    size    1324320

depends_lib-append  port:ossp-uuid

# Fixes since this release
patchfiles-append   patch-master.diff
patch.args          -p1
# Use default PKG_CONFIG_PATH to avoid picking up a FUSE installation
# in /usr/local (see #30537)
post-patch {
    reinplace "s|export PKG_CONFIG_PATH=\.*||g" ${worksrcpath}/configure
}

# do not try to use this function in macOS 10.13 to avoid compilation error
# (older versions don't have this function)
if {${os.platform} eq "darwin" && ${os.major} <= 17} {
    configure.env   ac_cv_func_utimensat=no
}
configure.args-append \
                    --exec-prefix=${prefix} \
                    --with-fuse=external \
                    --with-uuid \
                    --enable-posix-acls \
                    --enable-xattr-mappings \
                    --disable-silent-rules

platform darwin {
    depends_lib-append \
                    port:gettext-runtime
    configure.ldflags-append \
                    -framework CoreFoundation \
                    -lintl
}

pre-destroot {
    file mkdir ${destroot}/sbin
}

variant extra_progs description {Install extra ntfsprog tools} {
    depends_lib-append \
                    port:libgcrypt \
                    port:gnutls \
                    port:libgpg-error

    configure.args-append \
                    --enable-extras \
                    --enable-quarantined \
                    --enable-crypto
}

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

    destroot.violate_mtree \
                        yes

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

notes "
    To make this port work in the Finder, see this link: <https://trac.macports.org/wiki/howto/Ntfs3gFinder>
    Note: Method described here may not work for modern macOS
"
