#!/bin/csh -f # setcompiler # # csh script to enable easy one-line switching between available compilers. # # Must be sourced (not executed) so that variables are defined in the current # shell. # If no compiler is specified, uses contents of ~/.SRTcompiler if that exists, # otherwise uses KCC. # Currently works only on IRIX6 or Linux2 machines. # # Chris Green, March 1998 # # Function: # # Set required environment variables, aliases, and path to use the # selected compiler and appropriate debugger. # # Usage: # setcompiler [--p[rompt]] # # Options: # --p (or --prompt) set the command-line prompt to show current # compiler choice and working directory, e.g., # [cdfsga-KCC] ~/workdir % # # Arguments: # Compiler to use; can be: # gcc, g++ GNU C++ compiler # KCC, kcc, kai, KAI KAI C++ compiler # (with 33 suffix for version 3.3 if available) # CC, cc SGI native C++ compiler (IRIX only) # ########################################################################### set compiler=" " set default="KCC" if ("$BFARCH" =~ "IRIX6"* ) then if (`uname -r` == "6.5") then # Special treatment for IRIX 6.5 set BFARCH_BASE="IRIX6_5" else set BFARCH_BASE="IRIX6" endif set a=an else if ("$BFARCH" =~ "Linux2"* ) then set BFARCH_BASE="Linux2" set a=a else if ( "$BFARCH" =~ "OSF1V4"* ) then set BFARCH_BASE="OSF1V4" set a=an else echo "System not recognized. Please check and mail greenc@fnal.gov." set exit=1 goto finish endif echo "setcompiler running on $a ${BFARCH_BASE} system." unset a while ($#argv) if ("$1" =~ "--p"* ) then set myprompt else set compiler="$1" endif shift end if ("$compiler" == " ") then if (-e ~/.SRTcompiler) then set compiler=`cat ~/.SRTcompiler | cut -d'-' -f2` if ("${compiler}" == "${BFARCH_BASE}") then set compiler=gcc endif else set compiler="$default" echo "setcompiler: using default compiler $compiler." endif endif set dropit="`which dropit`" if ("$dropit" =~ *"not found"* ) then echo -n "setcompiler warning: dropit not in path. " if ( -x /usr/local/bin/dropit) then echo "*Temporarily* adding /usr/local/bin to path." set dropit="/usr/local/bin/dropit" set path=(`$dropit -cs /usr/local/bin`) set pathset else echo "Unable to find dropit! Check that FUE is installed on your system." set exit=2 goto finish endif endif set kaiVersionBFARCH="" set kaiVersionProduct="" set ccVersionBFARCH="" set failed=0 switch( "$compiler" ) case KCC32: case kcc32: case KAI32: case kai32: case KCC_3_2: case kcc_3_2: case KAI_3_2: case kai_3_2: if ("${BFARCH_BASE}" == "Linux2") then set kaiVersionProduct="v3_2d_4" else set kaiVersionProduct="v3_2d" endif # there is no breaksw here, continuing thru case kai case KCC33: case kcc33: case KAI33: case kai33: case KCC_3_3: case kcc_3_3: case KAI_3_3: case kai_3_3: if ("${kaiVersionProduct}" == "") set kaiVersionProduct="v3_3e_1" # there is no breaksw here, continuing thru case kai case KCC: case kcc: case KAI: case kai: # Use the current kai directory to get the default version string if ($?KCC_BASE && "${kaiVersionProduct}" == "") then set kaiVersionProduct=`(setup kai ; echo ${KCC_BASE})` set kaiVersionProduct=`basename ${kaiVersionProduct:h}` endif if ("`echo ${kaiVersionProduct} | cut -d_ -f1,2`" == "v3_2d") then set pp=KCC else set kaiVersionBFARCH="_3_3" set pp=KCC_3_3 endif setenv BFARCH "${BFARCH_BASE}-KCC"${kaiVersionBFARCH} switch ( "${BFARCH_BASE}" ) case IRIX6*: case OSF1V4: case Linux2: if ($?KAI_DIR) then unsetup kai endif echo "Setting up the KAI product." setup kai ${kaiVersionProduct} if ((! $?KAI_DIR) && ("x${kaiVersionProduct}" != "x")) then echo "Could not find version ${kaiVersionProduct}. Trying current ..." setup kai if ($?KCC_BASE) then set kaiVersionProduct=${KCC_BASE} set kaiVersionProduct=${kaiVersionProduct:h} set kaiVersionProduct=${kaiVersionProduct:t} endif endif if (! $?KAI_DIR) then echo "Problems setting up the KAI product." set exit=1 goto finish endif breaksw default: echo 'Bad value of ${BFARCH_BASE}: should never happen.' set exit=1 goto finish breaksw endsw alias ddd | grep -q ddd if (! $status) then unalias ddd echo 'Unnecessary alias for ddd removed' endif setup dddebugger if ("${BFARCH_BASE}" =~ "IRIX6"* ) then alias dddbx 'ddd --dbx' echo -n '`'"dddbx' aliased to: " alias dddbx endif if ( -x $KCC_BASE/bin/gdb) then alias kddd 'ddd --debugger $KCC_BASE/bin/gdb' echo -n '`'"kddd' aliased to: " alias kddd else if ( -x $KCC_BASE/bin/gdbkcc) then alias kddd 'ddd --debugger $KCC_BASE/bin/gdbkcc' echo -n '`'"kddd' aliased to: " alias kddd else echo "$KCC_BASE/bin/gdb not found. Assuming default gdb is kai-aware." endif breaksw case CC73: case cc73: case CC_7_3: case cc_7_3: if ( "${ccVersionBFARCH}" == "" ) then set ccVersionBFARCH="_7_3" endif case CC721: case cc721: case CC_7_2_1: case cc_7_2_1: if ( "${ccVersionBFARCH}" == "" ) then set ccVersionBFARCH="_7_2_1a" endif case CC: case cc: if ( ${BFARCH_BASE} !~ "IRIX6"* ) then echo 'Not a valid choice for this platform: '$compiler set exit=1 goto finish endif if ($?KAI_DIR) then echo "Removing the KAI product." unsetup kai endif setenv BFARCH "${BFARCH_BASE}-CC${ccVersionBFARCH}" set pp=CC${ccVersionBFARCH} alias ddd | grep -q ddd if (! $status) then unalias ddd echo 'Unnecessary alias for ddd removed' endif setup dddebugger alias dddbx 'ddd --dbx' echo -n '`'"dddbx' aliased to: " alias dddbx alias kddd | grep -q ddd if (! $status) then unalias kddd echo 'Unnecessary alias for kddd removed' endif breaksw case g\+\+: case gcc: if ($?KAI_DIR) then echo "Removing the KAI product." unsetup kai endif switch ( "${BFARCH_BASE}" ) case IRIX6*: case OSF1V4: if ( ! $?GCC_DIR ) then echo "Setting up the GCC product." setup gcc endif if ( ! $?GCC_DIR ) then echo "Problems setting up the gcc product." set exit=1 goto finish endif breaksw case Linux2: echo "Using the system's gcc on Linux." breaksw endsw setenv BFARCH "${BFARCH_BASE}" set pp=g++ alias ddd | grep -q ddd if (! $status) then unalias ddd echo 'Unnecessary alias for ddd removed' endif setup dddebugger alias dddbx | grep -q ddd if (! $status) then unalias dddbx echo 'Unnecessary alias for dddbx removed' endif alias kddd | grep -q ddd if (! $status) then unalias kddd echo 'Unnecessary alias for kddd removed' endif breaksw default: if (-e ~/.SRTcompiler) then echo 'File ~/.SRTcompiler must contain a valid BFARCH value if no arguments.' exit 1 else echo 'Usage: setcompiler [--prompt] [KCC || kcc || KAI || kai][33|_3_3] || [CC || cc] || [g++ || gcc]' set exit=1 goto finish endif breaksw endsw # Set the prompt to reflect the compiler if ( $?myprompt && "$SHELL" =~ *"tcsh" ) then set prompt="%S%B[%m-$pp]%b%s %c2 %% " endif # Fix the path and LD_LIBRARY_PATH to remove old references ... if (${BFARCH_BASE} == "IRIX6_5") then set OLDPATH="IRIX6" else set OLDPATH="$BFARCH_BASE" endif if (!($?LD_LIBRARY_PATH)) then setenv LD_LIBRARY_PATH "./lib/${OLDPATH}:${CDFSOFT2_DIR}/lib/${OLDPATH}" endif set tmp=(`$dropit -ca ./bin/${OLDPATH} ${CDFSOFT2_DIR}/bin/${OLDPATH}`) if ( "$tmp" != "" ) set path=($tmp) set tmp=(`$dropit -p $LD_LIBRARY_PATH -a ./lib/${OLDPATH} ${CDFSOFT2_DIR}/lib/${OLDPATH}`) setenv LD_LIBRARY_PATH "$tmp" # ... and append the correct ones set tmp=(`$dropit -cas ./bin/${BFARCH} ${CDFSOFT2_DIR}/bin/${BFARCH}`) if ( "$tmp" != "" ) set path=($tmp) echo "Successfully set up $compiler on "`uname -n`. set exit=0 finish: unset pp unset myprompt unset kaiVersionBFARCH unset kaiVersionProduct unset failed unset tmp if ($?pathset) then echo "Removing /usr/local/bin from path" set path=(`$dropit -c /usr/local/bin`) endif unset pathset unset dropit exit $exit