# Maintainer: Adrian <adrian@mxlinux.org>
pkgname=mx-tools
pkgver=26.09.7arch
pkgrel=2
pkgdesc="MX Tools - Dashboard application launcher for various MX tools"
arch=('x86_64')
url="https://github.com/MX-Linux/mx-tools"
license=('GPL3')
depends=('qt6-base' 'qt6-declarative')
makedepends=('cmake' 'ninja' 'qt6-declarative' 'qt6-tools')
source=("https://github.com/MX-Linux/mx-tools/archive/refs/tags/26.09.7arch.tar.gz")
sha256sums=('f3e26921d607d8aee0b86bd0e004c6c87b7919d1a14965daabea3b9acb0a6cbd')

_srcdir="${pkgname}-${pkgver}"

build() {
    cd "${srcdir}/${_srcdir}"

    rm -rf build

    cmake -G Ninja \
        -B build \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
        -DPROJECT_VERSION_OVERRIDE="${pkgver}"

    cmake --build build --parallel
}

package() {
    cd "${srcdir}/${_srcdir}"

    install -Dm755 build/mx-tools "${pkgdir}/usr/bin/mx-tools"

    install -dm755 "${pkgdir}/usr/share/mx-tools/locale"
    install -Dm644 -t "${pkgdir}/usr/share/mx-tools/locale/" build/*.qm 2>/dev/null || true

    install -Dm644 data/mx-tools.desktop "${pkgdir}/usr/share/applications/mx-tools.desktop"

    # The "MX Tools" submenu. On Debian these come from desktop-defaults-mx-common;
    # the file names differ from that package's so both can be installed without a
    # pacman file conflict - menus sharing a <Name> are merged and their include
    # rules accumulate.
    install -Dm644 data/menu/mx-tools-menu.directory \
        "${pkgdir}/usr/share/desktop-directories/mx-tools-menu.directory"
    install -Dm644 data/menu/mx-tools-menu.menu \
        "${pkgdir}/etc/xdg/menus/applications-merged/mx-tools-menu.menu"

    install -Dm644 icons/mx-tools.png "${pkgdir}/usr/share/icons/hicolor/96x96/apps/mx-tools.png"
    install -Dm644 icons/mx-tools.svg "${pkgdir}/usr/share/icons/hicolor/scalable/apps/mx-tools.svg"

    install -dm755 "${pkgdir}/usr/share/doc/mx-tools"

    install -dm755 "${pkgdir}/usr/share/man/man1"
    install -Dm644 -t "${pkgdir}/usr/share/man/man1/" help/*.1 2>/dev/null || true
    if [ -d help ]; then
        for help_file in help/*.html help/*.jpg help/*.png help/*.css; do
            [ -f "$help_file" ] && install -Dm644 "$help_file" "${pkgdir}/usr/share/doc/mx-tools/$(basename "$help_file")"
        done
    fi
    install -Dm644 help/license.html "${pkgdir}/usr/share/doc/mx-tools/license.html"
    gzip -c debian/changelog > "${pkgdir}/usr/share/doc/mx-tools/changelog.gz"

    install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
