# Maintainer: LoveSy <shana@zju.edu.cn>

pkgbase=libbobcat
pkgname=('libbobcat' 'libbobcat-devel')
pkgver=5.07.03
pkgrel=1
pkgdesc="Bobcat (Brokken's Own Base Classes And Templates) library"
arch=('i686' 'x86_64')
url="https://fbb-git.gitlab.io/bobcat/"
license=('GPL')
# Versions taken from the 'required' file in sources
makedepends=('icmake>=8.01.00' 'yodl>=3.07.01' 'gcc' 'git')
optdepends=()
# Use my own repo temporarily to avoid untaring soft link.
source=("${pkgname}::git+https://gitlab.com/fbb-git/bobcat.git#tag=${pkgver}"
        "fix-g_errno.patch"
        "fix-build.patch"
        "fix-light-build.patch"
        "0001-missing-header.patch")
sha256sums=('da1fa4d2c4649ab754dd9e94f753bd059f03eb92d3cbb7d5f4c2c7ada57e4ea9'
            '875f0176b256897eb9e62656877255a909321c7268a6e0eedafc900ca04c0d55'
            'd710f99c90e351d9b8a9927f0a41686489355404fcaf19c745e38323396d93b6'
            'b2f2773d4486d4b2b3c3f6c20042a7eb3b01e7e2a75d5bd3b28761283b891d9d'
            '5b043a14f152707df698a1aa4d5a4752613000f962f8002242f8620fba7aadb4')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Np1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd "${srcdir}/${pkgbase}"

  apply_patch_with_msg \
    fix-g_errno.patch \
    fix-build.patch \
    fix-light-build.patch \
    0001-missing-header.patch
}
build() {
  cd "${srcdir}/${pkgbase}/bobcat"
  CXXFLAGS="$CXXFLAGS -std=c++17 -D_GNU_SOURCE"
  # Add the -P option not to use precompiled headers, which can be useful since
  # they require a lot of free space, compared to a normal compilation:
  # ./build -P libraries all
  ./build light
  ./build man
  ./build install x "${srcdir}/dest"

  mkdir -p ${srcdir}/dest/usr/bin
  mv ${srcdir}/dest/usr/lib/*.dll ${srcdir}/dest/usr/bin/
}

package_libbobcat() {
  depends=('gcc-libs')

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libbobcat-devel() {
  pkgdesc="libbobcat headers and libraries"
  options=('staticlibs')
  groups=('development')
  depends=("libbobcat=${pkgver}")

  mkdir -p ${pkgdir}/usr

  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
