#! /bin/sh

echo "Running configure in `pwd` ..."

# List of all the variables we'll be accepting.
#
all_options="prefix"

# Default values for variables.
#
default_prefix=`pwd`

# Parse arguments.
#
for opt in $all_options; do
	eval "$opt=NONE"
done

for option
do
	case $option in
	-*=*)
		optname=`echo "$option" | sed -e "s/^--//" -e "s/=.*//" -e "s/-/_/g"`
		optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'`
		eval "$optname=\$optarg"
		;;
	-*)
		echo "configure: error: $option: invalid option; use --help to show usage" 1>&2
		exit 1
		;;
	esac
done

for opt in $all_options; do
	eval "[ \"x\$$opt\" = xNONE ]" && eval "$opt=\$default_$opt"
done

# End argument-parsing.

RM="/bin/rm -f"

uname=`uname -s`
case ${uname} in
HP-UX)
	;;
NetBSD|Linux)
	;;
esac

cat=cat
cc=g++
chmod=chmod
cp='/bin/cp -f'
dvips=dvips
echo=echo
head=head
latex=latex
ln='/bin/ln -f'
mkdep=makedepend
mkdir='mkdir -p'
mv='/bin/mv -f'
ranlib=ranlib
rm='/bin/rm -f'
rootdir=`pwd`
sed=sed
sort=sort
strip=strip
tar=tar
touch=touch
version=`cat version`

OUTFILES="\
	Makefile \
	c++/Makefile \
	gtl/Makefile \
	src/Makefile \
	"

for outfile in ${OUTFILES}; do
	[ -f ${outfile} ] && ${RM} ${outfile}
	infile=${outfile}.in
	if [ -f ${infile} ]; then
		echo "creating ${outfile}."
		sed \
			-e "s,@prefix@,${prefix},g" \
			-e "s,@cat@,${cat},g" \
			-e "s,@cc@,${cc},g" \
			-e "s,@chmod@,${chmod},g" \
			-e "s,@cp@,${cp},g" \
			-e "s,@dvips@,${dvips},g" \
			-e "s,@echo@,${echo},g" \
			-e "s,@head@,${head},g" \
			-e "s,@latex@,${latex},g" \
			-e "s,@ln@,${ln},g" \
			-e "s,@mkdep@,${mkdep},g" \
			-e "s,@mkdir@,${mkdir},g" \
			-e "s,@mv@,${mv},g" \
			-e "s,@ranlib@,${ranlib},g" \
			-e "s,@rm@,${rm},g" \
			-e "s,@rootdir@,${rootdir},g" \
			-e "s,@sed@,${sed},g" \
			-e "s,@sort@,${sort},g" \
			-e "s,@strip@,${strip},g" \
			-e "s,@tar@,${tar},g" \
			-e "s,@touch@,${touch},g" \
			-e "s,@version@,${version},g" \
			${infile} > ${outfile}
	fi
done

( cd cmdline; sh configure --prefix=${prefix} )
