# kdevelop

. ../globals.sh

VER=3.3.2
LOGDIR=$LOGDIR/kdevelop
[ -d $LOGDIR ] || mkdir -p $LOGDIR

LD_LIBRARY_PATH=$TOP/3.5.2/kdevelop/kdevelop-$VER/lib/interfaces/external/.libs:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

DO_NOT_COMPILE=""
I_LD=$LD_LIBRARY_PATH
export DO_NOT_COMPILE I_LD

SOURCE_DIR_NAME=$TARS_DIR
wd=`pwd`

patch_list=

untar_it()
{
  for i in $SOURCE_DIR_NAME/kdevelop*$VER*.tar.bz2
  do
    if [ ! -f $i ] ; then
      echo cannot untar file $i >&2
      return 1
    fi
    bunzip2 <$i | /usr/gnu/bin/tar xf -
  done
}

# 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' -o -name '*.h' \
      | xargs egrep -l '^[ 	]*#[ 	]*warning'`
  tfile=/tmp/rwrw$$
  for i in $w_list
  do
    sed '/^[ 	]*#[ 	]*warning/s!.*!/* & */!' <$i >$tfile
    [ -f $tfile ] && cp $tfile $i
  done
  rm -f $tfile
}

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

  do_kde_patches

  remove_warnings

  for dir in kdevelop*$VER*
  do
    pfile=$PATCHES_DIR/$dir-osr6.patch
    cd $dir
    [ -f $pfile ] && gpatch -p0 -b -z .00 -i $pfile
    cd ..
  done
  pfile=`ls -dt *patch.* 2>/dev/null | sed 1q`
  if [ x$pfile = x ] ; then return 0; fi

  gpatch -p0 -b <$pfile
}

config_it()
{
  for dir in kdevelop*$VER*
  do
    [ -x $dir/configure ] && {
      wd=`pwd`/$dir
      cd $wd
      LIBS="-lm -lgen -lfs" CFLAGS="$GLOBALCFLAGS -I$BUILDROOT/xenv/include" CXXFLAGS="$CFLAGS" ./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/$dir-configure
      cd ..
      wd=`pwd`
    }
  done
}

build_it()
{
  for dir in kdevelop*$VER*
  do
    [ -x $dir/configure ] && {
      wd=`pwd`/$dir
      cd $wd
      time gmake 2>&1 | tee $LOGDIR/$dir
      cd ..
      wd=`pwd`
    }
  done
}

resume_build()
{
  for dir in kdevelop*$VER*
  do
    [ -x $dir/configure ] && {
      wd=`pwd`/$dir
      cd $wd
      [ -f $LOGDIR/$dir ] || {
        time gmake 2>&1 | tee $LOGDIR/$dir
      }
      cd ..
      wd=`pwd`
    }
  done
}

install_it()
{
  for dir in kdevelop*$VER*
  do
    [ -x $dir/configure ] && {
      wd=`pwd`/$dir
      cd $wd
      time gmake install 2>&1 | tee $LOGDIR/$dir-install
      cd ..
      wd=`pwd`
    }
  done
}

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

}
