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

# Don't want to pick up host customizations
export INDEX_PRISTINE=1

# Don't give luser advice if it fails
export INDEX_QUIET=1

# Concurrency of index build
export INDEX_JOBS=6

pb=/var/portbuild

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

if [ $# -ne 3 ]; then
  usage
fi

arch=$1
branch=$2
buildid=$3
shift 3

builddir=${pb}/${arch}/${branch}/builds/${buildid}

. ${pb}/${arch}/portbuild.conf
. ${pb}/scripts/buildenv

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

unset DISPLAY

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

cd ${PORTSDIR}
make index

# remove extra spaces in dependency list -- this causes problems
# Also transform the dummy paths to their canonical locations
sed -i '' -e 's/  */ /g' -e 's/|  */|/g' -e 's/  *|/|/g' -e "s,${LOCALBASE},/usr/local," ${INDEXFILE}
