#! /bin/sh
# $Id: dm2ch,v 1.1 1997/09/03 09:14:10 queinnec Exp $
# This script compiles the description of a DMeroon class into .c and .h
# static files.

Usage="dm2ch file otherfiles..."

if [ $# = 0 ]
then 
    echo Usage: $Usage
    exit 1
fi

# Try to find if we are run in the TARGET directory

if [ -f config.sh ]
then . config.sh
else 
    echo Cannot find config.sh file
    echo You are probably not in a TARGET directory
    exit 3
fi

# Try to find a working Scheme implementation.
# Here is a list of Scheme implementations and we try to find one
# that works.

WELL_KNOWN_SCHEMES="bigloo++ bigloo oscheme scc++ sci+ sci scc scm elk stk gsi umb-scheme fools mit-scheme"

for s in ${WELL_KNOWN_SCHEMES}
    do f=`which $s` 2>/dev/null
    # 'which' is tricky wrt csh, sh
    if [ -f "$f" ]
    then SCHEME=$s
        break
    fi
done

if [ -z "${SCHEME}" ]
then 
    echo 'Cannot find a Scheme implementation???'
    echo Edit $0 to add such a beast to WELL_KNOWN_SCHEMES.
    exit 5
fi

{ echo "(load \"${TOP}/Bootstrap/filutl.scm\")"
  echo "(load \"${TOP}/Library/read.scm\")"
  echo '(set! *verbose* #t)'
  echo "(load \"${TOP}/Bootstrap/dm2ch.scm\")"
  echo "(process-file "
  for f 
    do echo " \"$f\" " 
  done
  echo " ) "
} | ${SCHEME}

# end of dm2ch
