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

_realname=fftw
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=3.3.8
pkgver=${_pkgver//-/.}
pkgrel=1
pkgdesc="A library for computing the discrete Fourier transform (DFT) (mingw-w64)"
arch=('any')
url="http://www.fftw.org"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("${url}/${_realname}-${_pkgver}.tar.gz")
sha256sums=('6113262f6e92c5bd474f2875fa1b01054c4ad5040f6b0da7c03c98821d9ae303')

precision="double float long_double quad"

build() {
  cd "${srcdir}/${_realname}-${_pkgver}"
  for cur in ${precision}; do
    local _config="--enable-sse2 --enable-avx"
    if [ "${cur}" = "float" ]; then
      _config="${_config} --enable-float"
    elif [ "${cur}" = "long_double" ]; then
      _config="--enable-long-double"
    elif [ "${cur}" = "quad" ]; then
      _config="--enable-quad-precision"
    fi
    [[ -d ${MINGW_CHOST}-${cur} ]] && rm -rf ${MINGW_CHOST}-${cur}
    mkdir -p ${MINGW_CHOST}-${cur}
    pushd ${MINGW_CHOST}-${cur} > /dev/null
    msg "Building ${_realname} with ${cur} ..."

    ../configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      ${_config} \
      --enable-static \
      --enable-shared \
      --enable-threads \
      --with-combined-threads \
      --with-our-malloc \
      --with-g77-wrappers \
      --with-windows-f77-mangling
    make

    popd > /dev/null

  done
}

package() {
  cd "${srcdir}/${_realname}-${_pkgver}"
  for cur in ${precision}; do
    pushd ${MINGW_CHOST}-${cur} > /dev/null
    msg "Instaling ${_realname} with ${cur} ..."
    make DESTDIR="${pkgdir}" install
    popd > /dev/null
  done
}
