#!/bin/sh
export LANG=C
SRC_DIR=/usr/src/distfiles
CWD=`pwd`
export WORK=$CWD/work
export WORK_PKG=$CWD/work/pkg
export CFLAGS="-O2"
export MAKEFLAGS="-j 2"
SRC_VERSION=0.0
ARCHI_VERSION=noarch
BUILD_VERSION=P1
SRC_FILE=egg-canna.el
#SRC_PATCH="\
#egg_4.0.6+0.20041122cvs-11.diff.gz"
PATH=$PATH:/opt/kde/bin:/usr/bin:/opt/www/htdig/bin:/usr/X11R6/bin

# remove work directory
if [ -d $WORK ]; then
  rm -rf $WORK;
fi;
mkdir $WORK

# check source file
# if not exist, get files.
for i in $SRC_FILE ; do 
  if [ ! -f $SRC_DIR/$i ]; then
    (cd $SRC_DIR; wget http://cgi18.plala.or.jp/nyy/canna/$i);
  fi;
done

#for i in $SRC_PATCH ; do 
#  if [ ! -f $SRC_DIR/$i ]; then
#    (cd $SRC_DIR; wget http://ring.asahi-net.or.jp/pub/linux/debian/debian/pool/main/e/egg/$i);
#  fi;
#done

echo "Building egg-canna.el..."
mkdir -p $WORK_PKG/usr/share/emacs/site-lisp
cp $SRC_DIR/$SRC_FILE $WORK_PKG/usr/share/emacs/site-lisp

mkdir -p $WORK_PKG/usr/share/doc/egg-canna
chown -R root.root $WORK_PKG/usr/share/doc/egg-canna

mkdir -p $WORK_PKG/usr/share/doc/egg-canna/build
cp -ap $CWD/PlamoBuild \
  $WORK_PKG/usr/share/doc/egg-canna/build

#make package
cd $WORK_PKG
echo "y
" | makepkg eggcanna-${SRC_VERSION}.tgz
mv eggcanna-${SRC_VERSION}.tgz $CWD/eggcanna-${SRC_VERSION}-${ARCHI_VERSION}-${BUILD_VERSION}.tgz
cd $CWD
