#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-warsow
VERSION=0.21
ARCH=alpha
BUILD=2

rm -rf $PKG
mkdir -p $PKG/usr/local/games
( cd $TMP
### thats the base from linux-package of warsow ###
tar xjf $CWD/warsow.tar.bz2 -C $PKG/usr/local/games
### now we build the alpha binaries ###
rm -rf warsow-$VERSION.sdk
tar xjf $CWD/warsow-$VERSION.sdk.tar.bz2
cd warsow-$VERSION.sdk/source
zcat $CWD/Makefile.diff.gz | patch -p1 --verbose || exit
make
cd release
cp -a * $PKG/usr/local/games/warsow
( cd $PKG
    find . -perm 666 -exec chmod 644 {} \;
    find . -perm 664 -exec chmod 644 {} \;
    find . -perm 600 -exec chmod 644 {} \;
    find . -perm 444 -exec chmod 644 {} \;
    find . -perm 400 -exec chmod 644 {} \;
    find . -perm 440 -exec chmod 644 {} \;
    find . -perm 777 -exec chmod 755 {} \;
    find . -perm 775 -exec chmod 755 {} \;
    find . -perm 500 -exec chmod 755 {} \;
    find . -perm 700 -exec chmod 755 {} \;
    find . -perm 555 -exec chmod 755 {} \;
)
( cd $PKG/usr/local/games/warsow/basewsw ; ln -sf ../libs/ui_axp.so . )
( cd $PKG/usr/local/games/warsow/basewsw ; ln -sf ../libs/cgame_axp.so . )
( cd $PKG/usr/local/games/warsow/basewsw ; ln -sf ../libs/game_axp.so . )
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/warsow-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/warsow.build.log
