#! /bin/sh
#set -xv
#=========================================================================
# Copyright (C) VMware, Inc. 1986-2011.  All Rights Reserved..
#
# Name - makeinstall.sh
#
# Usage - buildsystests [make-args]
#         Examples:
#           buildsystests CC=gcc  # will compile and link using gcc instead of cc
#           buildsystests clobber # will remove all executables and objects. 
# Purpose - invoke the install Makefile with the proper host dependent
#           arguments.
#
# $Id: makeinstall.sh,v 1.11 2008-01-28 23:14:39 normg Exp $
#
#=========================================================================

if [ "x$BASH_VERSION" = "x" ]; then
  if [ "a$GSBASH" = "a" ]; then
    if [ "a$GEMSTONE" = "a" ]; then
      echo "ERROR: GemStone scripts require a GEMSTONE environment variable."
      echo "       Please set it to the directory where GemStone resides."
      exit 1
    fi
    BASH=$GEMSTONE/bin/bash
  else
    BASH=$GSBASH
  fi
  # Should be using -x here, but we have Ultrix /bin/sh to consider..
  if [ ! -f $BASH ]; then
    echo "ERROR: I can't find $BASH. Please check your GEMSTONE environment"
    echo "       variable, or call GemStone Customer Support for assistance."
    exit 1
  fi
  if [ ! -f /etc/license ]; then # don't do this with Ultrix shell
    unset ENV
  fi
  exec $BASH -norc -noprofile $0 $*
  exit $?
fi

export HOSTTYPE=`/export/localnew/scripts/suntype -hosttype`
export OSTYPE=`/export/localnew/scripts/suntype -ostype`

if [ "x$INSTALLGSmake" = "x" ]; then
  INSTALLGSmake="make" # default value
  if [ "$HOSTTYPE.$OSTYPE" = "sparc.Solaris" ]; then
    INSTALLGSmake="/export/localnew/sparc.Solaris/bin/gnumake"
  fi
fi

# Set up correct path.  THIS IS NOT TRIVIAL!!!
savedPath=$PATH
PATH=/bin:/usr/bin		# minimal
if [ -d /usr/ccs/bin ]; then
  PATH=/usr/ccs/bin:$PATH	# must be after /bin, but before /usr/ucb
fi
# PATH=$PATH:/usr/ucb		# /usr/ucb not needed by this script.
PATH=$PATH:$savedPath		# put your junk AFTER my junk.
export PATH

# For internal work
if [ -f Makefile.install ]; then
  INSTALLGSmake="$INSTALLGSmake -f Makefile.install"
fi

case $HOSTTYPE.$OSTYPE in
 sparc.Solaris) 
               exec $INSTALLGSmake \
		  CFLAGS="-g -D$HOSTTYPE$OSTYPE -xarch=v9 -mt -D_REENTRANT"  \
                  LDLIBS="-lsocket -lnsl -lrt" $*
               ;;
 i386.Solaris)
               exec $INSTALLGSmake \
                  CFLAGS="-g -D$HOSTTYPE$OSTYPE -m64 -Kpic -mt -D_REENTRANT"  \
                  LDLIBS="-lsocket -lnsl -lrt" $*
               ;;
 x86_64.Linux)
               exec $INSTALLGSmake \
	          CFLAGS="-D$HOSTTYPE$OSTYPE -m64"\
                  LDLIBS="-lc -lrt -lm" $*
               ;;
 hppa.hpux*)
               # HP-UX 11.x on PA 
               exec $INSTALLGSmake "CFLAGS=+DD64 -Aa -Dhppahpux -D_HPUX" \
                  "AIO_LIB=-lrt" $*
               ;;

 ia64.hpux*)
	       # HP-UX 11.x on IA64
               exec $INSTALLGSmake "CFLAGS=+DD64 +DSitanium2 -Aa -D_HPUX" \
                  "AIO_LIB=-lrt" $*
               ;;
 RISC6000.AIX)
               exec $INSTALLGSmake \
                 "CFLAGS=-g -qdbxextra -qfullpath -+ -D_REENTRANT -D_THREAD_SAFE -q64 -qthreaded -qarch=ppc" $*
	       ;;

 *)
               exec $INSTALLGSmake CFLAGS=-D$HOSTTYPE$OSTYPE $*
               ;;
esac
