#!/bin/bash
#
# $Id: nsb-package,v 1.1 2002/08/02 15:18:15 rstory Exp $
# Author: Robert Story <rstory@freesnmp.com>
#
########################################################################
########################################################################

usage()
{
   echo "Usage: $0  [-c] [-d] [-p] [-s SRCD] [-b BUILDD] [-i INSTALLD] VERSION"
   echo ""
   echo " VERSION    : relase number (eg 5.0.3)"
   echo " -s SRCDIR  : soure directory [$HOME/src/net-snmp-VERSION]"
   echo " -b BUILDD  : build directory [$HOME/build/]"
   echo "              NOTE-platform will be appended to build directory"
   echo " -i INSTALLD: install directory [$HOME/build/\$PLATFORM/usr/local]"
   echo ""
   echo " -c : skip configure"
   echo " -d : dirty build (don't make distclean)"
   echo " -m : skip 'make all'"
   echo " -p : don't pause at prompts in between stages"
   echo " -t : skip 'make test'"
   exit 1
}

#set -x


if [ -f nsb-functions ];then
   source nsb-functions
elif [ -f $HOME/bin/nsb-functions ]; then
   source $HOME/bin/nsb-functions
else
   echo "Cannot find nsb-functions"
   exit 1
fi


########################################################################
########################################################################

#      x)  x=$OPTARG ;;
while getopts b:cdi:mps:t opt
do
    case "$opt" in
      b)  BUILDD=$OPTARG ;;
      c)  NSB_SKIP_CONFIG=1 ;;
      d)  NSB_CLEAN=0 ;;
      i)  INSTALLD=$OPTARG ;;
      m)  NSB_SKIP_BUILD=1 ;;
      p)  NSB_PROMPT=0 ;;
      s)  SRCD=$OPTARG ;;
      t)  NSB_SKIP_TEST=1 ;;
      \?)# unknown flag
        usage;;
    esac
done
shift `expr $OPTIND - 1`

if [ $# -ne 1 ]; then
   echo "expecting 1 argument, got $# ($@)"
   usage
fi

if [ $NSB_CLEAN -eq 1 ]; then
   if [ $NSB_SKIP_CONFIG -eq 1 ]; then
      echo "A clean build also requires configuration (-d and -c"
      echo "cannot both be specified)."
      usage
   fi
fi

VERSION=$1
if [ -z "$SRCD" ]; then
   SRCD=$HOME/src/net-snmp-$VERSION
fi
if [ -z "$BUILDD" ]; then
   BUILDD=$HOME/build
fi
if [ -z "$INSTALLD" ]; then
   INSTALLD=$HOME/build/`nsb-sysname`/usr/local
fi


########################################################################
########################################################################
BUILDD=$BUILDD/`nsb-sysname`
nsb-prompt "press enter to build $SRCD in $BUILDD, and install in $INSTALLD"
nsb-build $VERSION $SRCD $BUILDD $INSTALLD
