#!/bin/sh

# E17 buildscript (20040309)

#E17=/target/path
BUILD=~/test/e17-build
LOGS=~/software/e17/logs
PATCH=~/projects/Homepage/icculus/e17/patches
PKGS=~/sources/e17
##############################################################################
EVAS_OPTS="--enable-software-x11 --enable-image-loader-png \
--enable-image-loader-jpeg --enable-image-loader-eet \
--enable-image-loader-edb --enable-cpu-p2-only --enable-cpu-mmx \
--enable-cpu-sse --enable-cpu-c --enable-scale-smooth \
--enable-scale-sample --enable-convert-8-rgb-332 --enable-convert-8-rgb-666 \
--enable-convert-8-rgb-232 --enable-convert-8-rgb-222 \
--enable-convert-8-rgb-221 --enable-convert-8-rgb-121 \
--enable-convert-8-rgb-111 --enable-convert-16-rgb-565 \
--enable-convert-16-rgb-555 --enable-convert-16-rgb-rot-0 \
--enable-convert-32-rgb-8888 --enable-convert-32-rgbx-8888 \
--enable-convert-32-bgr-8888 --enable-convert-32-bgrx-8888 \
--enable-convert-32-rgb-rot-0"

build ()
{
	if [ -f "$LOGS/$1.log" ]
	then
		echo "Skipping $1..." 
	else
		echo "Building $1..." &&
		echo -e "\n$1\nOptions: $@" >$LOGS/$1.log &&
		build_foo $@ >>$LOGS/$1.log 2>&1
	fi
}

build_foo ()
{
# $1		package name
# $2		directory
# $3		configure options
# $4		export CFLAGS or not
# $5		patch

	if [ "$3" != "no" ]
	then
		args="$3"
	fi &&
	if [ "$4" = "yes" ]
	then
		CC_OPTS="$CFLAGS"
		LD_OPTS="$LDFLAGS"
		export CFLAGS="$CFLAGS `edb-config --cflags`"
		export LDFLAGS="$LDFLAGS `edb-config --libs`"
	fi &&
	echo -e "CFLAGS=$CFLAGS\nLDFLAGS=$LDFLAGS" >>$LOGS/$1.log &&
	cp -Rpd $PKGS/$2/$1 $BUILD/$1 &&
	cd $BUILD/$1 &&
	if [ -f "$PATCH/$1-$5.patch" ]
	then
		patch -Np1 -i $PATCH/$1-$5.patch
	fi &&
	case "$1" in 
		evas)
			./autogen.sh || true &&
			patch -Np1 -i $PATCH/evas-configure.patch &&
			./configure --prefix=$E17 $EVAS_OPTS 
			;;
		*)
			./autogen.sh --prefix=$E17 $args
			;;
	esac &&
	make &&
	case "$1" in
		edje)
			make -k install || true
			;;
		*)
			make install
			;;
	esac &&
	if [ "$4" = "yes" ]
	then
		export CFLAGS="$CC_OPTS"
		export LDFLAGS="$LD_OPTS"
	fi &&
	cd .. &&
	rm -r $BUILD/$1
}
##############################################################################
mkdir -p $BUILD $LOGS &&
# EFL
build edb e17/libs &&
build imlib2 e17/libs &&
build eet e17/libs &&
build imlib2_loaders e17/libs &&
build evas e17/libs no yes configure2 &&
build ebits e17/libs &&
build ecore e17/libs no yes &&
build efsd e17/apps &&
build ferite &&
build ebg e17/libs &&
build edje e17/libs no yes configure &&
build epeg e17/libs &&
build epsilon e17/libs no no configure &&
build esmart e17/proto no yes &&
build ewd e17/libs &&
build estyle e17/libs no no colors &&
build etox e17/libs --disable-dependency-tracking &&
build ewl e17/libs &&
# Apps
build entrance e17/apps --with-ecore=$E17 no configure &&
build iconbar e17/apps no no configure &&
rmdir $BUILD
