# kdepim

. ../globals.sh

SOURCE_FILE_NAME=kdepim-$VER.tar.bz2
wd=`pwd`/kdepim-$VER
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$wd/kode/.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 -
}


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

  ln -s . work 2>/dev/null  # konstruct patches are based from work/...
  patch_list=
  echo patching using konstruct patch files
  for i in $patch_list ; do
    gpatch -p0 <$PATCHES_DIR/$i
  done

  remove_warnings

  pfile=$PATCHES_DIR/kdepim-$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" CFLAGS="$GLOBALCFLAGS -I$BUILDROOT/xenv/include" CXXFLAGS="$CFLAGS" DO_NOT_COMPILE="indexlib kitchensync" ./configure -prefix $KDEDIR -x-includes=/usr/X11R6/include -x-libraries=/usr/X11R6/lib --with-extra-includes=/usr/java/include/unixware --disable-indexlib --disable-indexlib-unittests $CFGHINT 2>&1 | tee $LOGDIR/kdepim-configure
   if [ -f libksieve/parser/Makefile ] ; then
      # work around optimizer problem
      /usr/bin/echo '1,$s/-O2 //\nw\nq' | ed libksieve/parser/Makefile >/dev/null 2>&1
#     # icalsslexer.l has flex extensions.  grab flex-ed output from another system
#     cp ../../misc/icalsslexer.c libkcal/libical/src/libicalss/icalsslexer.c
   fi
  )
}

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

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

make_patch()
{
  foodir=`basename $wd`
  pfile=kdepim.patch.`date +%y%j%H%M`
#  for i in `find $foodir -name '*.orig'`; do
# there is a kmfilter.cpp.orig in 3.2.1...
  for i in `find $foodir -name '*.orig' | grep -v kmfilter.cpp`; do
    f=`echo $i | sed 's/.orig$//'`
    diff -c $f.orig $f
    cp $f /tmp
  done >$pfile

}
