#!/bin/sh
#
# Build script for rat. This script determines the type of machine it's
# running on, and calls "make" with the appropriate macro definitions
# to set up the machine specific includes etc.
#
# NOTE: If the environment variable MAKE is set, it's value will be
#       used instead of the default "make". Use this to give a path
#       to gnu make, for example.
#
# $Revision$
# $Date$
#
# Copyright (c) 1996 University College London
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#      This product includes software developed by the Computer Science
#      Department at University College London
# 4. Neither the name of the University nor of the Department may be used
#    to endorse or promote products derived from this software without
#    specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

# Find out the type of system we're running on. The nasty stuff is needed for $OSMVER
# since some systems (HP-UX) give the OS version in a weird format. At the end of this
# we should have the following variables set:
# 
#    OSTYPE : Base operating system type
#    OSMVER : The major version number of the system
#    OSVERS : The full version number of the system
#
echo "Determining system type..."
OSTYPE=`uname -s`
OSVERS=`uname -r`
case $OSTYPE in
  Linux         ) OSMVER=`echo $OSVERS | awk -F. '{printf("%d_%d", $1, $2)}'`
                  ;;
  SunOS | IRIX  ) OSMVER=`echo $OSVERS | awk -F. '{print $1}'`
		  OSLIBS="-lsocket -lnsl"
                  ;;
  HP-UX         ) OSTYPE=HPUX
                  OSMVER=`echo $OSVERS | awk -F. '{print $2}'`
                  ;;
  FreeBSD       ) OSMVER=`echo $OSVERS | awk -F. '{print $1}'`
		  OSLIBS=""
                  ;;  
  *             ) echo "$OSTYPE $OSVERS is not supported!"
                  exit
                  ;;
esac

echo "OSTYPE=$OSTYPE"
echo "OSVERS=$OSVERS"
echo "OSMVER=$OSMVER"

export OSLIBS
cmd="${MAKE:=make} all OSTYPE=$OSTYPE OSMVER=$OSMVER OSVERS=$OSVERS"

exec $cmd

