#!/bin/sh

MINGW="/mingw/"
TMP_DIR="c:/temp"

GLIB_BASE="ftp://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.12"
GLIB_PACKAGES="glib-2.12.1 glib-dev-2.12.1"

GTK_BASE="ftp://ftp.gtk.org/pub/gtk/v2.8/win32/"
GTK_PACKAGES="gtk+-2.8.20 gtk+-dev-2.8.20 pango-1.10.3 pango-dev-1.10.3 atk-1.10.3 atk-dev-1.10.3 cairo-1.2.4 cairo-dev-1.2.4"

GTK_DEP_BASE="ftp://ftp.gtk.org/pub/gtk/v2.8/win32/dependencies/"
GTK_DEP_PACKAGES="fontconfig-2.2.2-20040412 fontconfig-dev-2.2.2-20040412 freetype-2.1.10 gettext-0.14.5 gettext-dev-0.14.5 pkg-config-0.20 zlib123-dll libiconv-1.9.1.bin.woe32 libpng-1.2.8-bin"

LIBART_BASE="ftp://ftp.gnome.org/pub/gnome/binaries/win32/libart_lgpl/2.3"
LIBART_PACKAGES="libart_lgpl-2.3.17 libart_lgpl-dev-2.3.17"

MINGW_BASE="http://heanet.dl.sourceforge.net/sourceforge/gnuwin32/"
MINGW_PACKAGES="libpng-1.2.7-bin libpng-1.2.7-dep libpng-1.2.7-lib jpeg-6b-4-bin jpeg-6b-4-dep jpeg-6b-4-lib tiff-3.8.2-1-bin tiff-3.8.2-1-lib freetype-2.1.10-bin freetype-2.1.10-lib zlib-1.2.3-bin zlib-1.2.3-lib libgw32c-0.4-lib libiconv-1.9.2-1-bin libiconv-1.9.2-1-dep libiconv-1.9.2-1-lib"

EXPAT_BASE="ftp://ftp.jclark.com/pub/xml/"
EXPAT_PACKAGE="expat"
EXPAT_DLL="expat/bin/xmltok.dll"



cd $TMP_DIR

echo "Downloading glib packages..."
for PACKAGE in $GLIB_PACKAGES;
do
	if [ -e "$PACKAGE.zip" ]; then
		echo "  Already there - extracting $PACKAGE.";
	else
		echo "  Getting $PACKAGE.";
		wget "$GLIB_BASE/$PACKAGE.zip";
		fi
	echo "  Extracting $PACKAGE.";
	unzip -o -q "$PACKAGE.zip" -d $MINGW;
done
echo "OK"


echo "Downloading GTK dependency packages..."
for PACKAGE in $GTK_DEP_PACKAGES;
do
	if [ -e "$PACKAGE.zip" ]; then
		echo "  Already there - extracting $PACKAGE.";
	else
		echo "  Getting $PACKAGE.";
		wget "$GTK_DEP_BASE/$PACKAGE.zip";
		fi
	echo "  Extracting $PACKAGE.";
	unzip -o -q "$PACKAGE.zip" -d $MINGW;
done
echo "OK"

echo "Downloading GTK packages..."
for PACKAGE in $GTK_PACKAGES;
do
	if [ -e "$PACKAGE.zip" ]; then
		echo "  Already there - extracting $PACKAGE.";
	else
		echo "  Getting $PACKAGE.";
		wget "$GTK_BASE/$PACKAGE.zip";
		fi
	echo "  Extracting $PACKAGE.";
	unzip -o -q "$PACKAGE.zip" -d $MINGW;
done
echo "OK"

echo "Downloading libart_lgpl packages..."
for PACKAGE in $LIBART_PACKAGES;
do
	if [ -e "$PACKAGE.zip" ]; then
		echo "  Already there - extracting $PACKAGE.";
	else
		echo "  Getting $PACKAGE.";
		wget "$LIBART_BASE/$PACKAGE.zip";
		fi
	echo "  Extracting $PACKAGE.";
	unzip -o -q "$PACKAGE.zip" -d $MINGW;
done
echo "OK"

echo "Downloadung GnuWin32 packages..."
for PACKAGE in $MINGW_PACKAGES;
do
	if [ -e "$PACKAGE.zip" ]; then
		echo "  Already there - extracting $PACKAGE.";
	else
		echo "  Getting $PACKAGE.";
		wget "$MINGW_BASE/$PACKAGE.zip";
		fi
	echo "  Extracting $PACKAGE.";
	unzip -o -q "$PACKAGE.zip" -d $MINGW;
done
echo "OK"

echo "Downloading and installing expat"
if ! [ -e "$EXPAT_PACKAGE.zip" ]; then wget -q "$EXPAT_BASE/$EXPAT_PACKAGE.zip"; fi
unzip -o -q "$EXPAT_PACKAGE.zip" -d .
cp $EXPAT_DLL $MINGW/bin
echo "OK"

echo "Freetype"
cp -Rp $MINGW/include/freetype2/freetype $MINGW/include/freetype

