#!/bin/bash
#
# setup the environment for quartus 
#
#
cd $HOME
echo " moving .bashrc and .bash_profile to .old_"
#mv .bash_profile .old_bash_profile
mv .bashrc .old_bashrc
echo
echo
echo "writing new .bashrc"
echo
cat >$HOME/.bashrc <<'EOF'
# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
# Path to Q9.1 on Kenny
ALTERA_ROOT=/usr/local/stow/altera8.0/altera
export ALTERA_ROOT

QUARTUS_ROOTDIR=$ALTERA_ROOT/quartus
export QUARTUS_ROOTDIR

export sopc_builder=$QUARTUS_ROOTDIR/sopc_builder


# only needed for the cpu_sdk makefiles for NiosI
export sopc_kit_nios=$ALTERA_ROOT/ip/local/kits/nios
#


export PATH=$PATH:$QUARTUS_ROOTDIR/bin:$QUARTUS_ROOTDIR/sopc_builder/bin:$ALTERA_ROOT/ip/local/kits/nios/bin:$ALTERA_ROOT/ip/local/kits/nios/bin/nios-gnupro/bin

export PATH=$PATH:$ALTERA_ROOT/nios2eds/bin/nios2-gnutools/H-i686-pc-linux-gnu/bin/:$ALTERA_ROOT/nios2eds/sdk2/bin:$ALTERA_ROOT/nios2eds/bin


# Altera have their own custom PERL stuff.
export PERL5LIB=$PERL5LIB:$QUARTUS_ROOTDIR/sopc_builder/bin/:$QUARTUS_ROOTDIR/quartus/sopc_builder/bin/europa/:$QUARTUS_ROOTDIR/sopc_builder/bin/perl_lib/

# set up a sensible prompt
export PS1="\[\033]0;\u@\h: \W\007\]bash$ "

# and turn the keyboard beep off that results from the above
echo "set bell-style none" >> $HOME/.inputrc

export LC_COLLATE=C

#required by Quartus
export QUARTUS_64BIT=0
export MWOS=linux
export MWARCH=i86
export QUARTUS_MWWM=allwm

# uncomment the next line if you are using the Excalibur board
# export SOPC_BUILDER_CLASSIC=1
#
SOPC_KIT_NIOS2=$ALTERA_ROOT/nios2eds
export SOPC_KIT_NIOS2

export SOPC_BUILDER_CLASSIC=
EOF
echo "writing new .bash_profile"
echo
echo
cat >> $HOME/.bash_profile<<EOF
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi
EOF
echo
echo
echo "moving .mw/ to .mw_orig/"
echo
if [ -d $HOME/.mw ]; then
   mv -f .mw .mw_orig
else echo "no such directory .mw"
fi

if [ -f $HOME/mw_works.tgz ]; then
  /bin/tar -xzvf mw_works.tgz
   echo
   echo "should all be ready now"
   echo "You may need to manually add back any .bashrc customisations"
   echo " that you added to the original .bashrc"
else 
   wget www.cems.uwe.ac.uk/~ngunton/vhdl/mw_works.tgz
  /bin/tar -xzvf mw_works.tgz
   echo
   echo "should all be ready now"
   echo "You may need to manually add back any .bashrc customisations"
   echo " that you added to the original .bashrc"
fi

