#!/bin/sh
# Verification de l usage 

usage="usage: config nom binaire configuration systeme [tailles]"

case $# in
 0|1|2|3) echo $usage
          exit 1;;
   *) nom=$1; bin=$2; conf=$3; system=$4; shift; shift; shift; shift;;
esac

# Le fichier de configuration est-il un path absolu
#  ou bien un path relatif
case $conf in
	/*) ;; 
	*)  conf=conf/$conf ;;
esac

# Le fichier de configuration est-il la
if test ! -f $conf
then
   echo Le fichier $conf n existe pas.
   exit 1
fi

DIR=/usr/local/caml/V2-6.1/camlisp
SYSDIR=$DIR/$system

# le repertoire systeme de la machine qu on utilise
if test ! -d $SYSDIR
then
  echo le repertoire systeme $SYSDIR n existe pas
  echo $usage
  exit 1
fi

# Le fichier binaire est-il un path absolu
#  ou bien un path relatif
case $bin in
	/*) ;; 
	*)  bin=$SYSDIR/$bin ;;
esac

# Le fichier binaire est-il la
if test ! -f $bin
then
   echo Le binaire $bin n existe pas.
   exit 1
fi

# Creation du script shell de commande
llcmd=/tmp/ll$$
trap "rm -f $llcmd;exit 1" 1 2 3 15
echo exec $bin $* -r $SYSDIR/llcore/$nom.core \$\* > $llcmd
chmod +x $llcmd
 
#  Creation de l image memoire
#  Pour ne pas charger son .lelisp au moment de creer le core
HOME=qwerty

$llcmd $DIR/llib15.23/startup.ll <<EOF
(setq #:system:name (quote |$nom|))
`cat $conf`
(end)
EOF

cp $llcmd $nom
rm -f $llcmd
