#!/bin/sh

if [[ xx"$1" == xx"" ]]; then
  echo "Usage: $0 tagName [erase]"
  exit 1
else
  tag=$1
  echo "Building for tag $tag"
fi

export PATH=${PATH}:${ROOT}/usr/bin/x86:/usr/bin

#
# Now build just the RVL portion again with RVL_MEM == 64 to
# get the RVL modules built for a production RVL platform,
# using a different ROOT.
#
# This requires "make clobber" to avoid getting a mishmash 
# of 128MB and 64MB object files in the rvl portion of the tree.
#


export RVL_MEM=128
export SCROOT=/home/ngbuild/$tag/sc/sc_root/RVL_$RVL_MEM
export NGROOT=/home/ngbuild/$tag/ng/ng_root/RVL_$RVL_MEM
export ROOT=$SCROOT
echo $ROOT
if [ "$2" != "" ]; then rm -rf $ROOT; fi
mkdir -p $ROOT
cd /home/ngbuild/gba/sw
time make -k headers &&
time make -k clobber &&
time make -k headers &&
time make -k exports &&
time make -k &&
time make -k install

export ROOT=$NGROOT
echo $ROOT
if [ "$2" != "" ]; then rm -rf $ROOT; fi
mkdir -p $ROOT
cd /home/ngbuild/ng/sw
time make -k headers SCBUILD=$SCROOT &&
time make -k clobber &&
time make -k headers SCBUILD=$SCROOT &&
time make -k exports SCBUILD=$SCROOT &&
time make -k &&
time make -k install

#
# 64 Meg build
#
export RVL_MEM=64
export SCROOT=/home/ngbuild/$tag/sc/sc_root/RVL_$RVL_MEM
export NGROOT=/home/ngbuild/$tag/ng/ng_root/RVL_$RVL_MEM
export ROOT=$SCROOT
echo $ROOT
if [ "$2" != "" ]; then rm -rf $ROOT; fi
mkdir -p $ROOT
cd /home/ngbuild/gba/sw
time make -k headers &&
time make -k clobber &&
time make -k headers &&
time make -k exports &&
time make -k &&
time make -k install

export ROOT=$NGROOT
echo $ROOT
if [ "$2" != "" ]; then rm -rf $ROOT; fi
mkdir -p $ROOT
cd /home/ngbuild/ng/sw
time make -k headers SCBUILD=$SCROOT &&
time make -k clobber &&
time make -k headers SCBUILD=$SCROOT &&
time make -k exports SCBUILD=$SCROOT &&
time make -k &&
time make -k install

