#! /bin/sh -e 
unset CDPATH
unset LANG
LC_ALL=C
export LC_ALL CDPATH LANG
USAGE="Start this from base directory of the checked out CVS tree.
First parameter should be next build version ($1)."

# Option handling
while getopts 'n' f ; do
  case $f in
    n)
	#
	# Always build with latest unstable (I should use p-builder)
	#
	sudo aptitude update
	sudo aptitude dist-upgrade
	# Build-Depends-Indep packages
	sudo aptitude install \
          debhelper debiandoc-sgml tetex-bin tetex-extra w3m \
          cjk-latex freetype1-tools \
          tfm-arphic-bsmi00lp tfm-arphic-bkai00mp \
          tfm-arphic-gbsn00lp tfm-arphic-gkai00mp \
          hbf-jfs56 hbf-cns40-b5 hbf-kanji48
       ;;
    \?)      echo "$USAGE"; exit;;
  esac
done
shift $(($OPTIND - 1))

if [ "$0" != "bin/qrefnew" ] || [ $# != 1 ] ; then
  echo "$USAGE"
  exit
fi
MAINTAR=debian-reference_1.08
#
cd ..
cvs -d:ext:osamu@cvs.sf.net:/cvsroot/qref \
 export -D tomorrow -d $MAINTAR-$1 qref
# No need to include .cvsignore
rm -f $MAINTAR-$1/.cvsignore
# CVS permission bad.  Next source orig.tar.gz will be fixed
#chmod 644 $MAINTAR-$1/examples/*
if [ "$1" == "1" ]; then
 cp -a $MAINTAR-$1 $MAINTAR.orig
 cd $MAINTAR.orig
 rm -Rf debian
 cd ..
 tar -cvzf $MAINTAR.orig.tar.gz $MAINTAR.orig
fi
cd $MAINTAR-$1 ; dpkg-buildpackage -rfakeroot
cd ..
lintian -i $MAINTAR-$1_i386.changes >log.lintian
linda   -i $MAINTAR-$1_i386.changes >log.linda
