#! /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 26311 2011-08-01 22:42:15Z stever $
#
#=========================================================================
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`
export GS_MTYPE=`/export/localnew/scripts/suntype`

case $GS_MTYPE in
  7 )
    MAKE="/export/localnew/hppa.hpux/bin/gmake"
    ;;
  9 )
    MAKE="/opt/freeware/bin/gmake"
    ;;
 10 )
    MAKE="/opt/sfw/bin/gmake"
    PROF_FLAG="-xpg"
    ;;
 13 )
    if [ -a "/opt/sfw/bin/gmake" ]; then
      MAKE="/opt/sfw/bin/gmake"
    elif  [ -a "/usr/sfw/bin/gmake" ]; then
      MAKE="/usr/sfw/bin/gmake"
    else
      echo "cannot find gmake!"
      exit 1
    fi
    PROF_FLAG="-xpg"
    ;;
 42 )
    MAKE="/usr/bin/make"
    ;;
 50 )
    MAKE="/usr/bin/make"
    ;;
 77 )
    MAKE="/export/localnew/ia64.hpux/bin/gmake"
    ;;
esac


# 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="${MAKE} -f Makefile.install"
else
  INSTALLGSmake="${MAKE}"
fi

case $HOSTTYPE.$OSTYPE in
 sparc.Solaris) 
               exec $INSTALLGSmake \
		  CFLAGS="-g -D$HOSTTYPE$OSTYPE -xarch=v9 -mt -D_REENTRANT"  \
                  LDLIBS="-lsocket -lnsl -lrt" PROF_FLAG="$PROF_FLAG" $*
               ;;
 i386.Solaris)
               exec $INSTALLGSmake \
                  CFLAGS="-D$HOSTTYPE$OSTYPE -xarch=amd64"\
                  LDLIBS="-lsocket -lnsl -lrt" PROF_FLAG="$PROF_FLAG" $*
               ;;
 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" $*
	       ;;
 i386.Darwin)  exec $INSTALLGSmake \
                  CFLAGS="-g -m64 -pipe -D_REENTRANT -D_GNU_SOURCE -D_XOPEN_SOURCE -fPIC -fno-strict-aliasing" \
                  LDLIBS="-lpthread -ldl -lc -lm" $*
               ;;

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