# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>
_realname=mscgen
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.20
pkgrel=1
pkgdesc="Message Sequence Chart Generator (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='http://www.mcternan.me.uk/mscgen/'
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-libgd")
makedepends=("flex" "bison" "${MINGW_PACKAGE_PREFIX}-freetype" "${MINGW_PACKAGE_PREFIX}-ttf-dejavu")
options=()
source=( "http://www.mcternan.me.uk/mscgen/software/${_realname}-src-$pkgver.tar.gz" 
         "0.20-default-font.patch" 
         "0.20-escape.patch"
         "0.20-language.patch"
         "0.20-uninitialized-ymax.patch")
sha256sums=('3c3481ae0599e1c2d30b7ed54ab45249127533ab2f20e768a0ae58d8551ddc23'
            '691bddb540000a8aa6f6248beebae11f931cc35f7036270fab846bbbff65bcf2'
            '7cdae5bfb7f218405ffdeac4c8b0874da4c60dca89da8702289614d5ecd540ef'
            '62216cf5e6d36c9787eeadbf51817481a41933dbcda151f630a162f7e45b780d'
            '1f81fcbb6e644003c84168f7f78de751edfc6572c71591eea4e80807c643c096')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p2 -i ${srcdir}/0.20-default-font.patch
  patch -p1 -i ${srcdir}/0.20-escape.patch
  patch -p1 -i ${srcdir}/0.20-language.patch
  patch -p1 -i ${srcdir}/0.20-uninitialized-ymax.patch
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-freetype

  make all
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install
}
