#!/bin/bash

###
# this is a convenience script for getting/updating e17 from svn.
# (this is what you need to build e17 and entrance).
###

###
# NOTE: this script was modified by Paulo <SamuraiDio> Diovani
# to do not use the sudo command, but just su (root password 
# will be required for every install) and to do not automatic 
# install the dependencies (you'll need to install then yourself)
#
# If you want the automated script made by raster instead of this
# you can get it at http://www.rasterman.com/files/get_e.sh
###

###
# settings - feel free to change these...
###
# the directory where checkout the sources from SVN (the working copy)
WC_DIR="E17"
# the directory to install into (a full path to where on the system to install)
PREFIX="/usr/local"
# install as root ("yes" or "no") - note. you CAN install as a user too, but
# only into directories you have permission to install into. also you will
# need to modify your LD_LIBRARY_PATH shell variable to access things
ROOT_INSTALL="yes"
# build enlightenment - the window manager ("yes" or "no")
BUILD_E="yes"
###
# end config
###

# modules
CORE_MODULES="eina eet evas ecore efreet embryo edje e_dbus"
E_MODULES="e"

MODULES=$CORE_MODULES
if [ $BUILD_E == "yes" ]; then
  MODULES=$MODULES" "$E_MODULES
fi

# actual working parts of the script (no need to really touch this)
if [ $ROOT_INSTALL == "yes" ]; then
  echo "---------------------------------------------------------------------"
  echo ""
  # check ldo.so.conf
  echo "Check /etc/ld.so.conf sanity"
  LDCONF=`grep $PREFIX/lib /etc/ld.so.conf`
  if [ -z "$LDCONF" ]; then
    echo "Add "$PREFIX"/lib to /etc/ld.so.conf please."
    exit -1
  fi
fi

# make sure we have the prefix in the PATH for now
export PATH="$PREFIX/bin:$PATH"
export LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH"
export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH"

CLEAN="no"

if [ ! -d ./$WC_DIR ]; then
  mkdir $WC_DIR
fi

# check if we have a svn tree already
# to update or checkout the sources
for I in $MODULES; do
  if [ -d ./$WC_DIR/$I/.svn ]; then
    echo "-----------------------------------------------------------------"
    echo ""
    echo "Updating SVN for "$I
    CLEAN="yes"
    svn update $WC_DIR/$I
  else
    echo "-----------------------------------------------------------------"
    echo ""
    echo "Checking out SVN for "$I
    svn co http://svn.enlightenment.org/svn/e/trunk/$I $WC_DIR/$I
  fi
done

# enable error abort from now on
set -e

# build and install it all
echo "---------------------------------------------------------------------"
echo ""
echo "Build..."
for I in $MODULES; do
  pushd $WC_DIR/$I
  echo "---------------------------------------------------------------------"
  echo ""
  echo "Building: "$I
  echo ""
  if [ $CLEAN == "yes" ]; then
    make clean distclean || true
  fi
  echo ""
  echo "Autofoo: "$I
  echo ""
  ./autogen.sh --prefix=$PREFIX
  echo ""
  echo "Compiling: "$I
  echo ""
  make
  echo ""
  echo "Installing: "$I
  echo ""
  if [  $ROOT_INSTALL == "yes" ]; then
    su -c 'make install && ldconfig'
  else
    make install
  fi
  popd
done

echo "---------------------------------------------------------------------"
echo ""
echo "NOTE: you will want to add "$PREFIX"/bin to your user's (and maybe"
echo "      root's) PATH variable. (see your documentation on the PATH shell"
echo "      variable for more information on how to do this)."
if [ $ROOT_INSTALL == "no" ]; then
echo "NOTE: you will want to add "$PREFIX"/lib to your user's (and maybe"
echo "      root's) LD_LIBRARY_PATH variable. (see your documentation on the"
echo "      LD_LIBRARY_PATH shell variable for more information on how to do"
echo "      this)."
fi

