# Maintainer: Felitendo
# This PKGBUILD is updated automatically:
# https://github.com/Felitendo/PKGBUILDS

pkgname=concat-bin
pkgver=0.2.1
pkgrel=1
pkgdesc="Free and open-source CapCut replacement, a video editor with a Rust engine (upstream binary)"
arch=('x86_64')
url="https://github.com/jub0t/Concat"
# The binary is Concat under the AGPL; the FFmpeg libraries it ships beside
# itself are a BtbN GPL build. Both licence texts land in the package: the
# repository's LICENSE, and upstream's notices file, which is what names the
# terms of everything linked in - FFmpeg, Slint under its GPL option,
# whisper.cpp, sherpa-onnx.
license=('AGPL-3.0-or-later' 'GPL-3.0-or-later')
# Nothing is spawned at run time any more: FFmpeg is linked, whisper.cpp and
# sherpa-onnx are compiled in. What is left is what the binary loads - the
# ALSA backend of cpal, fontconfig and freetype for text, and the windowing
# libraries winit and the renderer open by name: EGL, Wayland, X11 and
# xkbcommon. dbus is the XDG portal, which is how the file dialogs and
# "reveal in file manager" work without a toolkit.
depends=('alsa-lib' 'fontconfig' 'freetype2' 'libglvnd' 'libxkbcommon'
         'libxkbcommon-x11' 'libx11' 'libxcursor' 'libxi' 'libxrender'
         'wayland' 'dbus' 'gcc-libs' 'glibc' 'hicolor-icon-theme')
provides=('concat')
conflicts=('concat')
# !strip: upstream's binary is already stripped, and the FFmpeg libraries
# beside it are theirs to ship as they are.
options=('!strip' '!debug')
# Upstream's Linux release is one self-contained folder: the binary, the
# FFmpeg 8.1 runtime libraries it was linked against, a desktop entry and an
# icon. The libraries have to come along - the binary needs libavcodec.so.62
# and Arch is on FFmpeg 9 (libavcodec.so.63) - so the whole folder is
# installed under /usr/lib/$pkgname, where the binary's own rpath
# ($ORIGIN/lib) finds them.
#
# The asset name carries the workspace's version rather than the tag (a
# prerelease of 0.2.2 ships Concat-0.2.2-linux-x86_64.tar.gz whatever its tag
# says), so it is resolved through the GitHub API and synced here along with
# the checksum; see pkg.sh.
_tag="v0.2.1"
_asset="Concat-0.2.1-linux-x86_64.tar.gz"
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/jub0t/Concat/releases/download/${_tag}/${_asset}")
sha256sums=('949c30dee52ba779d5d91777510cfd57580b67467d841bd2957956219886df6f')

package() {
  cd "${_asset%.tar.gz}"

  install -Dm755 concat "$pkgdir/usr/lib/$pkgname/concat"
  # cp, not install: lib/ is the usual set of FFmpeg soname symlinks beside
  # the real files, and only a copy that preserves them keeps it working.
  cp -a lib "$pkgdir/usr/lib/$pkgname/lib"

  install -d "$pkgdir/usr/bin"
  ln -s "/usr/lib/$pkgname/concat" "$pkgdir/usr/bin/concat"

  install -Dm644 concat.desktop "$pkgdir/usr/share/applications/concat.desktop"
  install -Dm644 concat.png \
    "$pkgdir/usr/share/icons/hicolor/256x256/apps/concat.png"

  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm644 THIRD_PARTY_NOTICES.md \
    "$pkgdir/usr/share/licenses/$pkgname/THIRD_PARTY_NOTICES.md"
}
