#
#                             stb225 Project
#                   ---------------------------------
#
# Copyright (C) 2009 NXP B.V.,
# All Rights Reserved.
#
# Filename: site_setup_soustb.sh
#
#
# Rev Date       Author      Comments
#-------------------------------------------------------------------------------
#   1 20060711   batelaan    Initial
#   2 20061024   batelaan    Add /user/bhssw/_utils/bin/linux to PATH; Do qmore setup.
#   3 20070712   batelaan    Only set QMORE_HOME to prevent QAC introducing path problems.
#   4 200707     rtaylor     Remove _SetDontOverride TARBALLS line
#   5 20070731   rtaylor     File not changed, so change it to what v4 should have been :-/
#   6 20070913   batelaan    Don't use $0, it is /bin/bash, not the name of this script.
#   8 20070918   amccurdy    Warn if /user/bhssw/_utils/bin/linux isn't found
#   9 20090202   batelaan    Set $TESTROOT for robotest
#  10 20090213   amccurdy    Use consistent indent for warning messages...
#  11 20090326   batelaan    Rm unwanted messages/envvars.

# Site-specific setup script sourced from $PRJROOT/setup.sh
# Arguments:
# - setup_start: execute commands at the beginning of setup.sh
# - setup_end: execute commands at the end of setup.sh

case "x$1" in
  xsetup_start)
    # This is the default anyway:
    # _SetOverride BUILDROOT_PATH_FMT '$PRJROOT/build_$CONFIG_NAME'
  ;;
  xsetup_end)

    # Append /user/bhssw/_utils/bin/linux to PATH if isn't already present and dir exists
    # (no need to warn if this does not exist).
    # Used for QMore (NXP SW QA tool).
    if [ -d "/user/bhssw/_utils/bin/linux" ]; then
      PATH=`pathmanip --append /user/bhssw/_utils/bin/linux`
      if [ -z "$QMORE_HOME" ]; then
        # This is not strictly pointing to QMORE installation,
        # $QMORE_HOME/bin/qmore does exist (it's a local script)
        # which sets things up properly and then invokes the real $QMORE_HOME/bin/qmore .
        # We do this because if we add any QAC stuff in PATH or LD_LIBRARY_PATH
        # basic stuff like 'man' starts failing!
        export QMORE_HOME=/user/bhssw/_utils/bin/linux
      fi
    fi

    # Test for directory /user/bhssw/stb225/test, if so look for the stb225test CM project.
    if [ -d "/user/bhssw/stb225/test" ]; then
      if [ -z "$TESTROOT" ]; then
          for d in \
              $HOME/ccm_wa/stb225/stb225test-$LOGNAME/stb225test \
              $HOME/ccm_wa/stb225/stb225test-${LOGNAME}_*/stb225test \
              ${PRJROOT%/stb225}/stb225test
          do
              if [ -d $d ]; then
                  TESTROOT=$d
                  break
              fi
          done
      fi
      if [ -z "$TESTROOT" ]; then
          echo "**WARNING: no stb225test workarea found: no robotest possible. I've looked for:"
          for d in \
              $HOME/ccm_wa/stb225/stb225test-$LOGNAME/stb225test \
              $HOME/ccm_wa/stb225/stb225test-${LOGNAME}_*/stb225test \
              ${PRJROOT%/stb225}/stb225test
          do
              echo "  - $d"
          done
      else
          echo "Using as TESTROOT: $d"
          export TESTROOT
          PATH=`pathmanip --prepend $TESTROOT/bin`
      fi
    fi
  ;;
  x*)
    echo 2>&1 "**ERROR: $BASH_SOURCE: incorrect argument ($1): should be setup_start|setup_end"
esac
