# kdelibs

. ../globals.sh

SOURCE_FILE_NAME=kdelibs-$VER.tar.bz2
wd=`pwd`/kdelibs-$VER
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$wd/kdefx/.libs:$wd/kdecore/.libs:$wd/dcop/.libs
export LD_LIBRARY_PATH




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 -
}

# patches kde community supplies to this release
do_kde_patches()
{
  if [ x"$patch_list" = x ] ; then return 0; fi

  for f in $patch_list
  do
    # no backup file, this becomes the new base from our perspective
    (cd $wd; gpatch -p0 -u <$PATCHES_DIR/$f)
  done
}

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 $tfile
}

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

  do_kde_patches

  remove_warnings

  pfile=$PATCHES_DIR/kdelibs-$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()
{

  (cd $wd;
   PATH=$PATH:/usr/lib/cups/bin LIBS="-lm -lgen" CFLAGS="$GLOBALCFLAGS -I$BUILDROOT/xenv/include" CXXFLAGS="$CFLAGS" ./configure -prefix $KDEDIR -x-includes=/usr/X11R6/include -x-libraries=/usr/X11R6/lib $CFGHINT 2>&1 | tee $LOGDIR/kdelibs-configure
  )
}

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

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

make_patch()
{
  foodir=`basename $wd`
  pfile=kdelibs.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

}
