| 1 | #!/bin/bash |
| 2 | |
| 3 | getDeps() { |
| 4 | local pkg="$1" |
| 5 | local deps="$(grep "^# Depends on:" $pkg/Pkgfile 2>/dev/null| cut -d':' -f2-)" |
| 6 | echo "${deps# *}" |
| 7 | } |
| 8 | |
| 9 | getRecursiveDeps() { |
| 10 | local pkg="$1" |
| 11 | local deps="$(getDeps $pkg)" |
| 12 | if [ -z "$deps" ]; then |
| 13 | case $pkg in |
| 14 | # toolchain ports must be in order |
| 15 | libgmp|libmpfr|libmpc|binutils|glibc|zlib|gcc) |
| 16 | ;; |
| 17 | *) |
| 18 | if [ ! "$(echo $BUILD_ORDER | grep " ${pkg}")" ]; then |
| 19 | BUILD_ORDER="$BUILD_ORDER $pkg" |
| 20 | fi |
| 21 | ;; |
| 22 | esac |
| 23 | else |
| 24 | for d in ${deps[@]}; do |
| 25 | getRecursiveDeps "$d" |
| 26 | done |
| 27 | |
| 28 | if [ ! "$(echo $BUILD_ORDER | grep " ${pkg}")" ]; then |
| 29 | BUILD_ORDER="$BUILD_ORDER $pkg" |
| 30 | fi |
| 31 | fi |
| 32 | } |
| 33 | |
| 34 | ALT_START=0 |
| 35 | |
| 36 | # check for passed arguments |
| 37 | if [ $# -ne 0 ]; then |
| 38 | # use package as starting point |
| 39 | ALT_START=1 |
| 40 | START_PKG=$1 |
| 41 | BUILD_ORDER="" |
| 42 | else |
| 43 | # global var to store all final deps order |
| 44 | BUILD_ORDER="libgmp libmpfr libmpc binutils glibc zlib gcc" |
| 45 | fi |
| 46 | |
| 47 | for i in $(find . -type f -name 'Pkgfile' -exec dirname {} \; | sort); do |
| 48 | PKG="$(basename $i)" |
| 49 | case $PKG in |
| 50 | # toolchain ports must be in order |
| 51 | libgmp|libmpfr|libmpc|binutils|glibc|zlib|gcc) continue ;; |
| 52 | esac |
| 53 | getRecursiveDeps "$PKG" |
| 54 | done |
| 55 | |
| 56 | if [ $ALT_START -eq 0 ]; then |
| 57 | echo $BUILD_ORDER | tr ' ' '\n' |
| 58 | else |
| 59 | echo $BUILD_ORDER | sed "s|.* $START_PKG|$START_PKG|" | tr ' ' '\n' |
| 60 | fi |
| 61 | |
| 62 | # End fo file |