#!/bin/sh
set -e
# pass commandline arguments to dpkg-buildpackage

cat <<EOT
****************************************************************
*               This is a build for i386                       *
****************************************************************
EOT

set -x
#pdebuild --debbuildopts "-i\.git -I.git $*"

cat > ~/.pbuilderrc <<EOT
# AUTO_DEBSIGN=yes
PKGNAME_LOGFILE=yes
SOURCE_ONLY_CHANGES=yes
# BUILDRESULT=$BUILDDIR
# HOOKDIR=${HOME}/.pbuilder
BASEPATH="/var/cache/pbuilder/i386.cow"
# BINDMOUNTS="/home/vagrant/_pbuilder_local_deps /dev/shm"
# This is a workaround a problem that /dev/shm is not mounted in pbuilder chroot
# BINDMOUNTS="/dev/shm"
EOT

STABLEVERSION=""
if [ $# = 1 ] ; then
    STABLEVERSION="-v$1"
fi
# FIXME: This does not work
STABLEVERSION=""

/usr/bin/pdebuild --pbuilder cowbuilder --buildresult `dirname \$PWD` --debbuildopts "$STABLEVERSION $SOURCEONLY" --debsign-k "Andreas Tille <tille@debian.org>"
NAME_VER=`dpkg-parsechangelog | awk '/^Source:/ {print $2}'`_`dpkg-parsechangelog | awk '/^Version:/ {print $2}' | sed 's/[0-9]\+://'`
if echo $@ | grep -q -- "-S" ; then
  echo "Building source only upload"
else
  echo "Removing source.changes"
  rm -f ../${NAME_VER}_source.changes
fi
lintian -i ../${NAME_VER}_*.changes
