#!/bin/sh

while [ $# -gt 0 ]; do
  case $1 in
    gen) gen=yes; shift;;
    doc) docs=yes; shift ;;
    tgz) tgz=yes; shift ;;
    test) test=yes; shift ;;
    testclean) testclean=yes; shift ;;
    *) echo "DIST [doc][tgz][test][testclean]"; exit 0;;
  esac
done

if [ "$gen" = "yes" ]; then
  autoconf -I `gauche-config --ac`
fi

if [ "$tgz" = "yes" ]; then
  if [ -f Makefile ]; then make maintainer-clean; fi
  autoconf -I `gauche-config --ac`
  ./configure

  if [ ! -f VERSION ]; then echo "No VERSION; something wrong?"; exit 1; fi
  VERSION=`cat VERSION`

  (cd src; make stubs)
  make distclean

  rm -rf ../Gauche-gtk2-$VERSION
  rm -f DIST_EXCLUDE_X
  cat DIST_EXCLUDE > DIST_EXCLUDE_X
  find . -name CVS -print -prune >> DIST_EXCLUDE_X

  mkdir ../Gauche-gtk2-$VERSION
  tar cvfX - DIST_EXCLUDE_X . | (cd ../Gauche-gtk2-$VERSION; tar xf -)
  (cd ..; tar cvf - Gauche-gtk2-$VERSION | gzip -9 > Gauche-gtk2-$VERSION.tgz)
fi
