--- /dev/null
+#!/bin/sh
+
+EXT="$1"
+if [ -z "$EXT" ]
+then
+ EXT="cmx"
+fi
+
+TARGET="$2"
+
+DEPS=$(
+while read target deps
+do
+ target="${target%.ml:}.$EXT"
+ dir=$(dirname "$target")
+ echo -n "$target":" "
+ for d in $deps
+ do
+ base=$(echo "$d" | sed 's/\(.*\)/\l\1/g' )
+ if [ -f "$dir"/"$base".ml -o -d "$dir"/"$base" ]
+ then
+ echo -n "$dir"/"$base"".$EXT "
+ fi
+ done
+ echo
+done)
+
+SORTED=""
+while true
+do
+ ROOT=$(echo "$DEPS" | grep '^[^ ]*.'$EXT': *$' | cut -f 1 -d: )
+ NDEPS=$(echo "$DEPS" | grep -v '^[^ ]*.'$EXT': *$')
+ if [ "$DEPS" = "$NDEPS" ]
+ then
+ SORTED="$SORTED $(echo $DEPS | cut -f 2 -d :)"
+ SORTED="$SORTED $(echo $DEPS | cut -f 1 -d :)"
+ break
+ fi
+ SORTED="$SORTED $ROOT"
+ for r in $ROOT
+ do
+ DEPS=$(echo "$DEPS" | sed "s|$r:\?||g")
+ done
+done
+for i in $SORTED
+do
+echo -n "$i "
+done
+echo