# determines PROJECT, if not forced by user
# default is Generic
if [ -z "$PROJECT" ]; then
  PROJECT="Generic"
else
  PROJECT="$PROJECT"
fi

# determines TARGET_ARCH, if not forced by user (i386 / x86_64 / powerpc)
# default is i386
if [ -z "$ARCH" ]; then
  TARGET_ARCH="i386"
else
  TARGET_ARCH="$ARCH"
fi

ROOT=`pwd`
PROJECT_DIR="$ROOT/projects"

OPENELEC_VERSION=`cat VERSION`

if [ "$OPENELEC_VERSION" = "devel" ]; then
  OS_VERSION="0.90"
else
  OS_MAJOR_VERSION=`echo "$OPENELEC_VERSION" | cut -f1 -d "."`
  OS_MINOR_VERSION=`echo "$OPENELEC_VERSION" | cut -f2 -d "."`
  OS_VERSION="$OS_MAJOR_VERSION.$OS_MINOR_VERSION"
fi

# read project options if available
 if [ -f "$PROJECT_DIR/$PROJECT/options" ]; then
   . $PROJECT_DIR/$PROJECT/options
 fi

# Target system library C (eglibc)
  TARGET_LIBC="eglibc"

# Library strip
  LIBSTRIP="yes"

# Need to point to your actual cc
# If you have ccache installed, take care that LOCAL_CC don't point to it
  LOCAL_CC=`which gcc`

# Need to point to your actual g++
# If you have ccache installed, take care that LOCAL_CXX don't point to it
  LOCAL_CXX=`which g++`

# Support C++ in toolchain
  TOOLCHAIN_CXX="yes"

# verbose compilation mode (yes/no)
  VERBOSE="yes"

# Concurrency make level (-j option)
#  Try value 1 (default) to 4 on single CPU computer, or more on
#  multi-processor computer (like hyperthreading SMP CPU)
  CONCURRENCY_MAKE_LEVEL=`cat /proc/cpuinfo | grep -c '^processor[[:cntrl:]]*:'`

# forcing install of all packages (yes/no)
  FORCE_INSTALL="no"

# set jpeg library depending on ARCH
  if [ "$TARGET_ARCH" = "i386" -o "$TARGET_ARCH" = "x86_64" ]; then
    LIBJPEG="libjpeg-turbo"
#    LIBJPEG="jpeg"
  else
    LIBJPEG="jpeg"
  fi

get_graphicdrivers() {
  if [ "$GRAPHIC_DRIVERS" = "all" ]; then
    GRAPHIC_DRIVERS="i915 i965 r200 r300 r600 radeon nvidia vmware"
  fi

  for drv in $GRAPHIC_DRIVERS; do
    [ "$drv" = "i915" ] && MESA_DRIVERS="$MESA_DRIVERS,i915"
    [ "$drv" = "i965" ] && MESA_DRIVERS="$MESA_DRIVERS,i965"
    [ "$drv" = "r200" ] && MESA_DRIVERS="$MESA_DRIVERS,r200"
    [ "$drv" = "r300" ] && MESA_DRIVERS="$MESA_DRIVERS,r300"
    [ "$drv" = "r600" ] && MESA_DRIVERS="$MESA_DRIVERS,r600"
    [ "$drv" = "radeon" ] && MESA_DRIVERS="$MESA_DRIVERS,radeon"
    [ "$drv" = "nouveau" ] && MESA_DRIVERS="$MESA_DRIVERS,nouveau"

    if [ "$drv" = "i915" -o "$drv" = "i965" ]; then
      XORG_DRIVERS="$XORG_DRIVERS intel"
    fi

    if [ "$drv" = "r200" -o "$drv" = "r300" -o "$drv" = "r600" -o "$drv" = "radeon" ]; then
      XORG_DRIVERS="$XORG_DRIVERS ati"
    fi

    if [ "$drv" = "nouveau" ]; then
      XORG_DRIVERS="$XORG_DRIVERS nouveau"
    fi

    if [ "$drv" = "nvidia" ]; then
      XORG_DRIVERS="$XORG_DRIVERS nvidia"
      XINERAMA_SUPPORT="yes"
    fi

    if [ "$drv" = "vmware" ]; then
      XINERAMA_SUPPORT="yes"
    fi
  done
}

. config/path $1
