:
#	SCCS: @(#)configure	1.9 (99/04/21)
#
#	UniSoft Ltd., London, England
#
# Copyright (c) 1998 The Open Group
# All rights reserved.
#
# No part of this source code may be reproduced, stored in a retrieval
# system, or transmitted, in any form or by any means, electronic,
# mechanical, photocopying, recording or otherwise, except as stated in
# the end-user licence agreement, without the prior permission of the
# copyright owners.
# A copy of the end-user licence agreement is contained in the file
# Licence which accompanies this distribution.
# 
# Motif, OSF/1, UNIX and the "X" device are registered trademarks and
# IT DialTone and The Open Group are trademarks of The Open Group in
# the US and other countries.
#
# X/Open is a trademark of X/Open Company Limited in the UK and other
# countries.
#
# ************************************************************************
#
# SCCS:   	@(#)configure	1.9 99/04/21 TETware release 3.3
# NAME:		configure
# PRODUCT:	TETware
# AUTHOR:	Andrew Josey, The Open Group
# DATE CREATED:	September 1997
#
# DESCRIPTION:
#	This simple script will auto configure the known operating 
#	systems which have defines.mk files included in the src/defines
#	directory.
# 
# MODIFICATIONS:
#	Andrew Dingwall, UniSoft Ltd., September 1998
#	integrated into the TETware distribution
#
#	Andrew Dingwall, UniSoft Ltd., November 1998
#	added support for FreeBSD
#
#	Andrew Dingwall, UniSoft Ltd., March 1999
#	integrated some enhancements received from Andrew Josey -
#		added support for DYNIX/ptx, Solaris 2.7, BSDI
# 
#	Andrew Josey, March 2000
#	Add in Solaris 8 support.
# ************************************************************************

# functions
badusage()
{
	echo "Usage:	$0 -t transport" 1>&2
	echo "To fix:	specify \"-t xti\", \"-t inet\", or \"-t lite\"" 1>&2
	exit 2
}

unknown_os()
{
	echo "$0: Unable to determine the OS type."
	echo "Please configure manually, refer to TETware Installation Guide."
	echo "Upon successful configuration please send the output of"
	echo "src/helpers/GuessOS and the corresponding makefile for your platform"
	echo "(edited from src/defines/template.mk) to tet_support@opengroup.org."
	exit 1
}

# parse the command line
args=`getopt t: $*`
if test $? -ne 0
then
	badusage
else
	set -- $args
fi

tplib=
while test $# -gt 0
do
	case "$1" in
	-t)
		tplib="$2"
		shift
		;;
	--)
		shift
		break
		;;
	-*)
		badusage
		;;
	esac
	shift
done

case "$tplib" in
inet|xti|lite)
	;;
*)
	badusage
	;;
esac

# change to the source directory
cd src
if test $? -ne 0
then 
	echo "$0: Unable to find src directory, aborting"
	exit 1
fi

# determine the OS type
case `uname -s` in
Windows_NT|Windows_95|DOS)
	os=win32
	if test "$tplib" = xti
	then
		echo "$0: Win32 systems do not support XTI networking" 1>&2
		exit 1
	fi
	;;
*DYNIX/ptx*)
	os=dynix
	;;
*)
	os=`sh ./helpers/GuessOS`
	;;
esac  


# decide whether we should link or copy the defines.mk file
case $os:$tplib in
win32:*)
	cpln=cp
	;;
*:inet)
	cpln="ln -s"
	;;
*)
	cpln=cp
	;;
esac


# determine which defines.mk file to use
fname=

case "$os" in
win32)
	fname=msc+mks.mk
	;;
dynix)
	fname=dynix.mk
	;;
*-unixware2*|*-unixware7)
	fname=svr42mp.mk
	;;
*-unixware1*)
	fname=svr4.mk
	;;
*-ibm-aix4.[12])
	fname=aix41.mk
	;;
*-ibm-aix4.3)
	fname=aix43.mk
	;;
*-ibm-aix3*)
	fname=aix32.mk
	;;
*-hi-hiux*)
	fname=hiux9.mk
	;;
*-hp-hpux10*)
	fname=hpux10.mk
	;;
*-hp-hpux*)
	fname=hpux9.mk
	;;
*-linux*)
	fname=linux.mk
	;;
*-dec-osf)
	fname=osf1.mk
	;;
*-dec-osf4)
	fname=decux4.mk
	;;
*-sun-solaris2*)
	case `uname -r` in
	5.[0-5]*)
		fname=sunos5.mk
		;;
	5.[67]*)
		fname=sunos56.mk
		;;
	*)
		unknown_os
		;;
	esac
	;;
*-sun-solaris8)
	fname=solaris7.mk
	cpln=cp
	echo "$0: Solaris 8 detected. (using solaris7.mk)"
	echo "The default configuration assumes 32-bit, with POSIX Threads,"
	echo "Sun Workshop C compiler and no C++ compiler."
	echo "Edit the defines.mk file if you need to enable 64-bit mode,"
	echo "or change other configuration as per the comments."
	;;
*-sun-solaris7)
	fname=solaris7.mk
	cpln=cp
	echo "$0: Solaris 7 detected."
	echo "The default configuration assumes 32-bit, with POSIX Threads,"
	echo "Sun Workshop C compiler and no C++ compiler."
	echo "Edit the defines.mk file if you need to enable 64-bit mode,"
	echo "or change other configuration as per the comments."
	;;
*-sun-sunos4*)
	fname=sunos41.mk
	;;
CRAY*)
	fname=cray.mk
	;;
*-sgi-irix*)
	fname=irix.mk
	;;
*-freebsd)
	fname=freebsd.mk
	;;
*-bsdi)
	fname=bsdi.mk
	;;
# these two had to be left out of the distribution for now
# *-qnx*)
#	fname=qnx4.mk
#	;;
# MPE/iX-*)
#	fname=mpeix.mk
#	;;
*)
	unknown_os
	;;
esac

# locate the chosen defines.mk file
if test ! -d defines
then
	echo "$0: no defines directory - aborting" 1>&2
	exit 1
fi

mkfile=`find defines -name ${fname:?} -print | head -1`

if test -z "$mkfile"
then
	echo "$0: can't find $fname in the defines directory" 1>&2
	exit 1
fi

# link/copy the chosen defines.mk file in place
echo "$0: using $mkfile"
rm -f defines.mk
eval ${cpln:?} ${mkfile:?} defines.mk

# configure TETware to use the chosen network transport
sh tetconfig -t $tplib
echo "OS=$os Configured"

# emit informational messages if we are not building Distributed TETware
# to use sockets
if test "$tplib" != inet
then
	chmod u+w defines.mk
	echo
	echo "$0: the selected defines.mk file has been designed to build"
	echo "Distributed TETware to use the socket network interface."
	echo "If you are building a different version of TETware you may need"
	echo "to edit the defines.mk file before building TETware."
fi
if test "$tplib" = lite
then
	echo "For example: if network libraries have been specified in the"
	echo "SYSLIBS assignment, you don't need these when building TETware-Lite."
fi
if test "$tplib" = xti
then
	echo "For example: you will need to add something to DTET_CDEFS to specify"
	echo "which transport provider(s) you want to use (-DTCPTPI and/or -DOSITPI),"
	echo "and you will probably want to specify -DSVID3_POLL as well."
	echo "Also, you may need to specify different network libraries using"
	echo "the SYSLIBS variable."
	echo "Refer to the TETware Installation Guide for details."
fi

# what to do next
echo
echo "To build TETware:"
echo "	cd src; make; make install"

