#! /bin/sh

make acinclude.m4
rm -rf killustrator.dist
cp -rp killustrator killustrator.dist
rm -rf killustrator.dist/etc killustrator.dist/koffice
cp -p admin/install-sh admin/ltmain.sh admin/ltconfig admin/missing admin/mkinstalldirs killustrator/etc/acinclude.m4 killustrator/etc/configure.in COPYING INSTALL killustrator/kil.dtd admin/config.guess admin/config.sub admin/am_edit killustrator.dist
mkdir killustrator.dist/po
cp -p ../kde-i18n/templates/koffice/killustrator.pot killustrator.dist/po
cp -p killustrator/etc/po_Makefile.am killustrator.dist/po/Makefile.am
list=""
for file in ../kde-i18n/*/messages/koffice/killustrator.po; do
   lang=`echo $file | awk -F '/' '{ print $3 }'`
   cp -p $file killustrator.dist/po/$lang.po
   msgfmt $file -o killustrator.dist/po/$lang.gmo
   list="$list $lang.gmo"
done
dlist=""
for file in ../kde-i18n/*/docs/koffice/killustrator; do
   lang=`echo $file | awk -F '/' '{ print $3 }'`
   echo $lang
   mkdir killustrator.dist/doc/$lang
   cp $file/* killustrator.dist/doc/$lang
   dlist="$dlist $lang"
   cp killustrator/doc/$lang/Makefile.standalone killustrator.dist/doc/$lang/Makefile.am
done
echo "append SUBDIRS = $dlist"
echo "SUBDIRS = de en" >> killustrator.dist/doc/Makefile.am

# remove killustrator from SUBDIRS. Every other instance doesn't hurt :)
for i in killustrator.dist/Makefile*; do 
  sed -e "s#koffice#po#" $i > $i.new && mv $i.new $i
done

# convert png icons back into xpm
echo "icons..."
cd killustrator.dist/pics
for file in *.png; do
    name=`basename $file .png`
    convert $file $name.xpm
done
rm -f *.png
mv Makefile.am Makefile.am.orig
sed 's/png/xpm/g' < Makefile.am.orig > Makefile.am
rm Makefile.am.orig

cd ../../killustrator.dist
find . -name \".deps\" | xargs rm -rf  
find . -name CVS | xargs rm -rf  
find . -name ".cvsignore" | xargs rm -f  

sed -e "s#@GMOFILES@#$list#" po/Makefile.am > po/Makefile.am.new && mv po/Makefile.am.new po/Makefile.am
echo 'dist-hook:' >> Makefile.am
echo -e "\tcd \$(top_distdir) && perl \$(top_srcdir)/am_edit" >> Makefile.am
echo "" >> Makefile.am
sed 's#^myown_dist = #myown_dist = am_edit#' Makefile.am | sed 's#SUBDIRS = share filter xmlutils standalone po pics#SUBDIRS = share filter xmlutils standalone po pics doc#' > Makefile.am.2
mv Makefile.am.2 Makefile.am
sed -e "s/\$(LIB_KIMGIO)/\$(LIB_KIMGIO) \$(LIBJPEG) \$(LIBTIFF)/" standalone/Makefile.am > standalone/Makefile.am.new && mv standalone/Makefile.am.new standalone/Makefile.am
aclocal
autoheader
automake --gnu --include-deps
perl am_edit 
autoconf

# if the following fails, try it by hand.
echo "CONFIGURE"
./configure --with-qt-dir=/usr/local/qt-1.44
make dist

