#!/bin/sh

[ $# -gt 0 ] && STAGE=$1 || STAGE=portlist

PORTDIRSFILE=portdirs

if [ ! -r ${STAGE} ]; then
	echo "List of ports \"${STAGE}\" not found."
	exit 1
fi

[ -r ${PORTDIRSFILE} ] || find . -type d > ${PORTDIRSFILE}

for p in $(cat ${STAGE}); do
	cat ${PORTDIRSFILE} | grep ".*/$p$"
done | \
	sed -e 's/\.\//\/usr\/ports\//' | awk '{print "cd " $1 "; make config-recursive"}' > ${STAGE}-config.sh

chmod a+x ${STAGE}-config.sh
