# Maintainer: Coelacanthus <uwu@coelacanthus.name>
# Contributor: Michael Breedlove <me@michaelbreedlove.net>

pkgname=goestools-git
_name=${pkgname%-git}
pkgver=r404.80ece1a
pkgrel=1
pkgdesc="Tools to work with signals and files from GOES satellites"
arch=('x86_64')
url="https://github.com/pietern/goestools"
license=('BSD-2-Clause')
makedepends=(
  'cmake'
  'git'
  'ninja'
  'nlohmann-json'
)
depends=(
  'nanomsg'
  'airspy'
  'opencv'
  'rtl-sdr'
  'zlib'
  'glibc'
  'gcc-libs'
)
provides=('goestools-git')
conflicts=('goestools-git')
source=(
  git+${url}.git
  git+https://gitlab.dkrz.de/k202009/libaec.git
  git+https://github.com/pietern/libcorrect.git
  git+https://github.com/arsenm/sanitizers-cmake.git
  git+https://github.com/mayah/tinytoml.git
)
b2sums=('SKIP'
        'SKIP'
        'SKIP'
        'SKIP'
        'SKIP')

pkgver() {
  cd "$_name"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "$_name"
  _submodules=(
    libaec
    libcorrect
    sanitizers-cmake
    tinytoml
  )
  for submodule in "${_submodules[@]}"; do
    git submodule init vendor/"${submodule#*::}"
    git submodule set-url vendor/"${submodule#*::}" "$srcdir"/"${submodule%::*}"
    git -c protocol.file.allow=always submodule update vendor/"${submodule#*::}"
  done

  # Allow to use system nanomsg and nlohmann_json
  # https://github.com/pietern/goestools/pull/88
  # https://github.com/pietern/goestools/pull/87
  git cherry-pick -n 4568f1fa79146566de4d6f93a3c5fabfb43263f1 # nanomsg
  git cherry-pick -n 6109d5e060208a77d0a163bec0c15c2b1506f5c9 # nlohmann_json
}

build() {
  cd "$_name"
  cmake -S . -B build \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None
  cmake --build build
}

package() {
  cd "$_name"
  DESTDIR="$pkgdir" cmake --install build
  install -d "${pkgdir}/usr/share/licenses/goestools-git/"
  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/goestools-git/"
}
# vim: set ts=2 sw=2 et:
