pkgname=fftw
pkgver=3.3.10
pkgdesc="Fast C library for the Discrete Fourier Transform"
homepage="https://www.fftw.org/"
licenses=("GPL-2+")
_patches=("fftw-3.3.10-fixup-cmake-optional.patch")
_patch_sums=("517ea0d21ba360db7c9d2fe805dec9de30362a71a567e7b034f7c569433d206f6b3abae4a8dfb704970e02d8d9b30cb9a578946417b4c1986fbfee6db68267b0")
sources=("${pkgname}-${pkgver/_p/-pl}.tar.gz"
  ${_patches[@]}
)
urls=("https://www.fftw.org/${sources[0]}"
  ${_patches[@]}
)
sha512sums=("2d34b5ccac7b08740dbdacc6ebe451d8a34cf9d9bfec85a5e776e87adf94abfd803c222412d8e10fbaa4ed46f504aa87180396af1b108666cde4314a55610b40"
  ${_patch_sums[@]}
)

_multibuild=(single double longdouble)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  for _patch in ${_patches[@]}; do
    patch -p1 -i ${filedir}/${_patch}
  done
}

src_build() {
  CFLAGS+=" -O3"

  local conf_args=(
    --prefix=/usr
    --enable-shared
    --disable-static
    --enable-fma #cpu_flags_x86_fma3
    --disable-fortran
    --disable-mips-zbus-timer
    --disable-threads
    --enable-openmp
    --disable-mpi
  )
  local conf_args_single=(
    "${conf_args[@]}"
    --enable-single
    --disable-altivec
    --enable-avx
    --enable-avx2
    --enable-sse
    --enable-sse2
  )
  local conf_args_double=(
    "${conf_args[@]}"
    --enable-avx
    --enable-avx2
    --enable-sse2
  )
  local conf_args_longdouble=(
    "${conf_args[@]}"
    --enable-long-double
  )

  for _build in "${_multibuild[@]}"; do
    mkdir -pv build-"${_build}"
    pushd build-${_build}
      case ${_build} in
        single)
          ../configure "${conf_args_single[@]}"
          ;;
        double)
          ../configure "${conf_args_double[@]}"
          ;;
        longdouble)
          ../configure "${conf_args_longdouble[@]}"
          ;;
      esac
    popd
  done

  for _build in "${_multibuild[@]}"; do
    make -C build-${_build}
  done
}

src_check() {
  for _build in "${_multibuild[@]}"; do
    make smallcheck -C build-${_build}/tests
  done
}

src_install() {
  for _build in "${_multibuild[@]}"; do
    make DESTDIR="$pkgdir" install -C build-${_build}
  done
}

# vim:ft=sh syn=sh et sw=2:
