# kdeutils

. ../globals.sh

SOURCE_FILE_NAME=kdeutils-$VER.tar.bz2
wd=`pwd`/kdeutils-$VER

untar_it()
{
  i=$TARS_DIR/$SOURCE_FILE_NAME
  if [ ! -f $i ] ; then
    echo cannot untar file $i >&2
    return 1
  fi

  if [ -d $wd ] ; then return 0; fi

  bunzip2 <$i | tar xf -
}


remove_warnings()
{
  w_list=`find . -name '*.c' -o -name '*.cc' -o -name '*.cpp' | xargs egrep -l '^[ 	]*#[ 	]*warning'`
  tfile=/tmp/rwrw$$
  for i in $w_list
  do
    sed '/^[ 	]*#[ 	]*warning/s!.*!/* & */!' <$i >$tfile
    cp $tfile $i
  done
  rm -f $tfile
}

patch_it()
{
  if [ -f $wd/configure.orig ] ; then
    return 0
  fi

  remove_warnings

  pfile=$PATCHES_DIR/kdeutils-$VER-osr6.patch

  cd $wd
  [ -f $pfile ] && gpatch -p0 -b -z .00 -i $pfile
  cd ..

  pfile=`ls -dt *patch.* 2>/dev/null | sed 1q`
  if [ x$pfile = x ] ; then return 0; fi

  patch -p0 -cb -i $pfile
}

config_it()
{
  # note: -lfs is only required with "-g"
  (cd $wd;
   LIBS="-lm -lgen -lfs" CFLAGS="$GLOBALCFLAGS -I$BUILDROOT/xenv/include" CXXFLAGS="$CFLAGS" DO_NOT_COMPILE="kfloppy kmilo klaptopdaemon kdf superkaramba" ./configure -prefix $KDEDIR -x-includes=/usr/X11R6/include -x-libraries=/usr/X11R6/lib --with-extra-includes=/usr/java/include/unixware $CFGHINT 2>&1 | tee $LOGDIR/kdeutils-configure
  )
}

build_it()
{
  (cd $wd; time gmake 2>&1 | tee $LOGDIR/kdeutils)
}

install_it()
{
  (cd $wd; time gmake install 2>&1 | tee $LOGDIR/kdeutils-install)
}

make_patch()
{
  foodir=`basename $wd`
  pfile=kdeutils.patch.`date +%y%j%H%M`
  for i in `find $foodir -name '*.orig'`; do
    f=`echo $i | sed 's/.orig$//'`
    diff -c $f.orig $f
    cp $f /tmp
  done >$pfile

}
