#!/bin/sh

# @(#) Gnome 2.12.1 Compilation script by Dirk Jagdmann <doj@cubic.org>
# version 2005-11-17

# to download files you need:
# wget ftp://ftp.gnu.org/gnu/wget/
# ncftpget http://ncftp.com/ncftp/

GNOMEGET=ftp://ftp.gnome.org/pub/GNOME/desktop/2.12/2.12.1/sources

GET="
ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.1.x/popt-1.7.tar.gz
ftp://ftp.remotesensing.org/pub/libtiff/tiff-3.7.4.tar.gz
http://www.zlib.net/zlib-1.2.3.tar.gz
ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
http://freedesktop.org/software/icon-theme/releases/hicolor-icon-theme-0.5.tar.gz
ftp://oss.sgi.com/projects/fam/download/stable/fam-2.7.0.tar.gz
http://easynews.dl.sourceforge.net/sourceforge/openjade/OpenSP-1.5.tar.gz
http://easynews.dl.sourceforge.net/sourceforge/openjade/openjade-1.3.2.tar.gz
ftp://ftp.xmlsoft.org/libxml2-2.6.22.tar.gz
ftp://ftp.xmlsoft.org/libxslt-1.1.15.tar.gz
http://dbus.freedesktop.org/releases/dbus-0.50.tar.gz
http://freedesktop.org/~david/dist/hal-0.5.5.1.tar.gz
http://www.freedesktop.org/software/desktop-file-utils/releases/desktop-file-utils-0.10.tar.gz

ftp://ftp.gtk.org/pub/gtk/v2.8/atk-1.10.1.tar.gz
ftp://ftp.gtk.org/pub/gtk/v2.8/glib-2.8.4.tar.gz
ftp://ftp.gtk.org/pub/gtk/v2.8/gtk+-2.8.7.tar.gz
ftp://ftp.gtk.org/pub/gtk/v2.8/pango-1.10.1.tar.gz
http://cairographics.org/releases/cairo-1.0.2.tar.gz
http://cairographics.org/snapshots/glitz-0.4.4.tar.gz

http://ftp.gnome.org/pub/GNOME/sources/glibmm/2.8/glibmm-2.8.1.tar.gz
http://ftp.gnome.org/pub/GNOME/sources/gtkmm/2.8/gtkmm-2.8.1.tar.gz
http://ftp.gnome.org/pub/GNOME/sources/libglademm/2.6/libglademm-2.6.1.tar.gz
http://ftp.gnome.org/pub/GNOME/sources/libgnomecanvasmm/2.12/libgnomecanvasmm-2.12.0.tar.gz
http://ftp.gnome.org/pub/GNOME/sources/gnome-vfsmm/2.12/gnome-vfsmm-2.12.0.tar.gz
http://ftp.gnome.org/pub/GNOME/sources/gconfmm/2.12/gconfmm-2.12.0.tar.gz
http://ftp.gnome.org/pub/GNOME/sources/libgnomemm/2.12/libgnomemm-2.12.1.tar.gz
http://ftp.gnome.org/pub/GNOME/sources/libgnomeuimm/2.12/libgnomeuimm-2.12.0.tar.gz

ftp://ftp.gnome.org/mirror/gnome.org/sources/gnome-vfs/2.13/gnome-vfs-2.13.1.tar.gz
"

SPAWN=2
PREFIX=/usr/local
PREP="zlib popt tiff jpeg fam OpenSP openjade audiofile pkgconfig hicolor-icon-theme"
GNOME="libxml2 libxslt gtk-doc glib libIDL ORBit2 intltool libbonobo glitz cairo pango atk gtk+ GConf desktop-file-utils gnome-mime-data gnome-vfs audiofile esound libgnome libart_lgpl libglade libgnomecanvas libbonoboui gnome-icon-theme gnome-keyring libgnomeui startup-notification gtk-engines gnome-themes scrollkeeper gnome-doc-utils gnome-desktop libwnck libsoup gnome-menus gnome-panel gnome-session vte gnome-terminal libgtop gail libxklavier gnome-applets meta-gnome-core metacity librsvg eel nautilus desktop-file-utils control-center libgtkhtml bug-buddy libgnomecups libgnomeprint libgnomeprintui gtksourceview gedit eog ggv gconf-editor gnome-utils procman gstreamer gst-plugins nautilus-cd-burner gnome-media nautilus-media gnome-netstatus gcalctool gpdf gucharmap zenity at-spi libgail-gnome gnome-speech gnome-user-docs file-roller system-tools-backends gnome-system-tools gnome-nettool vino dbus hal gnome-volume-manager gal gtkhtml gdm dasher gnome-keyring-manager"

#BUGGY="yelp"

# awefull stuff
#EXTRA="gnome-mag gnopernicus gok epiphany evolution evolution-data-server evolution-webcal ximian-connector gnome-games gnomemeeting totem sound-juicer gnome-system-monitor gnome-backgrounds evince"

GTKMM="libsigc++ glibmm gtkmm gconfmm libgnomemm libgnomecanvasmm libglademm gnome-vfsmm libgnomeuimm"

######################################################################

ALL="$PREP $GNOME $EXTRA $GTKMM"

dollar='$'

export jpeg_config="--enable-shared --enable-static"
export zlib_config="--shared"
export vte_config="--disable-gtk-doc --disable-python"
export librsvg_config="--disable-gtk-doc"
export libgnomeprint_config="--disable-gtk-doc"
#export libsigc_config=""
export gtkmm_config="--disable-examples --disable-demos"
export cairo_config="--enable-ps --enable-pdf"
export gtk_config="--with-xinput=yes"
export dbus_config="--disable-python"

function die
{
  echo $1
  exit 1
}

if [ "$1" = "-get" -o "$1" = "--get" ] ; then
    for i in $GET ; do
	name=`basename $i`
	if [ ! -f $name ] ; then
	    wget $i || die "could not fetch $i"
	fi
    done

    ncftpget "$GNOMEGET/*.tar.gz" || die "could not fetch all GNOME"
fi

# fix some file names
if [ -f jpegsrc.v6b.tar.gz ]
then mv -f jpegsrc.v6b.tar.gz jpeg-6b.tar.gz
fi

# calculate total number of packages
total=0
for i in $ALL
do total=$(($total + 1))
done

# process the packages
z=0
for i in $ALL
do z=$(($z + 1))
   FILE=`echo $i-[0123456789]*gz|awk '{print $1}'`

#   echo $FILE

   if [ -f $FILE ]
   then
        DIR=`basename $FILE .tar.gz`

        case $TERM in
	    xterm*|rxvt*)
		echo -ne "\033]0;Compiling $DIR $z/$total\007"
		;;
	    *)
		echo $FILE
		;;
	esac

        if [ ! -d $DIR ]
        then tar xfz $FILE
        fi
        cd $DIR

        if [ ! -f Makefile ]
        then
             config=`echo $i|tr - _|tr -d +`_config
             config=`eval "echo $dollar$config"`
             ./configure --prefix=$PREFIX $config || die "could not configure $i"
        fi
        make -j${SPAWN} || die "could not make $i"
        make install    || die "could not make install $i"

        cd ..
        rm -rf $DIR $FILE
        ldconfig
   fi
done

exit 0

# TODO: find out, why gtk-doc does not work at cube.doj
