#!/bin/ksh
#
if [ ! "$storage_model" ] ; then
   if [ -d /usr/local/env/localmrb/armn/${USER} ] ; then
      storage=/usr/local/env/localmrb/armn/${USER}
   else
      printf "\n Must define environment variable storage_model\n"
      printf " (to store *.o *.Abs etc... on pollux) \n\n"
      exit
   fi
else
   storage=$storage_model
fi
ici=`true_path .`
cd $storage 2> /dev/null
if test $? != 0 ; then
  printf "\n DIRECTORY $storage does not exist \n\n"
  exit
fi
cd $ici
storage=${storage}/$(basename ${SEQ_EXP_HOME:-$(true_path .)})
#
mkdir $storage 2> /dev/null
new=`true_path $storage`
if [ "$new" = "$ici" ]; then
   same=1
else
   same=""
fi

mkdir -p $storage/malib${EC_ARCH} 2> /dev/null
if [ ! "$same" ]; then
  if [[ $BASE_ARCH = AIX* ]] ; then
    /bin/rm -f malib${BASE_ARCH} ; ln -sf $storage/malib${BASE_ARCH} malib${BASE_ARCH}
  fi
  if [[ "$BASE_ARCH" = Linux* ]] ; then
		if [[ $EC_ARCH == ${BASE_ARCH}_${COMP_ARCH} ]] ; then
			 /bin/rm -f malib${EC_ARCH} ; ln -sf $storage/malib${EC_ARCH} malib${EC_ARCH}
		else
			 /bin/rm -f malib${BASE_ARCH} ; ln -sf $storage/malib${BASE_ARCH} malib${BASE_ARCH}
		fi
  fi
fi

mainntr=maingemntr_${BASE_ARCH}.Abs
maindm=maingemdm_${BASE_ARCH}.Abs
if [ ! "$same" ]; then
  /bin/rm -f ${mainntr}; ln -sf $storage/${mainntr} ${mainntr} ; touch $storage/${mainntr}
  /bin/rm -f ${maindm} ; ln -sf $storage/${maindm} ${maindm}   ; touch $storage/${maindm}
fi
if [ ! -s $storage/${mainntr} ] ; then
  echo "Copying release binary for gemntr: $(which maingemntr_REL_${BASE_ARCH}.Abs)"
  cp $(which maingemntr_REL_${BASE_ARCH}.Abs) $storage/${mainntr}
fi
if [ ! -s $storage/${maindm} ] ; then
  echo "Copying release binary for gemdm: $(which maingemdm_REL_${BASE_ARCH}.Abs)"
  cp $(which maingemdm_REL_${BASE_ARCH}.Abs) $storage/${maindm}
fi
chmod 755 $storage/${mainntr} $storage/${maindm}

#
/bin/rm -rf RUNENT RUNMOD RUNENT_output RUNMOD_output
mkdir -p $storage/RUNENT $storage/RUNMOD $storage/RUNENT_output $storage/RUNMOD_output 2> /dev/null
if [ ! "$same" ]; then
  ln -s $storage/RUNENT .
  ln -s $storage/RUNMOD .
  ln -s $storage/RUNENT_output .
  ln -s $storage/RUNMOD_output .
fi
#
