#!/bin/sh
#
######################################################################
#
# NAME
#	list-dependencies -- build package dependencies list
#
# SYNOPSIS
#	list-dependencies bootstrap build full
#
# DESCRIPTION
#	For each (reduced) dependency a line of the following format is
#	printed:
#
#		<depends_type>	<pattern>	<directory>
#
#	Valid dependency types are "bootstrap", "build" and "full".
#
# ENVIRONMENT
#	AWK
#		Path to the awk interpreter.
#
#	PKGSRCDIR
#		Root directory of the pkgsrc tree.
#
#	SED
#		Path to the sed command.
#
# The following variables are used by the reduce-depends.awk script:
#
#	PKG_ADMIN
#		Path to the pkg_admin command.
#
#	PWD_CMD
#		Path to the pwd command.
#
######################################################################

: ${ECHO:=echo}

set -e

trap "exit 1" USR1

reduce_depends() {
	${AWK} -f ${PKGSRCDIR}/mk/pkgformat/pkg/reduce-depends.awk "$1" \
	|| kill -USR1 $$
}

print_entries() {
	reduce_depends "$2" | while read dep; do
		pattern=`${ECHO} "$dep" | ${SED} -e "s,:.*,,"`
		dir=`${ECHO} "$dep" | ${SED} -e "s,.*:,,"`
		[ "$pattern" ]
		[ "$dir" ]
		${ECHO} "$1	$pattern	$dir"
	done
}

if [ $# != 5 ]; then
	echo "usage: list-dependencies bootstrap_depends test_depends tool_depends build_depends depends" 1>&2
	exit 1
fi

print_entries bootstrap "$1"
print_entries test "$2"
print_entries tool "$3"
print_entries build "$4"
print_entries full "$5"
