#!/bin/sh
#
# Examine the CCOPTS for building the IRIX kernel and make an
# appropriate set for building lsof.
#
# Usage:	MkKernOpts <version>

# Get the kernel's CC options.

KM=/var/sysgen/system/irix.sm
CCOPTS=`grep CCOPTS $KM`

# Preset the options of interest: _HIBERNATORII, _PAGESZ, _SHAREII,
# USE_LPAGES, and ULI

RHIB=""
RLGPG=""
RPGSZ=""
RSHAR=""
RULI=""

# Scan the kernel's CC options.

for i in $CCOPTS
do
  case $i in
  -D_HIBERNATORII)
    RHIB=$i
    ;;
  -D_PAGESZ*)
    RPGSZ=$i
    ;;
  -D_SHAREII)
    RSHAR=$i;
    ;;
  -DULI)
    RULI=$i
    ;;
  -DUSE_LGPAGES)
    RLGPG=$i
    ;;
  esac
done

# Assemble the result.
#
# Always accept _HIBERNATORII, _SHAREII, USE_LGPAGES, and ULI

if test "X$RHIB" != "X"
then
  R=$RHIB
fi
if test "X$RSHAR" != "X"
then
  if test "X$R" = "X"
  then
    R=$RSHAR
  else
    R="$R $RSHAR"
  fi
fi
if test "X$RLGPG" != "X"
then
  if test "X$R" = "X"
  then
    R=$RLGPG
  else
    R="$R $RLGPG"
  fi
fi
if test "X$RULI" != "X"
then
  if test "X$R" = "X"
  then
    R=$RULI
  else
    R="$R $RULI"
  fi
fi

# Accept _PAGESZ only if neither _HIBERNATORII nor _SHAREII is defined
# for IRIX version < 6.2.  Always accept _PAGESZ for IRIX 6.2.

if test "X$RPGSZ" != "X"
then
  if test $1 -ge 60200 -o \( "X$RHIB" = "X" -a "X$RSHAR" = "X" \)
  then
    if test "X$R" = "X"
    then
      R=$RPGSZ
    else
      R="$R $RPGSZ"
    fi
  fi
fi

# Echo the result.

echo $R
