#!/bin/tcsh -e
#
# Copyright (C) 2013-2016 Intel Corporation. All rights reserved.
#
# The information and source code contained herein is the exclusive property
# of Intel Corporation and may not be disclosed, examined, or reproduced in
# whole or in part without explicit written authorization from the Company.
#

set INST="/s/intelcompilers-2017/amd64_rhel6"

set DEBUGGERDIR="${INST}/debugger_2017/"
set LANGUAGE_TERRITORY=""

if ($?LC_CTYPE) then
    if ("$LC_CTYPE" != "") then
        set LANGUAGE_TERRITORY=`echo $LC_CTYPE | sed s/\\..\*//`
    endif
else if ($?LANG) then
    if ("$LANG" != "") then
        set LANGUAGE_TERRITORY=`echo $LANG | sed s/\\..\*//`
    endif
endif

if ("$LANGUAGE_TERRITORY" != "en_US") then
    if ("$LANGUAGE_TERRITORY" != "ja_JP") then
        set LANGUAGE_TERRITORY="en"
    else
        set LANGUAGE_TERRITORY="ja"
        if (! -d "$INST/documentation_2017/$LANGUAGE_TERRITORY/debugger") then
            set LANGUAGE_TERRITORY="en"
        endif
    endif
else
    set LANGUAGE_TERRITORY="en"
endif

set DOCDIR="$INST/documentation_2017/$LANGUAGE_TERRITORY/debugger"

if ( -d "$DOCDIR/gdb-ia" ) then
      set GDBINFO="$DOCDIR/gdb-ia/info/"
      set GDBMAN="$DOCDIR/gdb-ia/man/"
endif

if ( -d "$DOCDIR/gdb-mic" ) then
      set GDBINFO=$DOCDIR/gdb-mic/info/":$GDBINFO"
      set GDBMAN=$DOCDIR/gdb-mic/man/":$GDBMAN"
endif

if ( -d "$DOCDIR/gdb-igfx" ) then
      set GDBINFO=$DOCDIR/gdb-igfx/info/":$GDBINFO"
      set GDBMAN=$DOCDIR/gdb-igfx/man/":$GDBMAN"
endif

switch ( "`uname -m`" )
    case "x86_64" :
        set DEBUGGERARCH="intel64"
        if ( -d "$DEBUGGERDIR/gdb/${DEBUGGERARCH}_mic" ) then
            set PPREF_MIC="$DEBUGGERDIR/gdb/${DEBUGGERARCH}_mic"
            setenv GDB_CROSS "$DEBUGGERDIR/gdb/${DEBUGGERARCH}_mic/bin/gdb-mic"
            setenv GDBSERVER_MIC "$DEBUGGERDIR/gdb/targets/mic/bin/gdbserver"
            setenv MPM_LAUNCHER "$DEBUGGERDIR/mpm/bin/start_mpm.sh"
        endif
        breaksw
    default :
        set DEBUGGERARCH="ia32"
        breaksw
endsw

set PPREF="$DEBUGGERDIR/gdb/$DEBUGGERARCH"
setenv INTEL_PYTHONHOME "$DEBUGGERDIR/python/$DEBUGGERARCH/"

if ( -d "$DEBUGGERDIR/libipt/$DEBUGGERARCH/lib" ) then
    if !($?LD_LIBRARY_PATH) then
        setenv LD_LIBRARY_PATH "$DEBUGGERDIR/libipt/$DEBUGGERARCH/lib"
    else
        setenv LD_LIBRARY_PATH $DEBUGGERDIR/libipt/$DEBUGGERARCH/lib":$LD_LIBRARY_PATH"
    endif
endif

if ( -f "$DEBUGGERDIR/iga/lib" ) then
    if !($?LD_LIBRARY_PATH) then
        setenv LD_LIBRARY_PATH "$DEBUGGERDIR/iga/lib"
    else
        setenv LD_LIBRARY_PATH $DEBUGGERDIR/iga/lib":$LD_LIBRARY_PATH"
    endif
endif

if !($?MANPATH) then
    set MANPATH_CMD=`which manpath |& tee /dev/stdout`
    if !($?MANPATH_CMD) then
        setenv MANPATH $GDBMAN
    else
        set MANPATH_CMD=`manpath`
        setenv MANPATH $GDBMAN":${MANPATH_CMD}"
    endif
    unset MANPATH_CMD
else
    setenv MANPATH $GDBMAN":${MANPATH}"
endif

if !($?INFOPATH) then
    setenv INFOPATH $GDBINFO
else
    setenv INFOPATH $GDBINFO":$INFOPATH"
endif

if !($?NLSPATH) then
    setenv NLSPATH $PPREF/share/locale/%l_%t/%N
else
    setenv NLSPATH $PPREF/share/locale/%l_%t/%N":$NLSPATH"
endif

if ($?PPREF_MIC) then
    setenv PATH $PPREF_MIC/bin":$PATH"
    setenv NLSPATH $PPREF_MIC/share/locale/%l_%t/%N":$NLSPATH"
    unset PPREF_MIC
endif

unset INST PPREF DEBUGGERDIR DOCDIR GDBINFO GDBMAN LANGUAGE_TERRITORY
