#! /bin/bash

# Usage of the works is permitted provided that this
# instrument is retained with the works, so that any entity
# that uses the works is notified of this instrument.
#
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.

release="$1"
revision="$2"

if [ -z "$release" ]
then
  echo No release specified!
  exit
fi

if [ -f "ldebug$release.zip" ]
then
  echo Zipball exists!
  exit
fi
if [ -f "ldebug$release.tlz" ]
then
  echo Tarball exists!
  exit
fi
if [ -d ld.bld ]
then
  echo Directory exists!
  exit
fi

if ! hg clone ldebug ld.bld
then
  echo clone error
  exit
fi

cd ld.bld
if ! hg update $revision
then
  echo update error
  exit
fi

cd source
INICOMP_METHOD="lz4 lzd exodecr" use_build_decomp_test=1 \
 ./make -D_VERSION="' release 1 (',__DATE__,')'"
./makinst.sh

cd ../doc
./mak.sh

cd ..
7za -tzip a "../ldebug$release.zip" . -xr'!*.hg*'
tar --lzip --exclude-vcs -cf "../ldebug$release.tlz" .

cd ..
7za l "ldebug$release.zip"
tar -tf "ldebug$release.tlz"

