#! /bin/bash

unset LANG

if [ "$1" = "--dist" ] ; then
  dist="--target $2"
  shift
  shift
fi

branch=master
[ -n "$1" ] && branch=$1

clean_target=clean
grep -q -s distclean: Makefile* && clean_target=distclean

git status
git checkout $branch
git pull

make $clean_target

if [ -d package ] ; then
  echo 'old archive files found!'
  exit 1
fi

make archive

tobs $dist

make $clean_target
