#! /bin/sh
# @(#)sanityck	1.6 99/02/24
# 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 }'`
  case "$v" in
    1.2|1.2.[1-9])
       ;;		   
    *) echo '
ERROR: Your ALT_BOOTDIR environment variable does not point
       to a valid JDK for bootstrapping this build.
       A JDK 1.2 or 1.2.x build must be bootstrapped against
       a 1.2-V (or later) build. Please update your ALT_BOOTDIR
       setting, or just unset it, and try again.
'
       exit 1
       ;;
  esac
  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 '
ERROR: 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.
'
    exit 1
  fi

  # Check C compiler service-pack level
  #
  # From the VisualStudio 97 sp3 README:
  #                         fcs       sp1       sp2       sp3       
  # Visual C++ 5.0 link.exe 5.00.7022 5.02.7132 5.02.7132 5.010.7300
  #
  v="`link | head -1 | awk '{ print $7 }'`"
  if [ "x$v" = x ]; then
    echo '
ERROR: Cannot determine the service-pack level of your C++ compiler
'
    exit 1
  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 '
ERROR: 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.
'
    exit 1
  fi
  echo 'VisualStudio service-pack level (link.exe version):' $v
fi

echo 'Sanity check passed'
echo ''
