#!/bin/bash

if [ $# -eq 0 ] ; then
    echo "

After installing icmake using Debian (or a comparable distribution) the
installed icmake programs don't depend on the bobcat library. Once icmake has
been installed bobcat (i.e., libbobcat-dev) can also be installed.  Having
installed bobcat this script can be used to rebuild icmake's binaries, which
are then linked to bobcat's shared library, resulting in a reduction of the
sizes of icmake's binaries of about 40%.

After executing the 'rebuild' script icmake's binary programs are made
available in ./tmp/usr/libexec/icmake and in ./tmp/usr/bin. Those programs can
then safely be moved to, respectively, /usr/libexec/icmake and /usr/bin,
replacing the programs initially installed by 'apt install icmake'.

Provide any argument to start $0
"
    exit 1
fi

./clean
./prepare /

mkdir -p tmp/usr/libexec/icmake tmp/usr/bin

build2nd/libsupport

for target in spch multicmp comp dep exec pp un
do
    cd $target
    echo building icm-$target
    icmbuild
    mv tmp/bin/binary ../tmp/usr/libexec/icmake/icm-$target
    icmbuild clean
    cd ..
done

mv tmp/usr/libexec/icmake/icm-multicmp tmp/usr/libexec/icmake/icm-multicomp 

for target in icmake icmbuild modmap 
do
    cd $target
    echo building $target
    icmbuild
    mv tmp/bin/binary ../tmp/usr/bin/$target
    icmbuild clean
    cd ..
done


