# Contributor: AndyRTR <andyrtr@archlinux.org>
# Contributor: Bastien Dejean <nihilhill@gmail.com>

_pkgname=xcb-util-cursor
pkgname=static-compat-$_pkgname
pkgver=0.1.5
pkgrel=1
pkgdesc="XCB cursor library"
arch=('x86_64')
url="https://xcb.freedesktop.org"
license=('custom:MIT')
depends=('static-compat-xcb-util-renderutil' 'static-compat-xcb-util-image' 'glibc-static-compat')
makedepends=('xorg-util-macros' 'static-compat-xorgproto' 'static-compat-configure')
options=(staticlibs)
source=(https://xorg.freedesktop.org/archive/individual/lib/${_pkgname}-${pkgver}.tar.xz{,.sig})
sha512sums=('e2d14c3f0ab117524ba90d1a992b61717ccee04bc9e66c587a6a0f10571f15e89fc5db3413882ca7ce14ebc07b6b7b0a4ddecd59ba910e6ca654ea9b1c705ed5'
            'SKIP')
validpgpkeys=('4A193C06D35E7C670FA4EF0BA2FB9E081F2D130E') # Alan Coopersmith <alan.coopersmith@oracle.com>

build() {
  source static-compat-environment
  cd ${_pkgname}-${pkgver}
  export PATH=$PWD:$PATH
  printf '#!/usr/bin/bash\nexec /usr/bin/pkg-config --static "$@"\n' > pkg-config
  chmod +x pkg-config
  static-compat-configure --disable-shared --enable-static
  make
}

check() {
  source static-compat-environment
  cd ${_pkgname}-${pkgver}
  make check
}

package() {
  source static-compat-environment
  cd ${_pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install

  # avoid linker error
  # /usr/bin/ld: /usr/static-compat/lib/libxcb-image.a(xcb_image.o): in function `xcb_create_pixmap_from_bitmap_data':
  # (.text+0x14b7): undefined reference to `xcb_aux_create_gc'
  sed -i 's|Requires:.*|\0 xcb-util|g' "$pkgdir/$static_compat_prefix"/lib/pkgconfig/xcb-cursor.pc

  install -D -m644 COPYING \
    "${pkgdir}"/usr/share/licenses/${pkgname}/COPYING
}
