# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

pkgbase=libuv
pkgname=("${pkgbase}" "${pkgbase}-devel")
pkgver=1.42.0
pkgrel=1
pkgdesc="Multi-platform support library with a focus on asynchronous I/O"
arch=('i686' 'x86_64')
url="https://github.com/libuv/libuv"
license=('custom')
makedepends=('gcc')
depends=('gcc-libs')
source=("https://dist.libuv.org/dist/v${pkgver}/libuv-v${pkgver}.tar.gz"{,.sign})
sha512sums=('cc8ca797ec6e02fff7d4998fd5a509373ae6c674ff0d57960fef3418f59d3b93a655f52913ee5f712e32e3980b29df6315685c8b506790295d97c7c1f94f3425'
            'SKIP')
# PGP key IDs are available from https://github.com/libuv/libuv/blob/v1.x/MAINTAINERS.md
validpgpkeys=('AEAD0A4B686767751A0E4AEF34A25FB128246514') # Jameson Nash (@vtjnash)

prepare() {
  cd "${srcdir}"/${pkgname}-v${pkgver}
  ./autogen.sh
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  cd "${srcdir}"/${pkgbase}-v${pkgver}
  ./configure --host=${CHOST} \
              --build=${CHOST} \
              --prefix=/usr

  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}"/${pkgbase}-v${pkgver}
  # a few of these tests are known to fail.
  make check || true
}

package_libuv() {
  groups=('libraries')

  cd "${srcdir}"/${pkgbase}-v${pkgver}
  install -Dm644 LICENSE \
    "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
  install -Dm644 AUTHORS \
    "${pkgdir}"/usr/share/doc/${pkgname}/AUTHORS
  install -Dm644 README.md \
    "${pkgdir}"/usr/share/doc/${pkgname}/README.md
  install -Dm644 ChangeLog \
    "${pkgdir}"/usr/share/doc/${pkgname}/ChangeLog
 
  cd "${srcdir}/dest"
  mkdir -p ${pkgdir}/usr/bin
  cp -f usr/bin/*.dll ${pkgdir}/usr/bin
}

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

  cd "${srcdir}/dest"
  mkdir -p ${pkgdir}/usr/lib
  mkdir -p ${pkgdir}/usr/include

  cp -rf usr/lib/* ${pkgdir}/usr/lib
  cp -rf usr/include/* ${pkgdir}/usr/include
  #This is required for cmake.  
  cp "${srcdir}"/${pkgbase}-v${pkgver}/include/uv/posix.h ${pkgdir}/usr/include/uv
}
