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

_realname=xpm-nox
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.2.0
pkgrel=5
pkgdesc="X Pixmap library not using X (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="ftp://koala.inria.fr/pub/xpm"
license=("Groupe Bull")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' 'staticlibs' '!buildflags' '!makeflags')
source=(ftp://koala.inria.fr/pub/xpm/xpm-nox-${pkgver}.tar.bz2
        xpm-nox-4.2.0-mingw.patch
        xpm.pc)
md5sums=('c87a25f7cfae59cd536b708d02c0cfad'
         '20f17c990d74d1c7a52c352e2e9e7874'
         '7b5e02d69f8eebd5dbf2b1a1c8601329')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/xpm-nox-4.2.0-mingw.patch
}

build() {
  cp -r "${srcdir}"/${_realname}-${pkgver} "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  make prefix=${MINGW_PREFIX} CC=${MINGW_CHOST}-gcc
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make CC=${MINGW_CHOST}-gcc prefix=${MINGW_PREFIX} DESTDIR="${pkgdir}" install
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig
  cp ${srcdir}/xpm.pc ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/xpm.pc
  sed -e "s|@prefix@|${MINGW_PREFIX}|g" \
      -e "s|@PACKAGE_VERSION@|${pkgver}|g" \
      -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/xpm.pc
}
