# Description: FUSE-based transcoding filesystem from many formats to MP3 or MP4 including video transcoding.
# URL: https://nschlia.github.io/ffmpegfs/
# Maintainer: UNMAINTAINED
# Depends on: chromaprint fuse lame libchardet libcue libgmp libpcre util-linux
# Optional: asciidoc w3m fdk-aac libass libbluray libdvdnav libdvdread x264 x265 expat fontconfig freetype fribidi glib gnutls harfbuzz libffi libidn2 libogg libpng libtasn1 libtheora libunistring libva libvorbis libvpx libwebp libxml2 nettle opus p11-kit libdrm libvdpau xorg-libx11 xorg-libxau xorg-libxcb xorg-libxdmcp xorg-libxext xorg-libxfixes

name=ffmpegfs
version=2.14
release=1
source=(https://github.com/nschlia/ffmpegfs/archive/v$version/ffmpegfs-$version.tar.gz ffmpegfshelp.h)

build() {
  # upstream left this field unchanged since the last release
  sed -e '/^project(.* VERSION .*)/s/2.13/2.14/' -i $name-$version/CMakeLists.txt

  # do not hard-depend on conversion tools, just to build the manpage
  prt-get isinst asciidoc w3m || { sed -e '/add_dependencies(.* manpage)/s/^/#/' \
    -e '/add_dependencies(.* manpage-header)/s/^/#/' \
    -e '/add_dependencies(.* manpage-text)/s/^/#/' \
    -e '/\s+src\/ffmpegfs.h$/a src/ffmpegfshelp.h' \
    -i $name-$version/CMakeLists.txt;
    cp $SRC/ffmpegfshelp.h $name-$version/src; }

  # do not try to link against libraries that are not installed
  prt-get isinst libbluray || sed '/\s*bluray$/d' -i $name-$version/CMakeLists.txt
  prt-get isinst libdvdread || sed '/\s*dvdread$/d' -i $name-$version/CMakeLists.txt
  prt-get isinst libdvdnav || sed '/\s*dvdnav$/d' -i $name-$version/CMakeLists.txt

  cmake -S $name-$version -B build -G Ninja \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \
    -D CMAKE_C_FLAGS_RELEASE="$CFLAGS" \
    -Wno-dev

  ninja -C build -j ${JOBS:-1}
  DESTDIR=$PKG ninja -C build install
}
