#!/bin/sh

progname=`echo $0 | sed 's,.*/,,g'`

while [ $# != 0 ]; do
	x="$1"
	shift
	case "$x" in
	-v | --v*) verbose="$x" ;;
	-*)	# usage=1
		;;
	*)	test -z "$sys" || usage=1
		sys="$x" ;;
	esac
done

case "$sys" in
"")	if uname -m >/dev/null 2>/dev/null ; then
	    sys=`uname -m`-`uname -s`
	    sys=`echo $sys | tr [A-Z] [a-z]`
	else
	    echo "$progname: Can't determine system type; please specify." 1>&2
	fi
	;;
esac

if [ "$usage" != "" ]; then
	echo "$progname: usage: $0 [ -v ] [ SYSTEM_TYPE ]"	1>&2
	echo "  " where SYSTEM_TYPE matches:			1>&2
	sed <$0 1>&2 \
		-e '/^#SYS/!d' \
		-e 's/#SYS/      /'
	exit 1
fi

test -z "$verbose" || echo Configuring for system $sys.

# The "#SYS" comments here are magic.  Those lines are emitted in the
# usage message.

case $sys in
#SYS hppa-hpux
	9000/7??-hp-ux)
	name=hppa-hpux-9.03
	sysincludes=hpux-9.03
	config_flags="HPPA_HPUX_903=1"
	;;
#SYS sparc-sunos
    sun4*-sunos*)
    name=sparc-sunos-4.1.3
    sysincludes=sunos-4.1.3
    ;;
#SYS i386-linux
    i[3-5]86-linux*)
	name=i386-linux-1.0
	sysincludes=linux-1.0
	;;
#SYS i386-bsd/386
    i[3-5]86-bsd/386)
    name=i386-bsdi-1.1
    sysincludes=bsdi-1.1
    ;;
#SYS i386-netbsd
    i[3-5]86-netbsd*)
    ver=`uname -r`
    ver=`echo $ver | tr [A-Z] [a-z]`
    case $ver in
    0.9*)
	name=i386-netbsd-0.9
	sysincludes=netbsd-0.9
	;;
    1.0*)
	name=i386-netbsd-1.0
	sysincludes=netbsd-1.0
	;;
    *)
	echo "Version $ver not recognized for NetBSD" 
	exit 1
	;;
    esac
    ;;
#SYS m68k-netbsd
    m68*-netbsd*)
	name=m68000-netbsd
	;;
#SYS romp-bsd
    romp-bsd*)
	name=romp-bsd
	;;
#SYS risc-ultrix (r2000-ultrix)
    risc-ultrix* | r2000-ultrix*)
	name=r2000-ultrix-4.2
	sysincludes=ultrix-4.2
	;;
    *)
	echo "$progname: system type $sys not recognized"  1>&2
	exit 1
	;;
esac

links="include/pthread/machdep.h include/pthread/posix.h pthreads/machdep.c \
	pthreads/syscall.S include/sys include/unistd.h"
targets="../../machdep/engine-$name.h ../../machdep/posix-$sysincludes.h \
	../machdep/engine-$name.c ../machdep/syscall-$name.S \
	../machdep/$sysincludes ../machdep/unistd-$name.h"

rm -f $links 
while [ ! -z "$targets" ]; do
	set $targets
	if [ $# = 0 ]; then break; fi
	target=$1 ; shift
	targets="$*"
	set $links
	link=$1 ; shift
	links="$*"
	test -z "$verbose" || \
		echo Linking $link to $target.
	ln -s $target $link
done

echo Configured for system $sys. > config.status
echo $config_flags > config.flags

exit 0
