#!/bin/sh

#
#Omni slackbuild script
#
#

PRGNAM=iComity
VERSION=beta3
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-uh}
CWD=$(pwd)
TMP=${TMP:-/tmp/uh/src}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp/uh}
AUTHOR=${AUTHOR:-Unnamed_Hero}
EMAIL=${EMAIL:-sorry@email.hide}

DOC="AUTHORS BUGS BUILD COMPILERS COPYING NEWS README TODO copyright.notice"

if [ "$ARCH" = "i486" ]; then
 SLKCFLAGS="-O2 -march=i486 -mtune=i686"
 elif [ "$ARCH" = "i686" ]; then
     SLKCFLAGS="-O2 -march=i686 -mtune=i686"
 elif [ "$ARCH" = "x86_64" ]; then
     SLKCFLAGS="-O2 -fPIC"
fi


rm -rf $PKG
mkdir -p $TMP $PKG
rm -rf $TMP/$PRGNAM-$VERSION
cd $TMP || exit 1
#tar xvf $CWD/$PRGNAM-$VERSION.tar.bz2 || exit 1
cp -a $CWD/$PRGNAM-$VERSION.tar.bz2 $PKG/$PRGNAM-$VERSION.tar.bz2
#cd $PRGNAM || exit 1
chown -R root:root .
chmod -R u+w,go+r-w,a-s .




#CFLAGS="$SLKCFLAGS" \
#CXXFLAGS="$SLKCFLAGS" \
#  ./configure \
#    --prefix=/usr 
    
#make -j4 || exit 1
#make install DESTDIR=$PKG || exit 1

#find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \
#  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
  
#gzip -9 $PKG/usr/man/man?/*.?

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
#cp -a -r $PRGNAM $PKG/usr/share/icons
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild


mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

if [ -e $CWD/doinst.sh.gz ]; then
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
fi
     

cd $PKG

#cd $PKG

#if [ ! -e $CWD/slack-required ]; then
#    echo "Generating dependencies. This make take a few minutes to complete."
#    requiredbuilder -v -y -s $CWD $PKG
#else
#    cat $CWD/slack-required > $PKG/install/slack-required
#fi

echo "Making data.xml"
makedata --cwd $CWD --pkg $PKG --name $PRGNAM --version $VERSION --arch $ARCH --build $BUILD --tags "xapps,xfce,icons," --author $AUTHOR --email $EMAIL
/sbin/makepkg --linkadd n -c n $CWD/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
