# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=dsfmt
_pkgname=dSFMT
pkgver=2.2.3
pkgrel=0
pkgdesc="Double precision SIMD-oriented Fast Mersenne Twister"
url="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/#dSFMT"
arch="all"
license="BSD"
depends=""
makedepends=""
subpackages="$pkgname-dev"
source="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/$_pkgname-src-$pkgver.tar.gz
	$pkgname.pc
	0001-dSFMT.patch
	"
builddir="$srcdir/$_pkgname-src-$pkgver"

_soname="lib$_pkgname.so"

prepare() {
	cd "$builddir"

	sed "s/@VERSION@/$pkgver/" "$srcdir"/$pkgname.pc > $pkgname.pc || return 1
	default_prepare
}

build() {
	cd "$builddir"

	# copied from https://github.com/JuliaLang/julia/blob/master/deps/dsfmt.mk
	local cflags="$CFLAGS -DNDEBUG -DDSFMT_MEXP=19937 -DDSFMT_DO_NOT_USE_OLD_NAMES
		-fPIC -O3 -finline-functions -fomit-frame-pointer
		-fno-strict-aliasing --param max-inline-insns-single=1800
		-Wmissing-prototypes -Wall -std=c99 -shared"

	if [ "$CARCH" = x86_64 ]; then
		cflags="$cflags -msse2 -DHAVE_SSE2"
	fi

	gcc $cflags dSFMT.c -o $_soname
}

package() {
	cd "$builddir"

	install -D $_soname "$pkgdir"/usr/lib/$_soname || return 1
	install -D dSFMT.h "$pkgdir"/usr/include/dSFMT.h || return 1
	install -D $pkgname.pc "$pkgdir"/usr/lib/pkgconfig/$pkgname.pc
}

md5sums="057c5a11d28296825fba584f561a4369  dSFMT-src-2.2.3.tar.gz
57e48cb6635f9a84e70b5cb555b664cc  dsfmt.pc
dd236061b7019a9334b0174ce9d9e2fa  0001-dSFMT.patch"
sha256sums="82344874522f363bf93c960044b0a6b87b651c9565b6312cf8719bb8e4c26a0e  dSFMT-src-2.2.3.tar.gz
0dd529b54ef6b300f030854de1b229f63af371d3129fa830bafaad930a2a993f  dsfmt.pc
9e0659814256b870468f23dcc4cf1da6ede781061c1df2edddd811a7114fc8da  0001-dSFMT.patch"
sha512sums="6d8ddcd01aab3f9039f4f0288a8af53e290cc2f293ed8c4a8c9f3b3f12398e7eedfce8016117b425766ba89c61c86c13b3e420035b5f9bf91315b8b814c03662  dSFMT-src-2.2.3.tar.gz
07810381fea8477478a968aaeca983ef639dd42ee0efccf7bdc910d137b07f55c43f3feb1ee59eaf97f4143ac273e32a02f557cb3a0d4e430480f650efee4fbd  dsfmt.pc
9feac5b96e431d110e88631e5540cec1e8ce3443c0c74afd8132650a077ae569e0214bbee9326d4f8a91e8fc10603fdcceedebbc3713bf0c3713117906b1f6da  0001-dSFMT.patch"
