Michal Suchanek 9e6ccd
#!/bin/sh
Michal Suchanek 9e6ccd
Michal Suchanek 9e6ccd
dependencies=$1
Michal Suchanek 9e6ccd
modules=$2
Michal Suchanek 9e6ccd
result=$3
Michal Suchanek 9e6ccd
Michal Suchanek 9e6ccd
cat $modules | tr ' ' '\n' > $result
Michal Suchanek 9e6ccd
echo > $result~
Michal Suchanek 9e6ccd
Michal Suchanek 9e6ccd
while ! diff -q $result~ $result > /dev/null ; do
Michal Suchanek 9e6ccd
	cp $result $result~
Michal Suchanek 9e6ccd
	while read MOD ; do
Michal Suchanek 9e6ccd
		moddeps="$(grep ^$MOD: $dependencies | sed -e 's/.*://' ||:)"
Michal Suchanek 9e6ccd
		for DEP in $moddeps ; do
Michal Suchanek 9e6ccd
			if ! grep -q ^$DEP\$ $result ; then
Michal Suchanek 9e6ccd
				echo $DEP >> $result
Michal Suchanek 9e6ccd
				echo $MOD: $DEP
Michal Suchanek 9e6ccd
			fi
Michal Suchanek 9e6ccd
		done
Michal Suchanek 9e6ccd
	done < $result
Michal Suchanek 9e6ccd
done