#! /bin/sh
#
# @(#)sanityck	1.9 02/07/25 @(#)
#
# Copyright (c) 1998-2001 Sun Microsystems, Inc.  All rights reserved.
# PROPRIETARY/CONFIDENTIAL
# Use is subject to license terms.
#
#########
#
# Shell script to sanity-check the build environment

if [ `uname` = 'SunOS' ]; then
  PLATFORM=solaris
  EXE=
else
  PLATFORM=win32
  EXE=.exe
fi

if [ "x$INSANE" != 'xyes' -a "x$CLASSPATH" != x ]; then
  echo '
ERROR: Your CLASSPATH environment variable is set.  This will
       most likely cause the build to fail.  Please unset it
       and try again.
'
  exit 1
fi

if [ "x$ALT_BOOTDIR" != x ]; then
  j=$ALT_BOOTDIR/bin/java$EXE
  if [ -x $j ]; then true; else
    echo '
ERROR: ALT_BOOTDIR does not point to a valid JDK
'
    exit 1
  fi
  v="`$j -version 2>&1`"
  v=`echo $v | awk -F'"' '{ print $2 }'`
  if [ "$v" != '1.2fcs' -a "$v" != '1.2' -a "$v" != '1.2.2' -a "$v" != '1.3.0' -a $v != "1.3.0_01" -a $v != "1.3.0_02" -a $v != "1.3.1-beta"  ]; then
    echo '
ERROR: Your ALT_BOOTDIR environment variable points to a JDK
       release prior to 1.2fcs build J.  The JDK 1.2 build must be
       bootstrapped against a 1.2fcs-J (or later) build.
       Please update your ALT_BOOTDIR setting, or just unset
       it, and try again.
'
    exit 1
  fi
  echo 'Version of ALT_BOOTDIR JDK:' $v
fi

if [ "x$INSANE" != 'xyes' -a $PLATFORM = win32 ]; then

  # Check TEMP
  TMP=$TEMP
  if [ "x$TMP" != x ] && mkdir -p "$TMP"; then true; else
    TMP=C:/temp
    if mkdir -p $TMP; then true; else
      echo '
ERROR: No temporary directory.  Please set the TEMP environment variable.
'
      exit 1
    fi
  fi
  echo 'TEMP directory:' $TMP

  # Check for xcopy
  if which xcopy >nul; then true; else
    echo '
ERROR: The "xcopy" command could not be found in your PATH.  The JDK 1.2
       build requires this command, which can usually be found in
       C:\\WINNT\System32.  Please adjust your PATH environment variable
       and try again.
'
    exit 1
  fi

  # Check C compiler
  c=$TMP/sanity$$.c
  rm -f $c
  echo _MSC_VER >$c
  v="`cl -EP $c 2>nul | sed -e '/^$/d'`"
  rm -f $c
  if [ "x$v" = x -o "$v" -lt 1100 ]; then
    echo '
WARNING: Your Microsoft Visual C++ compiler predates the 5.0 release.
	 The JDK 1.2 build requires version 5.0 or later.  Please
         install VC++ 5.0 and try again.
'
  fi
  v1="`echo $v | awk -F. '{ print $2 }'`"
  v2="`echo $v | awk -F. '{ print $3 }'`"
  if [ "x$v1" = x -o "$v1" -lt 10 ] || [ "x$v2" = x -o "$v2" -lt 7300 ]; then
    echo '
WARNING: You have not installed Microsoft Visual Studio 97 service pack 3.
	 The JDK 1.2 build requires this service pack.  Please install it
         and try again.
'
  fi
  echo 'VisualStudio service-pack level (link.exe version):' $v
fi

# Check for a valid GCC in PATH

# Current GCC doesn't work for win32 build, so don't
# bother looking for it here.
#echo "Checking for valid GCC compiler."
#gcc_cmd="`which gcc`"
#if [ "x$gcc_cmd" != "x" ] ; then
#   echo "GCC_CMD=$gcc_cmd"
#else
#   echo "GCC not found."
#fi

if [ "x$BOOTDIR" != x ]; then
  j=$BOOTDIR/bin/java$EXE
  if [ -x $j ]; then
  v="`$j -version 2>&1`"
echo $v
  v=`echo $v | awk -F'"' '{ print $2 }'`
  if [ "$v" != '1.2fcs' -a "$v" != '1.2' -a "$v" != '1.2.2' -a "$v" != '1.3.0' -a $v != "1.3.0_01" -a $v != "1.3.0_02" -a $v != "1.3.1-beta"  ]; then
    echo '
ERROR: Your BOOTDIR environment variable points to a JDK
       release prior to 1.2fcs build J.  The JDK 1.2 build must be
       bootstrapped against a 1.2fcs-J (or later) build.
       Please update your BOOTDIR setting, or just unset
       it, and try again.
'
    exit 1
  fi
  else
    echo '
ERROR: BOOTDIR does not point to a valid JDK
'
    exit 1
  fi

  echo 'Version of BOOTDIR JDK:' $v
else
    if [ -d /usr/local/java ] ; then true ; else
    echo "Warning: BOOTDIR and ALT_BOOTDIR are not set"
    echo "         Consider updating your /usr/local/java link"
    echo "         or setting BOOTDIR to `which java | sed -e 's%/bin/java%%'`"
    echo ""
    fi
fi

# Check for KVMDIR
if [ "x$KVMDIR" != x ]; then
  j=$KVMDIR/api
  if [ -d $j ]; then true; else
    echo '
ERROR: KVMDIR does not point to a valid VM workspace
'
    exit 1
  fi
fi

echo 'Sanity check passed'
echo ''
