#!/bin/sh

### configuration
# the directory where cvs is checked out
CVSDIR="$PWD/e/e17"
# the things to build (relative to the cvs checkout)
SRC="libs/eet libs/evas libs/ecore libs/embryo libs/edje apps/e"
# the "prefix" installed (though it is relocatable)
PREIFX="/opt/e17"
# compile flahs
CFLAGS="-O2"
# extra link flags
LDFLAGS=""
# remove international font and input method support (makes this a lot smaller)
NOINTL="yes"

EET_OPT=""
EVAS_OPT=""
ECORE_OPT="--disable-ecore-dfb --disable-ecore-fb --disable-ecore-evas-gl --disable-ecore-evas-dfb --disable-ecore-evas-fb --disable-ecore-dbus --disable-ecore-config"
EMBRYO_OPT=""
EDJE_OPT=""
E_OPT=""

### internal stuff for the build
# where to install to temporarily before cleaning and tarring
TINST="$PWD/tinst"
TARBALL="$PWD/e17.tar.gz"

# make sure we can execute things from this root
PATH=$PREFIX"/bin":$PATH
LD_LIBRARY_PATH=$PREFIX"/lib":$LD_LIBRARY_PATH

# clean the inst root first
rm -rf "$TINST"
mkdir "$TINST"

# compile and install everything
for I in $SRC; do
  D="$CVSDIR/$I"
  pushd $D
  OPT=""
  # special options
  if [ "$I" = "libs/eet" ]; then
    OPT="$EET_OPT"
  fi
  if [ "$I" = "libs/evas" ]; then
    OPT="$EVAS_OPT"
  fi
  if [ "$I" = "libs/ecore" ]; then
    OPT="$ECORE_OPT"
  fi
  if [ "$I" = "libs/embryo" ]; then
    OPT="$EMBRYO_OPT"
  fi
  if [ "$I" = "libs/edje" ]; then
    OPT="$EDJE_OPT"
  fi
  if [ "$I" = "apps/e" ]; then
    OPT="$E_OPT"
  fi
  ./autogen.sh --prefix="$PREFIX" $OPT
  make
  make DESTDIR="$TINST" install
  popd
done

# clean out stuff an end user doesn't need to just use e17
pushd "$TINST"
  rm -rf `find . -name "*.a" -print`
  rm -rf `find . -name "*.la" -print`
  
  rm -rf \
  bin/ecore* \
  bin/edje \
  bin/edje-config \
  bin/edje_decc \
  bin/edje_ls \
  bin/edje_recc \
  bin/edje_test \
  bin/edje_thumb \
  bin/eet* \
  bin/embryo \
  bin/embryo-config \
  bin/enlightenment-config \
  bin/evas* \
  lib/enlightenment/preload \
  lib/evas/modules/engines/fb \
  lib/evas/modules/loaders/edb \
  lib/evas/modules/savers/edb \
  lib/pkgconfig \
  include \
  share/aclocal \
  share/ecore \
  share/edje/data \
  share/embryo/examples \
  share/enlightenment/doc \
  share/evas

  if [ "$NOINTL" = "yes" ]; then
    rm -rf \
    bin/enlightenment_imc \
    share/enlightenment/data/input_methods \
    share/enlightenment/data/fonts/baekmuk.COPYING \
    share/enlightenment/data/fonts/dotum.ttf \
    share/enlightenment/data/fonts/fireflysung.COPYING \
    share/enlightenment/data/fonts/fireflysung.ttf \
    share/enlightenment/data/fonts/kochi.COPYING \
    share/enlightenment/data/fonts/kochi-gothic.ttf \
    share/locale
  fi
  
  for I in `find . -print `; do
    strip -x $I >& /dev/null
  done
  
  tar zcf "$TARBALL" *
popd

