+#!/bin/bash
+
+getDeps() {
+ local pkg="$1"
+ local deps="$(grep "^# Depends on:" $pkg/Pkgfile | cut -d':' -f2-)"
+ echo "${deps# *}"
+}
+
+getRecursiveDeps() {
+ local pkg="$1"
+ local deps="$(getDeps $pkg)"
+ if [ -z "$deps" ]; then
+ case $pkg in
+ libgmp|libmpfr|binutils|glibc|gcc)
+ # discard these ports
+ ;;
+ *)
+ if [ ! "$(echo $BUILD_ORDER | grep " ${pkg}")" ]; then
+ BUILD_ORDER="$BUILD_ORDER $pkg"
+ fi
+ ;;
+ esac
+ else
+ for d in ${deps[@]}; do
+ getRecursiveDeps "$d"
+ done
+ BUILD_ORDER="$BUILD_ORDER $pkg"
+ fi
+}
+
+# global var to store all final deps order
+BUILD_ORDER="libgmp libmpfr binutils glibc gcc"
+
+for f in *; do
+ [ ! -d "$f" ] && continue
+ case $f in
+ libgmp|libmpfr|binutils|glibc|gcc) continue ;;
+ esac
+ getRecursiveDeps "$f"
+done
+
+echo $BUILD_ORDER
+echo
+
+# End fo file