# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase="c-ares"
pkgname=("libcares" "libcares-devel")
pkgver=1.34.5
pkgrel=1
pkgdesc="C library that performs DNS requests and name resolves asynchronously (libraries)"
arch=('i686' 'x86_64')
url="https://c-ares.haxx.se/"
msys2_repository_url="https://github.com/c-ares/c-ares"
msys2_references=(
  "cpe: cpe:/a:c-ares_project:c-ares"
  "cpe: cpe:/a:daniel_stenberg:c-ares"
)
license=("spdx:MIT")
makedepends=("cmake" 'gcc' 'ninja')
depends=("gcc-libs")
source=("https://github.com/c-ares/c-ares/releases/download/v${pkgver}/c-ares-${pkgver}.tar.gz"{,.asc})
sha256sums=('7d935790e9af081c25c495fd13c2cfcda4792983418e96358ef6e7320ee06346'
            'SKIP')
# keys: https://c-ares.org/#download
validpgpkeys=('27EDEAF22F3ABCEB50DB9A125CC908FDB71E12C2' # Daniel Stenberg <daniel@haxx.se>
              'DA7D64E4C82C6294CB73A20E22E3D13B5411B7CA') #Brad House <brad@brad-house.com>

build() {
  cd "${srcdir}/${pkgbase}-${pkgver}"

  cmake -GNinja -B "build-static" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCARES_STATIC=ON \
    -DCARES_SHARED=OFF
  cmake --build "build-static"
  DESTDIR="${srcdir}/dest" cmake --install "build-static"

  cmake -GNinja -B "build-shared" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCARES_STATIC=OFF \
    -DCARES_SHARED=ON
  cmake --build "build-shared"
  DESTDIR="${srcdir}/dest" cmake --install "build-shared"
}

package_libcares() {
  groups=('libraries')

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

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

  install -vDm 644 "${srcdir}/${pkgbase}-${pkgver}/LICENSE.md" -t "${pkgdir}/usr/share/licenses/${pkgbase}/"
}

package_libcares-devel() {
  pkgdesc="c-ares headers and libraries (development)"
  groups=('development')
  depends=("libcares=${pkgver}")

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