#!/bin/bash getDeps() { local pkg="$1" local deps="$(grep "^# Depends on:" $pkg/Pkgfile 2>/dev/null| cut -d':' -f2-)" echo "${deps# *}" } getRecursiveDeps() { local pkg="$1" local deps="$(getDeps $pkg)" if [ -z "$deps" ]; then case $pkg in # toolchain ports must be in order libgmp|libmpfr|libmpc|binutils|glibc|zlib|gcc) ;; *) if [ ! "$(echo $BUILD_ORDER | grep " ${pkg}")" ]; then BUILD_ORDER="$BUILD_ORDER $pkg" fi ;; esac else for d in ${deps[@]}; do getRecursiveDeps "$d" done if [ ! "$(echo $BUILD_ORDER | grep " ${pkg}")" ]; then BUILD_ORDER="$BUILD_ORDER $pkg" fi fi } # global var to store all final deps order BUILD_ORDER="libgmp libmpfr libmpc binutils glibc zlib gcc" for i in $(find . -type f -name 'Pkgfile' -exec dirname {} \;); do PKG="$(basename $i)" case $PKG in # toolchain ports must be in order libgmp|libmpfr|libmpc|binutils|glibc|zlib|gcc) continue ;; esac getRecursiveDeps "$PKG" done echo $BUILD_ORDER | tr ' ' '\n' echo # End fo file