#!/bin/bash

cd build2nd

if [ ! -e libsupport ] ; then
    echo 'call this script from ~/src/icmake to construct ../tmp/libicmake.a'
    exit 1
fi

mkdir -p ../tmp/support

cp -r ../xerr ../tmp/support            # icmake/tmp/support: constrction dir

cp ../support/support.tgz ../tmp/support    # cp support.tgz, icmconf,
cp icmconf.support ../tmp/support/icmconf   #    CLASSES and INSTALL.im
cp CLASSES.support ../tmp/support/CLASSES
cp ../tmp/INSTALL.im ../tmp/support/

cd ../tmp/support                       # at icmake/tmp/support

tar xzf ../../support/support.tgz       # extract the support.tgz in support/

icmbuild                                # construct the library in ./tmp

mv tmp/libtmp.a ../libicmake.a          # mv the lib. to icmake/tmp

mkdir -p ../build                       # tmp/build receives the .h/.f files
(tar cf - */*.h */*.f) | (cd ../build; tar xf -)

rm -r ../support                        # rm the now SF icmake/tmp/support dir
