#!/bin/sh

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

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

# configurable variables
pb=/var/portbuild
arch=$1
branch=$2
buildid=$3
shift 3

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

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

# -j# to make duds
DUDSJOBS=4

buildenv ${pb} ${arch} ${branch} ${builddir}

duds=${builddir}/duds
index=${PORTSDIR}/${INDEXFILE}

unset DISPLAY

export __MAKE_SHELL=/rescue/sh
export PACKAGE_BUILDING=1
export LOCALBASE=/nonexistentlocal
export X11BASE=/nonexistentx
export LINUXBASE=/nonexistentlinux
export PKG_DBDIR=/nonexistentpkg
export PORT_DBDIR=/nonexistentport

cd ${PORTSDIR}
make -j${DUDSJOBS} ignorelist ECHO_MSG=true > ${duds} || exit 1
sort ${duds} > ${duds}.tmp
mv -f ${duds}.tmp ${duds}

cp ${duds} ${duds}.orig
grep -Ff ${duds}.orig ${index} | cut -f 1 -d \| > ${duds}.full
