# Contributor: Chris Leishman <chris@leishman.org>
# Maintainer: Chris Leishman <chris@leishman.org>
pkgname=libneo4j-client
pkgver=2.2.0
pkgrel=0
pkgdesc="Client library for the Neo4j graph database"
url="https://github.com/cleishm/libneo4j-client"
arch="x86_64 aarch64 ppc64le"
license="Apache-2.0"
depends="openssl"
depends_dev="libressl-dev"
makedepends="$depends_dev automake autoconf libtool check-dev doxygen pkgconfig fts fts-dev libedit-dev libcypher-parser-dev"
install=""
subpackages="$pkgname-dev $pkgname-doc::noarch neo4j-client:client neo4j-client-doc::noarch"
source="https://github.com/cleishm/libneo4j-client/releases/download/v$pkgver/$pkgname-$pkgver.tar.gz"

builddir="$srcdir"/"$pkgname-$pkgver"
build() {
    cd "$builddir"
    ./configure \
            --prefix=/usr
    make
    make doc
}

check() {
    cd "$builddir"
    make LIBS="-lfts" check
}

package() {
    cd "$builddir"
    make DESTDIR="$pkgdir" install
    mkdir -p "$pkgdir"/usr/share/doc/libneo4j-client
    mv doc/html/* "$pkgdir"/usr/share/doc/libneo4j-client/
}

doc() {
    depends="$depends_doc"
    pkgdesc="$pkgdesc (documentation)"
    install_if="docs $pkgname=$pkgver-r$pkgrel"

    if [ "$subpkgname" = "libneo4j-client-doc" ]; then
        mkdir -p "$subpkgdir"/usr/share
        mv "$pkgdir"/usr/share/doc "$subpkgdir"/usr/share/
    elif [ "$subpkgname" = "neo4j-client-doc" ]; then
        mkdir -p "$subpkgdir"/usr/share
        mv "$pkgdir"/usr/share/man "$subpkgdir"/usr/share/
        find "$subpkgdir"/usr/share/man/ -type f | xargs gzip -9
    else
        die "Unknown doc package $pkgname"
    fi

    # remove if empty, ignore error (not empty)
    rmdir "$pkgdir"/usr/share "$pkgdir"/usr || true 2>/dev/null
    return 0
}

client() {
    depends="libedit libcypher-parser"
    pkgdesc="Command line shell for Neo4j"

    mkdir -p "$subpkgdir"/usr
    mv "$pkgdir"/usr/bin "$subpkgdir"/usr/

    # remove if empty, ignore error (not empty)
    rmdir "$pkgdir"/usr/bin "$pkgdir"/usr 2>/dev/null || true
    return 0
}

sha512sums="973f8e49ee780b9ef8710dad057f264db1004523059ece5504af32c2ba5367e9199898d24aa133c017c953b0b750b2a23495765069c9a5ad470e8387a0eb4d9a  libneo4j-client-2.2.0.tar.gz"
