# Description: Freely available NTFS driver with read and write support.
# URL: https://www.tuxera.com/company/open-source/
# Maintainer: John McQuah, jmcquah at disroot dot org
# Depends on: gnutls libgcrypt
# Optional: fuse

name=ntfs-3g
version=2022.10.3
release=3
source=(https://tuxera.com/opensource/${name}_ntfsprogs-$version.tgz)

build() {
  cd ${name}_ntfsprogs-$version

  # $DESTDIR/lib must exist during install; the Makefile honors
  # EPREFIX by moving to the desired location afterward
  mkdir $PKG/lib

  PKGMK_NTFS3="--prefix=/usr
    --exec-prefix=/usr
    --bindir=/usr/bin
    --sbindir=/usr/sbin
    --libexecdir=/usr/lib
    --enable-crypto
    --enable-extras
    --enable-ldscript
    --enable-posix-acls
    --enable-xattr-mappings
    --disable-ldconfig
    --disable-static
    --without-uuid
    --without-hd"
  prt-get isinst fuse && PKGMK_NTFS3+=" --with-fuse=external" \
    || PKGMK_NTFS3+=" --with-fuse=internal"

  ./configure $PKGMK_NTFS3

  make
  make DESTDIR=$PKG install

  ln -s /usr/bin/ntfs-3g $PKG/sbin/mount.ntfs
  ln -s ntfs-3g.8 $PKG/usr/share/man/man8/mount.ntfs.8
  ln -s ntfsfix.8 $PKG/usr/share/man/man8/fsck.ntfs.8

  # A wrapper script lets us silently discard any unsupported flags (from /etc/rc)
  cat >$PKG/sbin/fsck.ntfs <<\EOF
#!/bin/sh
ARGS="$(echo "$* " | sed 's/-a /-d /g; s/-p /-d /g; s/-f //g;')"
exec /usr/bin/ntfsfix $ARGS
EOF
  chmod 0755 $PKG/sbin/fsck.ntfs

  rm -r $PKG/usr/share/doc $PKG/usr/lib/$name $PKG/lib $PKG/usr/lib/*.la
}
