#!/bin/sh
# usage: $0 branch

# -j# to make index
# XXX corrupts index file because of lack of synchronization?
#INDEXJOBS=1

pb=/var/portbuild
. ${pb}/portbuild.conf
. ${pb}/scripts/buildenv

usage () {
  echo "usage: makeindex branch"
  exit 1
}

if [ $# != 1 ]; then
  usage
fi

case "x$1" in
  x4)
    branch=4
    ;;
  x4-exp)
    branch=4-exp
    ;;
  x5)
    branch=5
    ;;
  *)
    usage
    ;;
esac

# Set up the build env variables
buildenv ${pb} ${branch}

unset DISPLAY

# Don't pick up installed packages from the host
export LOCALBASE=/nonexistentlocal
export X11BASE=/nonexistentx

cd ${PORTSDIR}
make index
# remove extra spaces in dependency list -- this causes problems
# Also transform the dummy paths to their canonical locations
sed -e 's/  */ /g' -e 's/|  */|/g' -e 's/  *|/|/g' -e "s,${LOCALBASE},/usr/local," -e "s,${X11BASE},/usr/X11R6," INDEX > INDEX.tmp

mv -f INDEX.tmp INDEX
