#!/bin/sh

# Variables affecting the configuration and compilation

unset CC CXX CPP CFLAGS CXXFLAGS CPPFLAGS LDFLAGS

# Package-specific variables

PACKAGE=libxfce4mcs
VERSION=4.1.99.3
#BASEDIR=/usr/src
BASEDIR=`pwd`

CPU=$(uname -m)
SYSTEM=$CPU-pc-linux-gnu

FULLPKGNAME=$PACKAGE-$VERSION
SOURCEDIR=$BASEDIR/$FULLPKGNAME
SOURCEFILE=$BASEDIR/$FULLPKGNAME.tar.bz2
BUILDDIR=$BASEDIR/$FULLPKGNAME-build
PACKAGEDIR=$BASEDIR/$FULLPKGNAME-$CPU
PACKAGEFILE=$BASEDIR/$FULLPKGNAME-$CPU.tar.bz2

# Extract package if it is not extracted yet
if [ ! -d $SOURCEDIR ]
then
  bzip2 -dc $SOURCEFILE | tar xvC $BASEDIR

  cd $BASEDIR
  cat $FULLPKGNAME.patch | patch -Np0
fi

# Remove old package directory and make a new one
if [ -d $PACKAGEDIR ]
then
  rm -r $PACKAGEDIR
fi
mkdir $PACKAGEDIR

# Compile in source directory

#cd $SOURCEDIR
#make distclean

# Create a build directory

rm -r $BUILDDIR
mkdir $BUILDDIR
cd $BUILDDIR

# Configure package

$SOURCEDIR/configure \
--prefix=/usr \
--sysconfdir=/etc/X11 \
--enable-shared \
--disable-static \
--enable-final \
--disable-nls \
--disable-rpath \
--with-gnu-ld

# Start compiling

make

# Run the tests

make -k check

# Install the package to our own directory

make DESTDIR=$PACKAGEDIR install

# Do post-install stuff

## Strip libraries

cd $PACKAGEDIR/usr/lib
strip -g *.so

# Change file and directory ownerships

cd $PACKAGEDIR
#chown -R 0:0 .

# Compress binary package

tar -cC $PACKAGEDIR . | bzip2 -c9 > $PACKAGEFILE

