#!/bin/bash

###SHELLPACK preamble parsecbuild-install 0
GIT_LOCATION="https://github.com/cirosantilli/parsec-benchmark"
MIRROR_LOCATION="$WEBROOT/parsec/"

for PACKAGE in gsl-devel libgsl23 libgslcblas0 libjpeg8-devel libjpeg8 xz cmake libXt-devel libXmu-devel libXi-devel; do
	install-depends $PACKAGE
done

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargEnd

###SHELLPACK git_fetch parsecbuild-${VERSION}.tar.gz parsecbuild-${VERSION}-installed
cd $SHELLPACK_SOURCES
mv parsecbuild-${VERSION}-installed $SHELLPACK_DATA || die "Failed to move sources to data directory"
ln -s $SHELLPACK_DATA/parsecbuild-${VERSION}-installed parsecbuild-${VERSION}-installed
cd $SHELLPACK_SOURCES/parsecbuild-${VERSION}-installed || die "Failed to cd to sources"

echo Fetching native input data
file_fetch http://parsec.cs.princeton.edu/download/3.0/parsec-3.0-input-native.tar.gz \
	$MIRROR_LOCATION/parsec-3.0-input-native.tar.gz \
	parsec-input.tar.gz
echo Extracting native input data
tar -xf parsec-input.tar.gz --strip-components=1 || die "Failed to download and extract parsec-input.tar.gz"

# Build fixes
for FILE in `find -name "*.cpp"`; do
	sed -i -e 's/"__PARSEC_XSTRING/" __PARSEC_XSTRING/' $FILE
done

if [ "`which man`" != "" ]; then
	man g++ 2>&1 | grep -q no-pie
	if [ $? -ne 0 ]; then
		sed -i -e 's/-no-pie//g' ./pkgs/apps/x264/parsec/gcc-pthreads.bldconf
	fi
fi

###SHELLPACK self_extract x264.patch
cat $SHELLPACK_TEMP/x264.patch | patch -p1 || exit $SHELLPACK_FAILURE

echo parsecbuild preliminary download complete
exit $SHELLPACK_SUCCESS

==== BEGIN x264.patch ====
diff --git a/pkgs/apps/x264/src/common/set.c b/pkgs/apps/x264/src/common/set.c
index 6c7ddc468ff2..795e7d528bf2 100644
--- a/pkgs/apps/x264/src/common/set.c
+++ b/pkgs/apps/x264/src/common/set.c
@@ -176,7 +176,7 @@
 void x264_cqm_delete( x264_t *h )
 {
     int i, j;
-    for( i = 0; i < 6; i++ )
+    for( i = 0; i < 5; i++ )
     {
         for( j = 0; j < i; j++ )
             if( h->quant4_mf[i] == h->quant4_mf[j] )
==== END x264.patch ====
