1
0
Fork 0
mirror of https://github.com/pygos/build.git synced 2024-11-16 16:37:10 +01:00
build/util/depends.sh
David Oberhollenzer dbbb1889f4 Initial commit
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
2018-01-29 10:17:30 +01:00

40 lines
930 B
Bash
Executable file

dependencies_recursive() {
local NAME="$1"
local PKGDIR="$2"
if [ -e "$SCRIPTDIR/$PKGDIR/$NAME/depends" ]; then
while read DEP; do
echo "$NAME $DEP"
done < "$SCRIPTDIR/$PKGDIR/$NAME/depends"
while read DEP; do
dependencies_recursive "$DEP" "$PKGDIR"
done < "$SCRIPTDIR/$PKGDIR/$NAME/depends"
fi
}
dependencies() {
local RAW="$1"
local PKGLIST="$2"
local PKGDIR="$3"
local TEMP=$(mktemp)
truncate -s 0 "$PKGLIST"
# handle toplevel packages _with_ depenendencies
while read pkgname; do
dependencies_recursive "$pkgname" "$PKGDIR" >> "$TEMP"
done < "$RAW"
# handle toplevel packages without dependencies
while read pkgname; do
if [ ! -e "$SCRIPTDIR/$PKGDIR/$pkgname/depends" ]; then
grep -q "$pkgname" "$TEMP" &> /dev/null || \
echo "$pkgname" >> "$PKGLIST"
fi
done < "$RAW"
# generate topologically sorted list of packages
sort -u "$TEMP" | tsort | tac >> "$PKGLIST"
rm "$TEMP"
}