# $Id$
# Maintainer: MediaArea.net SARL <info@mediaarea.net>

pkgname=('bwfmetaedit' 'bwfmetaedit-plugin-c2pa' 'bwfmetaedit-gui')
pkgver=26.08.20260829
pkgrel=1
pkgdesc="Supplies technical and tag information about a video or audio file"
arch=('x86_64')
url="https://mediaarea.net/BWFMetaEdit"
license=('GPL')

makedepends=('qt5-base' 'qt5-quickcontrols2' 'qt5-svg' 'qt5-tools' 'ca-certificates' 'rust')
source=(${pkgname}_${pkgver}.tar.xz bwfmetaedit-vendor_${pkgver}.tar.xz)
sha256sums=('SKIP' 'SKIP')

prepare() {
    cd "${srcdir}"/bwfmetaedit/Source/ThirdParty/c2pa-rs
    rm -rf vendor
    tar -xf "${srcdir}"/bwfmetaedit-vendor_${pkgver}.tar.xz
    mkdir .cargo
    printf '[source.crates-io]\nreplace-with = "vendored-sources"\n\n[source.vendored-sources]\ndirectory = "vendor"\n' > .cargo/config.toml

    cd "${srcdir}"/bwfmetaedit/Project/GNU/CLI
    sh ./autogen
    LDFLAGS="$LDFLAGS -Wl,-rpath,/usr/lib/bwfmetaedit" ./configure --prefix=/usr --enable-c2pa=dynamic

    cd "${srcdir}"/bwfmetaedit/Project/QtCreator
    sh ./prepare ENABLE_C2PA=dynamic QMAKE_RPATHDIR+=/usr/lib/bwfmetaedit BINDIR=/usr/bin
}

build() {
    cd "${srcdir}"/bwfmetaedit/Source/ThirdParty/c2pa-rs
    CARGO_HOME="${srcdir}"/cargo_home CARGO_NET_OFFLINE=true \
        cargo build --release --offline --locked -p c2pa-c-ffi --no-default-features --features "rust_native_crypto, http, file_io"
    strip target/release/libc2pa_c.so

    cd "${srcdir}"/bwfmetaedit/Project/GNU/CLI
    make

    cd "${srcdir}"/bwfmetaedit/Project/QtCreator
    make
}

package_bwfmetaedit() {
    pkgdesc="${pkgdesc} (CLI)"

    cd "${srcdir}"/bwfmetaedit/Project/GNU/CLI
    make DESTDIR="${pkgdir}" install

    install -D -m 0644 "${srcdir}"/bwfmetaedit/License.html "${pkgdir}"/usr/share/licenses/${pkgname}/License.html
    install -D -m 0644 "${srcdir}"/bwfmetaedit/History_CLI.txt "${pkgdir}"/usr/share/doc/${pkgname}/History.txt
    install -D -m 0644 "${srcdir}"/bwfmetaedit/Release/ReadMe_CLI_Linux.txt "${pkgdir}"/usr/share/doc/${pkgname}/ReadMe.txt
    install -D -m 0644 "${srcdir}"/bwfmetaedit/conformance_point_document.xsd "${pkgdir}"/usr/share/doc/${pkgname}/conformance_point_document.xsd
}

package_bwfmetaedit-plugin-c2pa() {
    pkgdesc="C2PA (Content Credentials) support library for BWF MetaEdit"

    install -D -m 0755 "${srcdir}"/bwfmetaedit/Source/ThirdParty/c2pa-rs/target/release/libc2pa_c.so "${pkgdir}/usr/lib/bwfmetaedit/libc2pa_c.so"
    install -D -m 0644 "${srcdir}"/bwfmetaedit/License.html "${pkgdir}"/usr/share/licenses/${pkgname}/License.html
}

package_bwfmetaedit-gui() {
    pkgdesc="${pkgdesc} (GUI)"
    depends=('qt5-base' 'qt5-quickcontrols2' 'qt5-svg')

    cd "${srcdir}"/bwfmetaedit/Project/QtCreator
    make INSTALL_ROOT="${pkgdir}" install

    install -D -m 0644 "${srcdir}"/bwfmetaedit/License.html "${pkgdir}"/usr/share/licenses/${pkgname}/License.html
    install -D -m 0644 "${srcdir}"/bwfmetaedit/History_GUI.txt "${pkgdir}"/usr/share/doc/${pkgname}/History.txt
    install -D -m 0644 "${srcdir}"/bwfmetaedit/Release/ReadMe_GUI_Linux.txt "${pkgdir}"/usr/share/doc/${pkgname}/ReadMe.txt
    install -D -m 0644 "${srcdir}"/bwfmetaedit/conformance_point_document.xsd "${pkgdir}"/usr/share/doc/${pkgname}/conformance_point_document.xsd

    install -D -m 0644 "${srcdir}"/bwfmetaedit/Source/Resource/Image/Logo/Logo128.png "${pkgdir}"/usr/share/icons/hicolor/128x128/apps/bwfmetaedit-gui.png
    install -D -m 0644 "${srcdir}"/bwfmetaedit/Source/Resource/Image/Logo/Logo128.png "${pkgdir}"/usr/share/pixmaps/bwfmetaedit-gui.png
    install -D -m 0644 "${srcdir}"/bwfmetaedit/Project/GNU/GUI/bwfmetaedit-gui.desktop "${pkgdir}"/usr/share/applications/bwfmetaedit-gui.desktop
    install -D -m 0644 "${srcdir}"/bwfmetaedit/Project/GNU/GUI/bwfmetaedit-gui.metainfo.xml "${pkgdir}"/usr/share/metainfo/bwfmetaedit-gui.metainfo.xml
    install -D -m 0644 "${srcdir}"/bwfmetaedit/Project/GNU/GUI/bwfmetaedit-gui.kde3.desktop "${pkgdir}"/usr/share/apps/konqueror/servicemenus/bwfmetaedit-gui.desktop
    install -D -m 0644 "${srcdir}"/bwfmetaedit/Project/GNU/GUI/bwfmetaedit-gui.kde4.desktop "${pkgdir}"/usr/share/kde4/services/ServiceMenus/bwfmetaedit-gui.desktop
    install -D -m 0644 "${srcdir}"/bwfmetaedit/Project/GNU/GUI/bwfmetaedit-gui.kde4.desktop "${pkgdir}"/usr/share/kservices5/ServiceMenus/bwfmetaedit-gui.desktop
}
