#!/bin/sh
#
# The real work is done in the `src' directory.  This is just here to
# allow for the standard ./configure && make && make install sequence
# from the topdirectory
#
# If you want to build for multiple architectures, do:
# 
#	% mkdir myarch
#	% cd myarch
#	% ../src/configure [options]
#	% make
#	% make install

TARGET=lite
configoptions=""

while [ "$1" != "" ]; do
  case "$1" in
    --with-world)	TARGET=world
			shift
			;;
    *)			configoptions="$configoptions $1"
			shift
			;;
  esac
done

if [ -z "$BUILDARCH" ]; then
  BUILDARCH=src;
  MTBUILDARCH=mt
else
  MTBUILDARCH=${BUILDARCH}-mt
fi

if [ ! -d "$BUILDARCH" ]; then mkdir "$BUILDARCH"; fi

sed -e "s/@BUILDARCH@/$BUILDARCH/" \
    -e "s/@MTBUILDARCH@/$MTBUILDARCH/" \
    -e "s/@TARGET@/$TARGET/" \
	Makefile.in > Makefile

(cd $BUILDARCH && ../src/configure $configoptions)

case $TARGET in
  world)
        if [ ! -d "$MTBUILDARCH" ]; then mkdir "$MTBUILDARCH"; fi
	cd $MTBUILDARCH && ../src/configure --enable-mt $configoptions
	;;
esac
