#! /bin/sh

WORKINGDIR=`pwd`
echo "** INFO -- Working directory: $WORKINGDIR"

# try to set the best BOOTSTRAP_MAKE variable: MAKE <+ gmake <+ make
BESTMAKE=
GMAKE="`which gmake`"

gmake -v

#if [ "$GMAKE" = "" ]
if [ "$?" != "0" ]
  then
    echo "** INFO -- gmake is not on the PATH. Assuming GNU Make is make!"
    BESTMAKE="`which make`"
  else
    BESTMAKE=$GMAKE
fi

BOOTSTRAP_MAKE=${MAKE-$BESTMAKE}
echo "** INFO -- Make is: $BOOTSTRAP_MAKE"
# end of setting BOOTSTRAP_MAKE

# touch bootstrapped sources because subversion doesn't sets the mtime of files
# to checkout time, not to the last mtime in the repository.
MTIME=`date +%Y%m%d%H%M.%S`
echo "** INFO -- Modification time: $MTIME"
find . -print | xargs touch -t $MTIME
# end of touch

# install bootstrap time packages: autoxt
mkdir -p pre-pkgs
mkdir -p pre-pkgs/bootstrap
cp -rf autoxt pre-pkgs/bootstrap/
cd pre-pkgs/bootstrap/autoxt
./bootstrap
./configure --prefix=$WORKINGDIR/pre-pkgs/bootstrap
$BOOTSTRAP_MAKE
$BOOTSTRAP_MAKE install

cd $WORKINGDIR
PATH=$WORKINGDIR/pre-pkgs/bootstrap/bin:$PATH
export PATH
echo "** INFO -- AutoXT is: `which autoxt`"
# end of autoxt install

# bootstrap the subpackages
PKGS="autoxt srts xtc sdf-import sc ssl gpp c-tools stratego-front aterm-tools asfix-tools dot-tools graph-tools sdf-front sdf-tools stratego-tools boxenv stratego-util"

for dir in $PKGS
do 
  echo
  echo "** INFO -- bootstrapping in $dir"
  echo
  (cd $dir; ./bootstrap)
done
# end of bootstrap the subpackages

# apply the autotools
touch README
touch NEWS

rm -f mkinstalldirs missing install-sh

rm -f config.cache
rm -f acconfig.h
aclocal -I .
autoconf
autoheader
automake -a

#
# autobundle -- Make distributions by bundling separate software packages.
#
# Copyright (C) 2000 Merijn de Jonge <mdejonge@cwi.nl>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
