#!/bin/sh
#--------------------------- Shell MegaWave2 Macro --------------------------#
_sccsid="%Z%MegaWave %R%, %M% %I%, %G%";
_Func="Install a new version of the MegaWave2 'light' Preprocessor";
_Prog="`basename $0`"
_Vers="0.0"
_Date="2005"
_Auth="Jacques Froment";
_Usage="[-public] [-clear] [-debug]"
#-----------------------------------------------------------------------------
# This file is part of the MegaWave2 system library 
# MegaWave2 is a "soft-publication" for the scientific community. It has
# been developed for research purposes and it comes without any warranty.
# The last version is available at http://www.cmla.ens-cachan.fr/Cmla/Megawave
# CMLA, Ecole Normale Superieure de Cachan, 61 av. du President Wilson,
#       94235 Cachan cedex, France. Email: megawave@cmla.ens-cachan.fr 
#-----------------------------------------------------------------------------
# Run this shell-script to make a new version of the MegaWave2 preprocessor
# on your machine. Notice : you must have configured your environment to be 
# the MegaWave2 administrator (it does not mean to be the super-user root).
# Options :
# -public : change the preprocessor of the PUBLIC version of MegaWave2
#           (the version used by everybody else than you in your lab), in
#           addition to the PRIVATE version of MegaWave2.
# -clear : clear previous objects.
# -debug : produce debugging information to debug the binaries.

if [ "${MW_MACHINETYPE}" = "" ]; then
   echo "Please set the \$MW_MACHINETYPE environment variable"
   exit 1
fi
if [ "${MW_SYSTEMTYPE}" = "" ]; then
   echo "Please set the \$MW_SYSTEMTYPE environment variable"
   exit 1
fi
if [ "${PRIVATE_MEGAWAVE2}" = "" ]; then
   echo "Please set the \$PRIVATE_MEGAWAVE2 environment variable"
   exit 1
fi
if [ "${PUBLIC_MEGAWAVE2}" = "" ]; then
   echo "Please set the \$PUBLIC_MEGAWAVE2 environment variable"
   exit 1
fi

clear=0
public=0
opt=""

while [ "$1" != "" ]
do
        case "$1" in

            "-public") public=1
		       shift
		       ;;


            "-clear") clear=1
		      shift
                      ;;

	    "-debug") opt="$opt debug"
		      shift
		      ;;

        *)      . .mw2_help_lg_com
                ;;
       
       esac
done

echo " "
echo "*** Install the MegaWave2 'light' preprocessor (mwplight Install) ***"

needir=${PRIVATE_MEGAWAVE2}/kernel_obj/mwplight/obj/${MW_MACHINETYPE}
if [ ! -d ${needir} ]; then
  echo "Create directory ${needir}..."
  mkdir -p ${needir}
fi
needir=${PRIVATE_MEGAWAVE2}/kernel_obj/mwplight/${MW_MACHINETYPE}
if [ ! -d ${needir} ]; then
  echo "Create directory ${needir}..."
  mkdir -p ${needir}
fi

../shell/mwconfig "$opt"
if [ $? -ne 0 ]; then
  echo "*** Error in mwconfig ! Abort mwplight Install. ***" 2>&1
  exit 1
fi
if [ $clear -eq 1 ]; then
  make clean
fi
make all
if [ $? -ne 0 ]; then
  echo "*** Error in 'make all' ! Abort mwplight Install. ***" 2>&1
  exit 1
fi
make install
if [ $? -ne 0 ]; then
  echo "*** Error in 'make install' ! Abort mwplight Install. ***" 2>&1
  exit 1
fi
if [ $public -eq 1 ]; then
  make sysinstall
  if [ $? -ne 0 ]; then
    echo "*** Error in 'make sysinstall' ! Abort mwplight Install. ***" 2>&1
    exit 1
  fi
fi

echo " "
echo "*** Install done for the 'light' preprocessor on $PRIVATE_MEGAWAVE2 ***"
if [ $public -eq 1 ]; then
  echo "*** Install done for the 'light' preprocessor on $PUBLIC_MEGAWAVE2 ***"
fi  
exit 0


