#!/bin/sh 
#--------------------------- Shell MegaWave Macro ----------------------------#
_sccsid="%Z%MegaWave2 %R%, %M% %I%, %G%";
_Prog="mwcmwcheck"
_Vers="1.2";
_Date="2001-2006";
_Func="Check the MegaWave2 compiler";
_Auth="Jacques Froment";
_Usage=""

#----------------------------------------------------------------------------#
# This file is part of the MegaWave2 system macros. 
# 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 
#-----------------------------------------------------------------------------

# Error code returned :
# 0 : MegaWave2 compiler successively checked for all given modules and
#     using both the 'traditional' preprocessor and the 'light' one.
# 1 : None modules could be checked.
# 2 : The compilation using the 'traditional' preprocessor failed for
#     at least one module, and so one using the 'light' one.
# 3 : The compilation using the 'traditional' preprocessor failed for
#     at least one module, but all computations worked for the 'light' one.
# 4 : The compilation using the 'light' preprocessor failed for
#     at least one module, but all worked for the 'traditional' one.

# Check input
if [ $# -ne 0 ]; then
   . .mw2_help_lg_com
fi

# List of modules on which the compiler has to be checked.
# Make the choice of modules that can be compiled at the first pass,
# that is that does not depend to another module.

modlist="ccopy"

# Check result with mwp ('traditional' preprocessor) and mwplight (the 'light' one)
mwp=1
mwplight=1

oneok=0
for mod in $modlist
do
 where=`mwwhere $mod | head -1`
 if [ "$where" = "" ]; then
  echo "Warning: compiler cannot be checked on module \"$mod\" (module not found) !"  1>&2
 else
  loc=`dirname $where`
  if [ ! -w $loc ]; then
   echo "Warning: compiler cannot be checked on module \"$mod\" ! (no write permission on \"$loc\")"  1>&2
  else
   (cd $loc; cmw2 -N -traditional $mod >> /dev/null 2>> /dev/null;)
   if [ $? -ne 0 ]; then
    mwp=0
    echo "Module \"$mod\" cannot be compiled using the 'traditional' preprocessor !" 1>&2
    echo "Following the corresponding output. Please send these lines when reporting bugs:" 1>&2
    echo "--------------------------------------------------------------------------------" 1>&2 
    (cd $loc; cmw2 -N -traditional $mod)
    echo "--------------------------------------------------------------------------------" 1>&2 
   else
    oneok=1
   fi
   (cd $loc; cmw2 -N -light $mod >> /dev/null 2>> /dev/null;)
   if [ $? -ne 0 ]; then
    mwplight=0
    echo "Module \"$mod\" cannot be compiled using the 'light' preprocessor !" 1>&2
    echo "Following the corresponding output. Please send these lines when reporting bugs:" 1>&2
    echo "--------------------------------------------------------------------------------" 1>&2 
    (cd $loc; cmw2 -N -light $mod)
    echo "--------------------------------------------------------------------------------" 1>&2 
   else
    oneok=1
   fi
  fi
 fi
done

if [ $oneok -eq 0 ]; then
 echo "Error: zero module successfully compiled !"  1>&2
 exit 1
fi

if [ $mwp -eq 0 ] && [ $mwplight -eq 0 ]; then
 exit 2
fi

if [ $mwp -eq 0 ]; then
 exit 3
fi

if [ $mwplight -eq 0 ]; then
 exit 4
fi

exit 0







