#!/bin/bash
# Author: David E. Fox
#set -x
# adapt DIRS to your needs
DIRS="kdelibs kdebase kdesupport kdegames kdegraphics kdemultimedia kdenetwork kdetoys kdeutils kdepim kdoc klyx koffice kdesdk kdevelop kdeadmin"

BASE=/opt/kde
LOG=$BASE/buildall.log
function dodate
{
    echo -n `date +%Y%m%d-%k:%M` >>$LOG
    echo -n '  ' >>$LOG
}

#rm -f $LOG
dodate
echo "./buildall $DIRS" >>$LOG
for i in $DIRS
do
    cd $BASE/$i
    dodate
    echo "$i Start" >>$LOG
    make -f Makefile.cvs
    if [ $? != 0 ]
    then
        dodate
        echo "$i Makefile.cvs failed" >>$LOG
        exit 1
    fi

    if [ -f rex_configure ]
    then
        CONF=`cat rex_configure`
    else
        CONF="./configure"
    fi
    CONF="$CONF $CONFOPTS"

    dodate
    echo "$i $CONF" >>$LOG
    $CONF
    if [ $? != 0 ]
    then
        dodate
        echo "$i configure failed" >>$LOG
        exit 1
    fi

    # make clean
    dodate
    echo $i "make -j2" >>$LOG
    #  make MAKE="make -j2"
    make MAKE="make"
    if [ $? != 0 ]
    then
        dodate
        echo "$i make -j2 failed, trying -j1" >>$LOG
        make
        if [ $? != 0 ]
        then
            dodate
            echo "$i make failed" >>$LOG
            exit 1
        fi
    fi

    dodate
    echo $i "make install" >>$LOG
    #   sudo make install
    make install
    if [ $? != 0 ]
    then
        dodate
        echo "$i make install failed" >>$LOG
        exit 1
    fi
done

dodate
echo "fin" >>$LOG