# Maintainer: Fabio 'Lolix' Loli <fabio.loli@disroot.org> -> https://github.com/FabioLolix
# Contributor: LIN Ruoshui <lin dot ruohshoei plus archlinux at gmail dot com>
# Contributor: lukpod

pkgname=amule-git
pkgver=3.0.0.r92.b5d8d40d0
pkgrel=1
pkgdesc="Client for the eD2k and Kad networks"
arch=(x86_64)
url="https://github.com/amule-org/amule"
license=(GPL-2.0-or-later)
depends=(
  binutils
  crypto++
  curl
  gd
  #geoip
  glib2
  glibc
  gtk3
  hicolor-icon-theme
  libayatana-appindicator
  libgcc
  libmaxminddb # IP2COUNTRY
  libpng
  libstdc++
  libupnp
  readline
  wxwidgets-common
  wxwidgets-gtk3
  zlib
  zstd
)
makedepends=(
  boost
  cmake
  git
  po4a # manpage translation
)
provides=(amule amule-daemon)
conflicts=(amule)
options=(!lto)
source=(
  "git+https://github.com/amule-org/amule.git"
  amuled.systemd
  amuleweb.systemd
  amule.sysusers
  amule.tmpfiles
)
sha256sums=('SKIP'
  '20ac6b60c5f3bf49c0b080dfc02409da3c9d01b154344188008c6a75ca69681e'
  'f4f43b1154ddccc9036a4291a58c6715f097b171fec62ea7aead0c9d9fa654f2'
  'c4ca658ab4105b3b90e0bb3efcc8121eca1c4d873787db1ed4f637925c16d502'
  'e9d1b7019c7075b0f8616c6507a767b87de8f899936680e9ff5829d8cbba224d')

pkgver() {
  cd amule
  git describe --tags | sed 's/-/.r/; s/-g/./'
}

build() {
  local _flags=(
    -DBUILD_ALCC=ON
    -DBUILD_ALC=ON
    -DBUILD_AMULECMD=ON
    -DBUILD_CAS=ON
    -DBUILD_DAEMON=ON
    -DBUILD_FILEVIEW=ON
    -DBUILD_REMOTEGUI=ON
    -DBUILD_WEBSERVER=ON
    -DBUILD_WXCAS=ON
    -DENABLE_IP2COUNTRY=ON
    -DENABLE_NLS=ON
    -DENABLE_UPNP=ON
  )

  cmake -B build -S amule -Wno-dev \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    "${_flags[@]}"

  cmake --build build
}

check() {
  ctest --test-dir build --output-on-failure
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -Dm644 amuled.systemd "$pkgdir"/usr/lib/systemd/system/amuled.service
  install -Dm644 amuleweb.systemd "$pkgdir"/usr/lib/systemd/system/amuleweb.service
  install -Dm644 amule.sysusers "$pkgdir"/usr/lib/sysusers.d/amule.conf
  install -Dm644 amule.tmpfiles "$pkgdir"/usr/lib/tmpfiles.d/amule.conf
}
