#!/bin/sh
# http://code.entropywave.com/projects/orc/
SRC_URL=http://code.entropywave.com/download/orc
DOC_URL=
#
# script by: til <rob DOT til DOT freedman AT googlemail DOT com>
REPO=http://zenwalk.pinguix.com/user-accounts/tilderb/extra/d/orc

CWD=$(pwd)
set -e -u -x

# orc
version=0.4.11

build=${build:-'66.1'}
arch=${arch:-i486}
#cpu=pentium-m
cpu=${cpu:-i686}

TMP=${TMP:-$CWD}
pkgname=orc-$version
package=$pkgname-$arch-$build

PKG_DEP=""
PKG_SRC="$REPO/build-orc.sh
$SRC_URL/$pkgname.tar.gz"

# check source exists
#for url in $PKG_SRC;do [ ! -e ${url##*/} ] && wget -N -c $url; done

PKG=$TMP/$package
SRC=$TMP/$pkgname

[ -d $SRC ] && rm -fr $SRC
[ -d $PKG ] && rm -fr $PKG

# prepare build directory
mkdir -p $PKG/{install,usr/{src,doc}/$pkgname}

tar xf $CWD/$pkgname.tar.gz -C $TMP
cd $SRC
./configure --help >$CWD/configure-help

CFLAGS="-O2 -march=$arch -mtune=$cpu " \
CXXFLAGS="-O2 -march=$arch -mtune=$cpu " \
 ./configure --prefix=/usr  # --disable-static

make || exit 1
make install DESTDIR=$PKG

# more docs
cp COPYING README TODO $PKG/usr/doc/$pkgname

cd $PKG
# strip symbols
find usr/ | xargs -r file | grep -e "executable" -e "shared object" | grep ELF |\
	cut -f 1 -d : | xargs -r strip --strip-unneeded

find usr/ | xargs -r file | grep "current ar archive" | cut -f 1 -d : | xargs -r strip -g

# slack description
cat <<EOF > install/slack-desc
#  |-----handy-ruler------------------------------------------------------|
orc: Orc (The Oil Runtime Compiler)
orc: 
orc: Orc is a library and set of tools for compiling and executing 
orc: very simple programs that operate on arrays of data.  
orc: The “language” is a generic assembly language that represents
orc: many of the features available in SIMD architectures, including 
orc: saturated addition and subtraction, and many arithmetic operations.
EOF
# build script
cp $CWD/build-orc.sh usr/src/$pkgname

fakeroot /sbin/makepkg -l y -c n $CWD/$package.txz

cd $CWD
echo -n $PKG_DEP >$package.dep
echo "$PKG_SRC" >$package.src
md5sum $package.txz >$package.md5

#rm -fr $SRC $PKG
