#!/bin/bash

## Compiles KDE and puts it in /tmp/kde* directories
## so you can make them into slackware packages

TMP=/tmp
CWD=`pwd`
ARCH=i386
BUILD=1

for file in $* ; do
  file=`echo $file | sed s/\\\\/$//`;
  echo "Doing dir: $file"
  if [ -d $file ]; then
    if [ ! -f $file.done ]; then
      cd $file
      make clean
      rm -f config.h config.cache config.status Makefile
      export   CFLAGS="-O2 -march=i386 -mcpu=i686 -pipe -fomit-frame-pointer"
      export CXXFLAGS="-O2 -march=i386 -mcpu=i686 -pipe -fomit-frame-pointer"
      ./configure --prefix=/usr/local/kde --disable-debug --enable-final --with-gnu-ld --enable-fast-malloc=full --enable-dnotify --enable-fast-malloc
      echo "\$? is $?"
      if [ $? -eq 0 ]; then
          make
          echo "\$? is $?"
          if [ $? -eq 0 ]; then
              mkdir $TMP/$file
              make install DESTDIR=$TMP/$file
              cd $TMP/$file
              makepkg -l y -c n /$TMP/$file-$ARCH-$BUILD.tgz
              cd "$CWD"
              touch $file.done

              upgradepkg /$TMP/$file-$ARCH-$BUILD.tgz && touch /usr/src/kde/kde-3.2.0-beta1/$file.upgraded
              # installpkg /$TMP/$file-$ARCH-$BUILD.tgz

              mv /$TMP/$file-$ARCH-$BUILD.tgz /usr/src/kde/kde-3.2.0-beta1/packages/
              rm -rf /$TMP/$file
              
          fi
      fi
      cd "$CWD"
    fi
  fi
done
