if [[ $# -ne 4 ]]; then
   echo Bad parameters  [fnmt,fnmtdnie,dnie,tif] [MAJOR] [MINOR] [FIX]
   exit 1
fi

CFGDIST=$1
CFGMAJOR=$2
CFGMINOR=$3
CFGFIX=$4

OS=$(lsb_release -si)
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
VER=$(lsb_release -sr)

RELEASEDIR=../RELEASE-$OS-$VER-$ARCH-bits
SRCDIR=../../src
BUILDDIR=/tmp/build
rm -f $BUILDDIR/../*.deb
rm -rf $BUILDDIR
mkdir $BUILDDIR
cp -R $SRCDIR/* $BUILDDIR
cp -R ../common.autotools/* $BUILDDIR
cp -R all/* $BUILDDIR
cp -R card-$CFGDIST/* $BUILDDIR
pushd $BUILDDIR
find ./ -type f | xargs sed -i s/#CFGDIST#/$CFGDIST/g
find ./ -type f | xargs sed -i s/#CFGMAJOR#/$CFGMAJOR/g
find ./ -type f | xargs sed -i s/#CFGMINOR#/$CFGMINOR/g
find ./ -type f | xargs sed -i s/#CFGFIX#/$CFGFIX/g
autoreconf -if
dpkg-buildpackage -rfakeroot -us -uc -j2 -b
popd
mkdir $RELEASEDIR
cp $BUILDDIR/../*.deb $RELEASEDIR
cp $BUILDDIR/test_DIST/libpkcs11-$CFGDIST-test-dist $RELEASEDIR
cp $BUILDDIR/test_P11/libpkcs11-$CFGDIST-test-p11 $RELEASEDIR
