#!/bin/sh
# simon@kde.org

src=$1
dst=$2

echo "*** preparing kde sources (from $src into $dst) ..."

if test ! -x $src; then
	echo "Cannot find kde (kdelibs) sources. Make sure they can be found"
	echo "at the same level as this module (like ../kdelibs) or set the"
	echo "KDESRC environment variable to the directory which contains the"
	echo "kdelibs directory."
	exit 255
fi

# starting with kdecore stuff

cp $src/kdecore/kurl.{cpp,h} $dst/kdecore/

cp $src/kdecore/krfcdate.{cpp,h} $dst/kdecore/

cp $src/kdecore/kdatastream.h $dst/kdecore/

cp $src/kdecore/ksock.{cpp,h} $dst/kdecore/

cp $src/kdecore/kcharsets.{cpp,h} $dst/kdecore/

cp $src/kdecore/kentities.c $dst/kdecore

cp $src/kdecore/ksharedptr.h $dst/kdecore

cp $src/kdecore/kstddirs.{cpp,h} $dst/kdecore

cp $src/kdecore/ktempfile.{cpp,h} $dst/kdecore

cp $src/kdecore/ksavefile.{cpp,h} $dst/kdecore

cp $src/kdecore/charsets.config $dst/kdecore/charsets

# let's move over Waldo's KCookieJar

cp $src/kio/http/kcookiejar/kcookie*.{cpp,h} $dst/kio/http/kcookiejar/

# now the http ioslave

cp $src/kio/http/*.{c,cpp,cc,h} $dst/kio/http/

# some more kio stuff

cp $src/kio/global.h $dst/kio

cp $src/kio/slaveinterface.{cpp,h} $dst/kio

cp $src/kio/connection.{cpp,h} $dst/kio

# Harri's javascript

cp $src/kjs/*.{cpp,h} $dst/kjs

cp $src/kjs/README $dst/kjs

cp $src/kjs/THANKS $dst/kjs

cp $src/kjs/configure.in.in $dst/kjs

# we need the partmanager and some other stuff from kparts

cp $src/kparts/partmanager.{cpp,h} $dst/kparts

cp $src/kparts/event.{cpp,h} $dst/kparts

cp $src/kparts/browserextension.{cpp,h} $dst/kparts

cp $src/kparts/factory.{cpp,h} $dst/kparts

# now let's get the big baby :-)

# some small cleanup first, to shut up cp
find $dst/khtml -type d -name ".libs" | xargs rm -rf 

cp $src/khtml/*.{cpp,h,cc} $dst/khtml/

rm $dst/khtml/khtml_ext.*
rm $dst/khtml/khtml_find.*

cp -a $src/khtml/rendering $dst/khtml

cp -a $src/khtml/html $dst/khtml

cp -a $src/khtml/dom $dst/khtml

cp -a $src/khtml/xml $dst/khtml

cp -a $src/khtml/css $dst/khtml

cp -a $src/khtml/ecma $dst/khtml

cp -a $src/khtml/misc $dst/khtml

find $dst/khtml/ -type f -name "*.lo" | xargs rm -rf

# don't forget KSSL :)

find $dst/kssl -type d -name ".libs" | xargs rm -rf 
### hack
rm -rf $dst/kssl/.libs
rm -rf $dst/kssl/.deps

find $src/kssl/* -maxdepth 0 ! -name "Makefile.am" ! -name "CVS" ! -name "ksslinfodlg.*" -exec cp -a {} $dst/kssl \;

rm -rf $dst/kssl/.libs
rm -rf $dst/kssl/.deps
rm -rf $dst/kssl/*.lo
rm -rf $dst/kssl/*.o

find $dst/kssl/kssl -type d -name "CVS" | xargs rm -rf

for i in ./kdesrc/khtml/rendering/Makefile.am \
	 ./kdesrc/khtml/html/Makefile.am \
	 ./kdesrc/khtml/dom/Makefile.am \
 	 ./kdesrc/khtml/xml/Makefile.am \
	 ./kdesrc/khtml/misc/Makefile.am \
	 ./kdesrc/khtml/ecma/Makefile.am \
	 ./kdesrc/khtml/css/Makefile.am ; do
    perl -pi -e "s,\\$\(all_includes\),-I\\$\(srcdir\)/../../../dropin -I\\$\(srcdir\)/../../kdecore -I\\$\(srcdir\)/../.. -I\\$\(srcdir\)/.. -I\\$\(srcdir\)/../misc -I\\$\(srcdir\)/../misc -I\\$\(srcdir\)/../css -I\\$\(srcdir\)/../dom -I\\$\(srcdir\)/../xml -I\\$\(srcdir\)/../html -I\\$\(srcdir\)/../../../dropin/kio -I\\$\(srcdir\)/../../kjs -I\\$\(srcdir\)/../../../dropin/khtml \\\$\(QT_INCLUDES\) \\$\(X_INCLUDES\)," $i
    echo "KDE_OPTIONS = qtonly" >> $i
done;

perl -pi -e "s,lib_LTLIBRARIES,noinst_LTLIBRARIES," ./kdesrc/khtml/ecma/Makefile.am
perl -pi -e "s,\\$\(top_builddir\)/kjs/libkjs.la,../../kjs/libkjs.la," ./kdesrc/khtml/ecma/Makefile.am
perl -pi -e "s,myinclude_HEADERS,noinst_HEADERS," ./kdesrc/khtml/dom/Makefile.am
