# Maintainer: Martchus <martchus@gmx.net>

# All my PKGBUILDs are managed at https://github.com/Martchus/PKGBUILDs where
# you also find the URL of a binary repository.

_reponame=arch-repo-manager
pkgname=arch-repo-manager-git
_name=${pkgname%-git}
pkgver=340.599185d
pkgrel=2
arch=('i686' 'x86_64' 'armv6h' 'armv7h' 'aarch64')
pkgdesc='Tool for managing custom Arch Linux repositories'
license=('GPL')
depends=('libc++utilities-git.so' 'libpasswordfile-git.so' 'libboost_filesystem.so' 'libarchive.so' 'lmdb' 'liburing')
optdepends=('reflective-rapidjson-git: development with libpkg/librepomgr'
            "$_name-doc: API documentation")
makedepends=('cmake' 'git' 'ninja' 'boost' 'catch2' 'rapidjson-git' 'reflective-rapidjson-git')
checkdepends=('cppunit')
provides=(libpkg-git.so librepomgr-git.so)
options=(debug)
url="https://github.com/Martchus/${_reponame}"
source=("${_reponame}::${MARTCHUS_GIT_URL_PREFIX:-git+https://github.com/Martchus}/${_reponame}.git"
        "lmdb-safe::${MARTCHUS_GIT_URL_PREFIX:-git+https://github.com/Martchus}/lmdb-safe.git"
        'tabulate::git+https://github.com/p-ranav/tabulate.git')
sha256sums=('SKIP' 'SKIP' 'SKIP')

pkgver() {
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame}"
  echo "$(git rev-list --count HEAD).$(git rev-parse --short HEAD)"
}

prepare() {
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame}"

  for submodule in tabulate lmdb-safe ; do
    rm -r 3rdparty/$submodule
    ln -sr ../$submodule 3rdparty/$submodule
  done
}

build() {
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame}"
  cmake \
    -G Ninja \
    -DCMAKE_BUILD_TYPE:STRING='RelWithDebInfo' \
    -DCMAKE_INSTALL_PREFIX:PATH='/usr' \
    -DCONFIGURATION_NAME:STRING='git' \
    -DCONFIGURATION_PACKAGE_SUFFIX:STRING='-git' \
    -DCONFIGURATION_TARGET_SUFFIX:STRING='git' \
    -DBUILD_SHARED_LIBS:BOOL=ON \
    -DDUMMY_BUILD_ACTION_ENABLED:BOOL=ON \
    -DREFLECTION_GENERATOR_EXECUTABLE:FILEPATH='/usr/bin/reflective_rapidjson_generator-git' \
    -DBOOST_ASIO_IO_URING:BOOL=OFF \
    .
  VERBOSE=1 ninja
}

check() {
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame}"
  ninja check
}

package() {
  cd "$srcdir/${PROJECT_DIR_NAME:-$_reponame}"
  DESTDIR="${pkgdir}" ninja install
}
