#!/bin/bash

if [ "$#" == "0" ] ; then
echo "
    Usage: icm_bootstrap <any argument>

    Parser and scanner files generated by bisonc++ and flexc++ must already
    be available (which holds true for the standard distribution)

    Before calling this script icm_prepare must have been called.
"                                     
    exit 0
fi


if [ ! -e tmp/INSTALL.sh ] ; then
    echo tmp/INSTALL.sh does not exist. Execute ./icm_prepare to create it
    exit 1
fi

. bootstrap/functions

. tmp/INSTALL.sh
    # now BINDIR, SKELDIR, .... etc have been defined
    # the @SKELDIR@ etc. names in icmbuild and icmstart are converted by
    # icm_install, calling scripts/convert


# build icmake and its support programs

for target in support comp dep exec pp un   icmake icmbuild 
do
    cd $target
    ./icm_bootstrap || exit 1
    cd ..
done
# cp /usr/bin/{icmake,icmbuild} tmp/usr/bin/              || exit 1
# cp /usr/lib/icmake/{icm-*,icmun} tmp/usr/lib/icmake/    || exit 1
# echo

echo


echo ./scripts to ./tmp/{icmbuild.in,icmstart.in}
    # conversions by icm_install
cd scripts
    cp icmstart.sh ../tmp/icmstart.sh
    ./catim ib <icmbuild.in >../tmp/icmbuild.in
    ./catim is <icmstart.in >../tmp/icmstart.in
cd ..
echo

echo skeleton files in usr/share/icmake/ to tmp${SKELDIR}
try cp -r usr/share/icmake/* tmp${SKELDIR}
echo

echo configuration files in etc/icmake/ to tmp${CONFDIR}
try cp -r etc/icmake/* tmp${CONFDIR}
echo

cd doc

echo man-pages *.1 to tmp${MANDIR}/man1
for x in *.1 ; do
    gzip -9cn $x > ../tmp${MANDIR}/man1/$x.gz || exit 1
done
echo

echo man-pages *.7 to tmp${MANDIR}/man7
for x in *.7 ; do
    gzip -9cn $x > ../tmp${MANDIR}/man7/$x.gz  || exit 1
done
echo

echo ./changelog to tmp${DOCDIR}
cd ..
gzip -9cn changelog > tmp${DOCDIR}/changelog.gz || exit 1
echo

echo ./examples files to tmp${DOCDIR}
try cp -r examples tmp${DOCDIR}


echo ./etc files to tmp/etc
try cp -r etc  tmp/ 
echo

echo Done.


# The obsoleted document icmake.ps is no longer included in the distributions
# echo doc/icmake.ps and ./changelog to tmp${DOCDIR}
# gzip -9cn icmake.ps > ../tmp${DOCDOCDIR}/icmake.ps.gz  || exit 1

