#!/bin/sh

# Configuration subroutine to validate and canonicalize a configuration type.
# Supply the specified configuration type as an argument.
# If it is invalid, we print an error message on stderr and exit with code 1.
# Otherwise, we print the canonical config type on stdout and succeed.

# This file is supposed to be the same for all GNU packages
# and recognize all the CPU types, system types and aliases
# that are meaningful with *any* GNU software.
# Each package is responsible for reporting which valid configurations
# it does not support.  The user should be able to distinguish
# a failure to support a valid configuration from a meaningless
# configuration.

# Please email any bugs, comments, and/or additions to this file to:
# configure@cygnus.com

# decode aliases into canonical names

case "$1" in
# cpu alone is a valid alias for cpu-none-none.
vax | tahoe | i386 | i860 | m68k | m68000 | m88k | sparc | ns32k \
	| alliant | arm | c1 | c2 | mips | pyramid | tron | a29k \
	| rtpc | rs6000 | i960)
	cpu=$1
	vendor=none
	os=none
	;;
nindy960)
	cpu=i960
	vendor=intel
	os=nindy
	;;
vxworks68)
	cpu=m68k
	vendor=wrs
	os=vxworks
	;;
vxworks960)
	cpu=i960
	vendor=wrs
	os=vxworks
	;;
am29k)
	cpu=a29k
	vendor=none
	os=bsd
	;;
umax)
	cpu=ns32k
	vendor=encore
	os=sysv # maybe?
	;;
pn)
	cpu=pn
	vendor=gould
	os=sysv # maybe?
	;;
np1)
	cpu=np1
	vendor=gould
	os=sysv # maybe?
	;;
merlin)
	cpu=merlin
	vendor=utek
	os=sysv # maybe?
	;;
iris | iris4d)
	cpu=mips
	vendor=sgi
	os=sysv # maybe?
	;;
news1000)
	cpu=m68030
	vendor=sony
	os=sysv # maybe?
	;;
news | news700 | news800 | news900)
	cpu=m68k
	vendor=sony
	os=sysv # maybe?
	;;
unixpc | safari | pc7300 | 3b1 | 7300 | 7300-att | att-7300)
	cpu=m68k
	vendor=att
	os=sysv # maybe?
	;;
delta | 3300 | motorola-3300 | motorola-delta \
      | 3300-motorola | delta-motorola)
	cpu=m68k
	vendor=motorola
	os=sysv # maybe?
	;;
vax-dec)
	cpu=vax
	vendor=dec
	os=ultrix # maybe?
	;;
balance)
	cpu=ns32k
	vendor=sequent
	os=dynix
	;;
mmax)
	cpu=ns32k
	vendor=encore
	os=sysv # maybe?
	;;
symmetry)
	cpu=i386
	vendor=sequent
	os=dynix
	;;
sun2)
	cpu=m68000
	vendor=sun
	os=sunos4
	;;
sun2os3)
	cpu=m68000
	vendor=sun
	os=sunos3
	;;
sun2os4)
	cpu=m68000
	vendor=sun
	os=sunos4
	;;
sun3)
	cpu=m68k
	vendor=sun
	os=sunos4
	;;
sun3os3)
	cpu=m68k
	vendor=sun
	os=sunos3
	;;
sun3os4)
	cpu=m68k
	vendor=sun
	os=sunos4
	;;
sun4)
	cpu=sparc
	vendor=sun
	os=sunos4
	;;
sun4os3)
	cpu=sparc
	vendor=sun
	os=sunos3
	;;
sun4os4)
	cpu=sparc
	vendor=sun
	os=sunos4
	;;
pbd)
	cpu=sparc
	vendor=unicom
	os=sysv
	;;
roadrunner | sun386 | sun386i)
	cpu=i386
	vendor=sun
	os=sunos
	;;
ps2)
	cpu=i386
	vendor=ibm
	os=sysv # maybe?
	;;
i386sco)
	cpu=i386
	vendor=sco
	os=sysv # maybe?
	;;
i386v)
	cpu=i386
	vendor=none
	os=sysv
	;;
i386v32)
	cpu=i386
	vendor=none
	os=sysv32
	;;
next)
	cpu=m68k
	vendor=next
	os=sysv # maybe?
	;;
hp300bsd)
	cpu=m68k
	vendor=hp
	os=bsd
	;;
hp300hpux | hpux | hp9k3[2-9][0-9])
	cpu=m68k
	vendor=hp
	os=hpux
	;;
hp9k31[0-9] | hp9k2[0-9][0-9])
	cpu=m68000
	vendor=hp
	os=hpux
	;;
isi | isi68)
	cpu=m68k
	vendor=isi
	os=sysv # maybe?
	;;
apollo68)
	cpu=m68k
	vendor=apollo
	os=sysv # maybe?
	;;
altos | altos3068)
	cpu=m68k
	vendor=altos
	os=sysv # maybe?
	;;
altosgas)
	cpu=m68k
	vendor=altos
	os=gas
	;;
miniframe)
	cpu=m68000
	vendor=convergent
	os=sysv # maybe?
	;;
tower | tower-32)
	cpu=m68k
	vendor=ncr
	os=sysv # maybe?
	;;
bigmips | news-3600 | risc-news)
	cpu=mips
	vendor=sony
	os=newsos # maybe?
	;;
littlemips)
	cpu=mips
	vendor=little
	os=bsd
	;;
dec3100 | decstatn | decstation | decstation-3100 | pmax)
	cpu=mips
	vendor=dec
	os=ultrix
	;;
magnum | m3230)
	cpu=mips
	vendor=mips
	os=sysv # maybe?
	;;
gmicro)
	cpu=tron
	vendor=none
	os=sysv # maybe?
	;;
convex-c1)
	cpu=c1
	vendor=convex
	os=sysv # maybe?
	;;
convex-c2)
	cpu=c2
	vendor=convex
	os=sysv # maybe?
	;;
none)
	cpu=none
	vendor=none
	os=none
	;;

# not an alias.  parse what we expect to be a canonical name.
*)
	cpu=`echo $1 | sed 's/-.*$//'`

	if [ "${cpu}" = "$1" ] ; then
		# no vendor so this is an invalid name.
		echo '***' No vendor: configuration \`$1\' not recognized 1>&2
		exit 1
	else
		# parse out vendor
		rest=`echo $1 | sed "s/${cpu}-//"`
		vendor=`echo ${rest} | sed 's/-.*$//'`

		if [ "${vendor}" = "${rest}" ] ; then
			# a missing os is acceptable
			os=none
		else
			os=`echo ${rest} | sed "s/${vendor}-//"`
		fi
	fi
	;;
esac

# At this point we should have three parts of a canonical name in cpu,
# vendor, and os.

# verify that the cpu is known.

case "${cpu}" in
vax | tahoe | i386 | i860 | m68k | m68000 | m88k | sparc | ns32k \
	| alliant | arm | c1 | c2 | mips | pyramid | tron | a29k \
	| rtpc | rs6000 | i960 | none)
	;;
*)
	echo '***' Invalid cpu \`${cpu}\': configuration \`$1\' not recognized 1>&2
	exit 1
	;;
esac

# verify that the vendor is known.

case "${vendor}" in
none | convex | mips | dec | little | sony | ncr | convergent \
	| altos | apollo | isi | hp | next | sco | ibm | sun \
	| unicom | sequent | encore | motorola | att | sgi \
	| utek | gould | wrs | intel | aout | bout | coff) ;;
*)
	echo '***' Invalid vendor \`${vendor}\': configuration \`$1\' not recognized 1>&2
	exit 1
	;;
esac

# verify that the os is known, if it exists.

case "${os}" in
aix* | aout | bout | bsd* | coff | ctix* | dynix* | esix* | hpux* \
	| isc* | mach* | newsos* | nindy* | none | osf* | osf* | sco* \
	| sunos* | sysv* | ultrix* | unos* | v88r* | vms* | vxworks*)
	;;
*)
	echo '***' Invalid os \`${os}\': configuration \`$1\' not recognized 1>&2
	exit 1
	;;
esac

echo ${cpu}-${vendor}-${os}