#!/bin/sh
# make a tarball for distribution
      
# bail on error
set -e

# tarball dist name; e.g. elsa-2002.08.12
distname=elsa-`date "+%Y.%m.%d"`
echo $distname

mkdir $distname || exit
cd $distname || exit

# main stuff
export CVSROOT=":ext:scott@manju.cs.berkeley.edu:/home/cvs-repository"
cvs export -D now smbase || exit
cvs export -D now ast || exit
cvs export -D now elkhound || exit
cvs export -D now elsa || exit

# toplevel files
cp elsa/toplevel/* .

# remove some files I don't want going into the external distribution
rm elsa/mkdist
rm -rf elsa/toplevel

# generated docs; I have to run "make doc" myself in my own checked-out
# versions before doing 'mkdist'
cp -a ../../smbase/gendoc smbase || exit
cp -a ../../ast/gendoc ast || exit
cp -a ../../elkhound/gendoc elkhound || exit
cp -a ../../elsa/gendoc elsa || exit

# package it up
cd ..
targz $distname || exit
rm -rf $distname

if [ "$1" = "-notest" ]; then
  echo "stopping without testing"
  exit 0
fi

# test it
untargz ${distname}.tar.gz
cd ${distname}
echo "building... (output in $distname/make.out)"
./configure >make.out 2>&1
make >>make.out 2>&1
make check >>make.out 2>&1

# make sure I can build the ocaml examples
(cd elkhound/ocaml; make) >>make.out 2>&1

# check for having run flex or bison
# UPDATE: have to run flex b/c it's how lexical extensions are added..
if egrep '^bison' make.out; then
  echo "We ran bison during the build; that's bad!"
  exit 2
fi

if egrep '^m4' make.out; then
  echo "We ran m4 during the build; that's bad!"
  exit 2
fi

# blow away the test directory
if [ "$1" != "-keep" ]; then
  cd ..
  rm -rf $distname
fi







