#!/bin/csh -evf

unsetenv TCBUILD_FLAGS
setenv OSTYPE `uname -s`
setenv MACHTYPE `uname -m`

if ($OSTYPE == "solaris" || $OSTYPE == "SunOS") then
  # CC cannot be static or we get missing symbol errors for dlopen
  setenv CC 		"/project/cs/titanium/srs/sparc-sun-solaris2.9/bin/gcc-4.0.1"
  setenv CXX 		"/project/cs/titanium/srs/sparc-sun-solaris2.9/bin/g++-4.0.1"
  setenv PERL 		"/usr/sww/bin/perl"
  setenv GMAKE 		"/usr/sww/bin/gmake"
  setenv AR 		"/usr/sww/bin/gar"
  setenv READLINK	"/project/cs/titanium/srs/sparc-sun-solaris2.8/bin/readlink"

  setenv CONFIGURE_ARGS "--disable-mpi --disable-ammpi"
  #setenv CONFIGURE_ARGS "--with-papi=/project/cs/titanium/srs/sparc-sun-solaris2.8/papi"

else if ($OSTYPE == "Linux") then
 if ($MACHTYPE == "i686") then
  setenv CC 		"/project/cs/titanium/srs/i686-pc-linux-gnu/bin/gcc-4.0.0"
  setenv CXX 		"/project/cs/titanium/srs/i686-pc-linux-gnu/bin/g++-4.0.0 -static"
  setenv PERL 		"/usr/sww/bin/perl"
 else if ($MACHTYPE == "ia64") then
  setenv CC 		"/project/cs/titanium/srs/ia64-linux/bin/gcc-4.0.0"
  setenv CXX 		"/project/cs/titanium/srs/ia64-linux/bin/g++-4.0.0 -static"
  setenv PERL 		"/usr/bin/perl"
 else
  echo Unknown Linux architecture: $MACHTYPE
  exit 1
 endif
  setenv READLINK	"/bin/readlink"
  setenv GMAKE 		"/usr/bin/make"
  setenv KSH 		"/usr/bin/ksh"

  if (! -d /usr/mill/bin) then
    echo ERROR: you should build the Linux SRS release on Millennium
    exit 1
  endif

  setenv GM_INCLUDE 	"/usr/mill/pkg/gm/include"
  setenv GM_LIB 	"/usr/mill/pkg/gm/lib"
  setenv GMRUN_CMD 	"%E/gasnetrun.gexec.pl -np %N %C"

  setenv MPI_CC 	"/usr/mill/pkg/mpich-gm/bin/mpicc"
  setenv MPIRUN_CMD 	"/usr/mill/pkg/mpich-gm/bin/mpirun -np %N %C" 
  #setenv MPIRUN_CMD 	"/project/cs/titanium/srs/i686-pc-linux-gnu/bin/mpirun-mill -np %N %C"

  setenv TI_CSPAWN_CMD	"gexec -n %N %C"

  setenv CONFIGURE_ARGS "--enable-gm"

else
  echo Unknown OS type: $OSTYPE
  exit 1
endif

#echo n | ./Bootstrap
#./configure --enable-srs $CONFIGURE_ARGS
make all distcheck
make -C runtime/backend tlib
make -C ex check
make -C ex/TestSuite test
make -C ex/TestSuite test-w
make install

