#!/bin/sh

MACHINE=`uname -m`
if [ $MACHINE = i686 -o $MACHINE = i586 ]; then
  OS=`uname -o 2>/dev/null`
  if [ $? != 0 ]; then # -o option unrecognized
    OS=unknown
  fi
  if [ ! $OS = Cygwin ]; then
    OS=`uname -s`
  fi 
else
  OS=`uname -s`
fi

echo $MACHINE $OS

if [ $OS = OpenBSD -o $OS = FreeBSD ]; then
  REVERSE="tail -r"
else
  REVERSE=tac
fi

X=`./expand-schant.sh int src/schant`
mv x.c schant-int.c
cat schant-int.c | bin/shmall >xx.scm
rm schant-int.c
#filter out forward function definitions
cat xx.scm | $REVERSE | sed -e '/^__forward/{N;N;N;d;}' | \
  $REVERSE >xxxxx.scm
mv xxxxx.scm xx.scm
echo vm >compilation-mode.txt
cat bin/schimper.txt compilation-mode.txt xx.scm | bin/schant-int >xx
rm xx.scm
cat bin/simpvir-assembler.txt xx | bin/schant-int >schant-int.vm.txt
rm xx
