#!/bin/sh
# 
# generate a Makefile from an Imakefile outside of the source tree
# 


curdir=`dirname $0`
rootdir=`expr $curdir : '\(.*\)/bin/scripts'`
HGConfigdir=`expr $curdir : '\(.*\)/bin/scripts'`/config

if [ ! -d $HGConfigdir ]
then
  echo "hgmkmf: config directory $HGConfigdir does not exist"
  exit 1
fi

usage="usage: $0 [-a]"
do_all=

case "$#" in
	0)	;;
	1)	case "$1" in
			-a)	do_all="yes"
				;;
			*)	echo "$usage" 1>&2; exit 1
				;;
		esac
		;;
	*)	echo "$usage" 1>&2; exit 1
		;;
esac

if [ -f Makefile ]; then 
	rm -f Makefile.bak
	mv Makefile Makefile.bak
fi

case "$do_all" in
	yes)	set -x
		hgimake -T "template" -I$HGConfigdir -I/usr/lib/X11/config -DUseInstalled -DRootDir=$rootdir &&
		make Makefiles &&
		make depend
		;;
	*)	set -x
		hgimake -T "template" -I$HGConfigdir -I/usr/lib/X11/config -DUseInstalled -DRootDir=$rootdir
		;;
esac
