SUMMARY="Fast C library for the Discrete Fourier Transform"
DESCRIPTION="FFTW is a C subroutine library for computing the discrete \
Fourier transform (DFT) in one or more dimensions, of arbitrary input size, \
and of both real and complex data (as well as of even/odd data, i.e. the \
discrete cosine/sine transforms or DCT/DST). We believe that FFTW, which is \
free software, should become the FFT library of choice for most applications.
Our benchmarks, performed on on a variety of platforms, show that FFTW's \
performance is typically superior to that of other publicly available FFT \
software, and is even competitive with vendor-tuned codes. In contrast to \
vendor-tuned codes, however, FFTW's performance is portable: the same program \
will perform well on most architectures without modification. Hence the name, \
FFTW, which stands for the somewhat whimsical title of Fastest Fourier \
Transform in the West."
HOMEPAGE="http://www.fftw.org/"
COPYRIGHT="2003, 2007-2011 Matteo Frigo
	2003, 2007-2011 Massachusetts Institute of Technology"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="http://www.fftw.org/fftw-$portVersion.tar.gz"
CHECKSUM_SHA256="56c932549852cddcfafdab3820b0200c7742675be92179e59e6215b340e26467"
PATCHES="fftw-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

libVersion="3.6.10"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	fftw$secondaryArchSuffix = $portVersion compat >= 3
	cmd:fftw_wisdom$secondaryArchSuffix
	cmd:fftwf_wisdom$secondaryArchSuffix
	cmd:fftwl_wisdom$secondaryArchSuffix
	cmd:fftwq_wisdom$secondaryArchSuffix
	cmd:fftw_wisdom_to_conf$secondaryArchSuffix
	lib:libfftw3$secondaryArchSuffix = $libVersionCompat
	lib:libfftw3_threads$secondaryArchSuffix = $libVersionCompat
	lib:libfftw3f$secondaryArchSuffix = $libVersionCompat
	lib:libfftw3f_threads$secondaryArchSuffix = $libVersionCompat
	lib:libfftw3l$secondaryArchSuffix = $libVersionCompat
	lib:libfftw3l_threads$secondaryArchSuffix = $libVersionCompat
	"
if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
PROVIDES+="
	lib:libfftw3q$secondaryArchSuffix = $libVersionCompat
	lib:libfftw3q_threads$secondaryArchSuffix = $libVersionCompat
	"
fi

REQUIRES="
	haiku$secondaryArchSuffix
	"
if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
REQUIRES+="
	lib:libquadmath$secondaryArchSuffix
	"
fi

PROVIDES_devel="
	fftw${secondaryArchSuffix}_devel = $portVersion compat >= 3
	devel:libfftw3$secondaryArchSuffix = $libVersionCompat
	devel:libfftw3_threads$secondaryArchSuffix = $libVersionCompat
	devel:libfftw3f$secondaryArchSuffix = $libVersionCompat
	devel:libfftw3f_threads$secondaryArchSuffix = $libVersionCompat
	devel:libfftw3l$secondaryArchSuffix = $libVersionCompat
	devel:libfftw3l_threads$secondaryArchSuffix = $libVersionCompat
	"
if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
PROVIDES_devel+="
	devel:libfftw3q$secondaryArchSuffix = $libVersionCompat
	devel:libfftw3q_threads$secondaryArchSuffix = $libVersionCompat
	"
fi
REQUIRES_devel="
	fftw$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
BUILD_REQUIRES+="
	devel:libgfortran$secondaryArchSuffix
	"
fi
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoreconf
	cmd:awk
	cmd:cmp
	cmd:diff
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:perl
	"

debugList=(
	"$libDir"/libfftw3.so.$libVersion
	"$libDir"/libfftw3_threads.so.$libVersion
	"$libDir"/libfftw3f.so.$libVersion
	"$libDir"/libfftw3f_threads.so.$libVersion
	"$libDir"/libfftw3l.so.$libVersion
	"$libDir"/libfftw3l_threads.so.$libVersion
	)
if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
debugList+=(
	"$libDir"/libfftw3q.so.$libVersion
	"$libDir"/libfftw3q_threads.so.$libVersion
	)
fi
defineDebugInfoPackage fftw$secondaryArchSuffix "${debugList[@]}"

BUILD()
{
	# Autoreconf because m4 patching
	autoreconf --verbose --install --symlink --force

	mkdir -p double long-double quad float

	# 32 bit targets NORTHWOOD
	# 64 bit targets PRESCOTT

	CONFIGURE="--enable-shared --enable-threads --disable-avx --disable-avx2 \
		--disable-avx512"
	#CONFIGURE="--enable-shared --enable-threads"
	if [ "$effectiveTargetArchitecture" = x86_64 ]; then
		CONFIGURE_DOUBLE_X86_64="--enable-sse2"
		CONFIGURE_SINGLE_X86_64="--enable-sse"
		#CONFIGURE_DOUBLE_X86_64="--enable-sse2 --enable-avx"
		#CONFIGURE_SINGLE_X86_64="--enable-sse --enable-avx"
	fi

	# build double-precision version
	cd double
	runConfigure ../configure \
		$CONFIGURE \
		$CONFIGURE_DOUBLE_X86_64
	make $jobArgs
	cd ..

	# build long-double-precision version, can't handle sse2
	cd long-double
	runConfigure ../configure \
		--enable-long-double \
		$CONFIGURE
	make $jobArgs
	cd ..

if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
	# build long-quad-precision version, can't handle sse2
	cd quad
	runConfigure ../configure \
		--enable-quad-precision \
		$CONFIGURE
	make $jobArgs
	cd ..
fi

	# build single-precision version
	cd float
	runConfigure ../configure \
		--enable-single \
		$CONFIGURE \
		$CONFIGURE_SINGLE_X86_64
	make $jobArgs
	cd ..
}

DIRS="double long-double float"
fftwLibs="libfftw3 libfftw3_threads libfftw3f libfftw3f_threads libfftw3l libfftw3l_threads"
if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
	DIRS="$DIRS quad"
	fftwLibs="$fftwLibs libfftw3q libfftw3q_threads"
fi

INSTALL()
{
	for i in $DIRS; do
 		make -C $i install
 	done

	rm -f "$libDir"/libfftw*.la

	prepareInstalledDevelLibs $fftwLibs
	fixPkgconfig

	packageEntries devel \
		"$developDir" \
		"$libDir"/cmake
}

TEST()
{
	for i in $DIRS; do
		make -C $i check $jobArgs
	done
}
