#!/bin/sh

BUILDDIR=/usr/local/src/mono/1.9.1

# This is needed to pick up our built mono for commands
export PATH=/usr/local/bin:$PATH 

apt-get install -y build-essential bison gawk
apt-get install -y libglib2.0-dev
apt-get install -y libpng12-dev libx11-dev libfontconfig1-dev
apt-get install -y libfreetype6-dev libjpeg62-dev libtiff4-dev
apt-get install -y libungif4-dev libexif-dev libcairo2-dev
apt-get install -y libpango1.0-dev libgtk2.0-dev libglade2-dev
apt-get install -y libgnome2-dev libgnomecanvas2-dev libgnomeui-dev
apt-get install -y libgnomeprint2.2-dev libgnomeprintui2.2-dev
apt-get install -y libpanel-applet2-dev libgtksourceview-dev
apt-get install -y libgtkhtml3.14-dev
apt-get install -y intltool

apt-get remove 'mono-*' libgdiplus

mkdir -p $BUILDDIR
cd $BUILDDIR

wget -c http://go-mono.com/sources/libgdiplus/libgdiplus-1.9.tar.bz2
tar xvf libgdiplus-1.9.tar.bz2
cd libgdiplus-1.9
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://go-mono.com/sources/mono/mono-1.9.1.tar.bz2
tar xvf mono-1.9.1.tar.bz2

cat > $$-mono-boehm.gc <<GCPATCH
--- mono-1.9.1/mono/metadata/boehm-gc.c	2008-01-29 23:02:34.000000000 +0100
+++ mono-1.9.1-gc/mono/metadata/boehm-gc.c	2008-06-30 20:05:41.000000000 +0200
@@ -106,7 +106,26 @@
 void
 mono_gc_collect (int generation)
 {
-	GC_gcollect ();
+       static int no_explicite_gc = 0;
+       if (no_explicite_gc == 0)
+       {
+               if (getenv("GC_NO_EXPLICIT"))
+               {
+                       no_explicite_gc = 1;
+                       return;
+               }
+               else
+               {
+                       no_explicite_gc = 2;
+               }
+       }
+       else if (no_explicite_gc==1)
+       {
+               g_print("\n --------GC_NO_EXPLICIT \n");
+               return;
+       }
+
+       GC_gcollect ();
 }
 
 int
GCPATCH
patch -p0 < $$-mono-boehm.gc
rm $$-mono-boehm.gc
cd mono-1.9.1
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://switch.dl.sourceforge.net/sourceforge/nant/nant-0.86-beta1-src.tar.gz
tar xvf nant-0.86-beta1-src.tar.gz
cd nant-0.86-beta1
make 
make install
cd ..

wget -c http://ftp.novell.com/pub/mono/sources/gtk-sharp212/gtk-sharp-2.12.0.tar.bz2
tar xvf gtk-sharp-2.12.0.tar.bz2
cd gtk-sharp-2.12.0
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://ftp.novell.com/pub/mono/sources/gecko-sharp2/gecko-sharp-2.0-0.13.tar.bz2
tar xvf gecko-sharp-2.0-0.13.tar.bz2
cd gecko-sharp-2.0-0.13
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://go-mono.com/sources/gnome-sharp2/gnome-sharp-2.16.1.tar.gz
tar xvf gnome-sharp-2.16.1.tar.gz
cd gnome-sharp-2.16.1
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://go-mono.com/sources/gtksourceview-sharp2/gtksourceview-sharp-2.0-0.12.tar.bz2
tar xvf gtksourceview-sharp-2.0-0.12.tar.bz2
cd gtksourceview-sharp-2.0-0.12
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://ftp.novell.com/pub/mono/sources/gnome-desktop-sharp2/gnome-desktop-sharp-2.20.1.tar.bz2
tar xvf gnome-desktop-sharp-2.20.1.tar.bz2
cd gnome-desktop-sharp-2.20.1
./configure --prefix=/usr/local
make
make install
cd ..

cd mono-1.9.1
wget  -c http://go-mono.com/sources/monodoc/monodoc-1.9.zip
unzip monodoc-1.9.zip
cd monodoc-1.9
./configure --prefix=/usr/local
make
make install
cd ../..

wget -c http://go-mono.com/sources/mono-tools/mono-tools-1.9.tar.bz2
tar xvf mono-tools-1.9.tar.bz2
cd mono-tools-1.9
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://ftp.novell.com/pub/mono/sources/mono-debugger/mono-debugger-0.60.tar.bz2
tar xvf mono-debugger-0.60.tar.bz2
cd mono-debugger-0.60
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://ftp.novell.com/pub/mono/sources/heap-buddy/heap-buddy-0.2.tar.gz
tar xvf heap-buddy-0.2.tar.gz
cd heap-buddy-0.2
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://ftp.novell.com/pub/mono/sources/mono-addins/mono-addins-0.3.1.tar.bz2
tar xvf mono-addins-0.3.1.tar.bz2
cd mono-addins-0.3.1
./configure --prefix=/usr/local
make
make install
cd ..

wget -c http://ftp.novell.com/pub/mono/sources/monodevelop/monodevelop-1.0.tar.bz2
tar xvf monodevelop-1.0.tar.bz2
cd monodevelop-1.0
./configure --prefix=/usr/local
make
make install
cd ..
