#!/bin/sh

. ../config/osx/common.sh

function build_plattform()
{
	PLATFORM=$1
	SIMD=$2
	LIBTYPE=$3

	make distclean
	CC="$COMMON_CC -arch $PLATFORM $COMMON_CFLAGS_NOARCH" CXX="$COMMON_CXX" LDFLAGS="$COMMON_LDFLAGS_NOARCH -arch $PLATFORM" ./configure --host=$PLATFORM-apple-darwin9.6.0 --disable-shared --disable-dependency-tracking --disable-fortran $SIMD
	make $COMMON_MAKEFLAGS
	cp .libs/libfftw3$LIBTYPE.a lib/osx/libfftw3$LIBTYPE-$PLATFORM.a
}

echo "Building fftw..."

mkdir -p lib/osx

build_plattform x86_64 "--enable-single --enable-sse" "f"
build_plattform i386 "--enable-single --enable-sse" "f"
build_plattform ppc "--enable-single --enable-altivec" "f"

lipo -create lib/osx/libfftw3f-i386.a lib/osx/libfftw3f-ppc.a lib/osx/libfftw3f-x86_64.a -output lib/osx/libfftw3f-ni.a

build_plattform x86_64 "--enable-sse2" ""
build_plattform i386 "--enable-sse2" ""
build_plattform ppc "" ""

lipo -create lib/osx/libfftw3-i386.a lib/osx/libfftw3-ppc.a lib/osx/libfftw3-x86_64.a -output lib/osx/libfftw3-ni.a
