# i18n

. ../globals.sh

SOURCE_DIR_NAME=$TARS_DIR/i18n
wd=`pwd`

patch_list=

untar_it()
{
  for i in $SOURCE_DIR_NAME/*$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' | 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/i18n-$VER-osr6.patch

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

  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 *i18n*$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 *i18n*$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 *i18n*$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 *i18n*$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=i18n.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

}
