#!/bin/sh
#
# This program is a clone of 'xmkmf', which is part of the 
# MIT X11 distribution. It is an interface to imake, which is used
# to build Makefiles automatically from Imakefiles.
# 
usage="usage:  $0 [<RCCLRootDirectory> [<currentDirectory>]]"

rootdir=
curdir=.

case $# in 
    0) ;;
    1) rootdir=$1 ;;
    2) rootdir=$1  curdir=$2 ;;
    *) echo "$usage" 1>&2; exit 1 ;;
esac

case "$rootdir" in
    -*) echo "$usage" 1>&2; exit 1 ;;
esac

if [ "$rootdir" = "" ]; then
    if [ "$RCCL" = "" ]; then
	echo "Error - environment variable RCCL not defined" 2>&1 ; exit 1
    else 
	rootdir="$RCCL"
    fi
fi

if [ -f Makefile ]; then 
    echo mv Makefile Makefile.BAK
    mv Makefile Makefile.BAK
fi

args="-I$rootdir/conf -DRCCLRootDir=$rootdir -DcurrentDir=$curdir"

echo imake $args
imake $args 
if egrep -s VXW/Makefile: Makefile ; then
   if [ ! -d VXW ] ; then
      if [ -f VXW ] ; then
         echo $0: error -- VXW exists as a regular file
	 exit 1
      fi
      echo mkdir VXW
      mkdir VXW
   fi   
   echo imake $args -DVxWorksConfig -s VXW/Makefile
   imake $args -DVxWorksConfig -s VXW/Makefile
fi
exit 0
