# Maintainer: Yusuke Sasaki <y_sasaki@nuem.nagoya-u.ac.jp>

_realname=potrace
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.16
pkgrel=2
pkgdesc="Tool for tracing a bitmap, which means, transforming a bitmap into a smooth, scalable image (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://potrace.sourceforge.io/'
msys2_references=(
  "cpe: cpe:/a:potrace_project:potrace"
)
license=('GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://potrace.sourceforge.io/download/${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-reaarange-compiler-detect.patch)
sha256sums=('be8248a17dedd6ccbaab2fcc45835bb0502d062e40fbded3bc56028ce5eb7acc'
            '17a46071e826fd2f2715c63002ff6ddb2635f40b44ceb88fec9bdb5f4d61e1ea')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-reaarange-compiler-detect.patch
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --mandir=${MINGW_PREFIX}/share/man \
    --enable-shared \
    --enable-static \
    --with-libpotrace
  make
}

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