#! /bin/sh
set -e
set -o pipefail
[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_DIALOG4PORTS}" ] && set -x
if [ -z "${DIALOG4PORTS}" -o -z "${PORTSDIR}" -o -z "${MAKE}" ]; then
echo "DIALOG4PORTS, MAKE and PORTSDIR required in environment." >&2
exit 1
fi
: ${DIALOGPORT:=ports-mgmt/portconfig}
: ${DIALOGNAME:=portconfig}
OPTIONSFILE="$1"
if ! [ -e $DIALOG4PORTS ]; then
if [ -n "${INSTALL_AS_USER}" -o "${PREFIX}" != "${LOCALBASE}" ]; then
if ! [ -d "${PORTSDIR}/${DIALOGPORT}" ]; then
echo "===> Skipping 'config' as ${DIALOGPORT} is not checked out" >&2
exit 1
fi
DIALOG4PORTS=$(${MAKE} -C ${PORTSDIR}/${DIALOGPORT} -V DIALOG4PORTS)
if ! [ -e "${DIALOG4PORTS}" ]; then
echo "===> Building ${DIALOGNAME} as it is required for the config dialog"
${MAKE} -C ${PORTSDIR}/${DIALOGPORT} -D NO_DIALOG clean build
fi
else
echo "===> Building/installing ${DIALOGNAME} as it is required for the config dialog"
${MAKE} -C ${PORTSDIR}/${DIALOGPORT} -D NO_DIALOG clean install
${MAKE} -C ${PORTSDIR}/${DIALOGPORT} -D NO_DIALOG clean
fi
fi
if ! env -u PKGNAME ${DIALOG4PORTS} -v > /dev/null 2>&1; then
exec env LC_ALL=C.UTF-8 $DIALOG4PORTS > $OPTIONSFILE 2>&1
fi
exec env LC_ALL=C.UTF-8 $DIALOG4PORTS 2> $OPTIONSFILE