# Contributor: William Pitcock <nenolod@dereferenced.org>
# Maintainer: William Pitcock <nenolod@dereferenced.org>
pkgname=fftw
pkgver=3.3.6p2
pkgrel=0
pkgdesc="fastest fourier transform in the west"
url="http://www.fftw.org/"
license="GPL"
makedepends="texinfo"
# order of the libs split functions are important because of lib naming
subpackages="$pkgname-dev $pkgname-doc $pkgname-single-libs:single
	$pkgname-long-double-libs:long_double $pkgname-double-libs:double"
srcpkgver=${pkgver//p/-pl}
source="http://www.fftw.org/$pkgname-$srcpkgver.tar.gz
	cycle.h.patch"
arch="all"
_precision="single double long-double"

builddir="$srcdir/$pkgname-$srcpkgver"

prepare() {
	cd "$builddir"
	default_prepare
	for i in $_precision; do
		cp -r "$builddir" $srcdir/$i
	done
}

build() {
	for i in $_precision; do
		case "$i" in
			single)_cf="--enable-single";;
			double)_cf="";;
			long-double)_cf="--enable-long-double";;
		esac

		case "$i--$CARCH" in
		single--x86_64 | double--x86_64)
			_cf="$_cf --enable-sse2 --enable-avx";;
		single--arm* | single--aarch64)
			_cf="$_cf --enable-neon";;
		esac

		msg "Building for $i precision ($_cf)"
		cd "$srcdir"/$i
		./configure \
			--build=$CBUILD \
			--host=$CHOST \
			--prefix=/usr \
			--sysconfdir=/etc \
			--mandir=/usr/share/man \
			--infodir=/usr/share/info \
			--enable-shared \
			--enable-threads \
			$_cf
		make
	done
}

package() {
	for i in $_precision; do
		cd "$srcdir"/$i
		make DESTDIR="$pkgdir" install
	done
}

single() {
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libfftw3f*.so* \
		"$subpkgdir"/usr/lib/
}

double() {
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libfftw3*.so* \
		"$subpkgdir"/usr/lib/
}

long_double() {
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libfftw3l*.so* \
		"$subpkgdir"/usr/lib/
}

sha512sums="e130309856752a1555b6d151c4d0ce9eb4b2c208fff7e3e89282ca8ef6104718f865cbb5e9c4af4367b3615b69b0d50fd001a26d74fd5324ff2faabe14fe3472  fftw-3.3.6-pl2.tar.gz
d71ffb0aa658f7b22239491698426f4a97e657abc953020745f7581d2937a062a279eaa5980cd7f7fe2e8425a032eafc3d4c0cffdc79a83a3aef382c988d739a  cycle.h.patch"
