Add more tests (broken, needs a refactoring of the build script)
[tatoo.git] / tools / ocamlmoduledep.sh
diff --git a/tools/ocamlmoduledep.sh b/tools/ocamlmoduledep.sh
new file mode 100755 (executable)
index 0000000..3102e1e
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+
+PROG="$0"
+CMDLINE="$*"
+usage() {
+    echo "$PROG [-native] [-I dir .. -I dir] Module"
+}
+
+INCLUDES=""
+MODULE=""
+NATIVE=0
+while true; do
+    case $1 in
+        -I)
+            dir=`echo "$2" | sed "s:^+:$(ocamlc -where)/:"`
+            INCLUDES="$INCLUDES
+$2"
+            shift
+            ;;
+        -native)
+            NATIVE=1
+            ;;
+        [A-Z]*)
+            if test -z "$MODULE"; then
+                MODULE=$1
+            else
+                usage
+                exit 1
+            fi
+            ;;
+        *)
+            echo "ERROR: '$1'"
+            usage
+            exit 2
+            ;;
+    esac
+    shift
+    if test "$#" -eq 0; then break; fi
+done
+module="$(echo $MODULE | cut -b1 | tr A-Z a-z)$(echo $MODULE | cut -b2-)"
+if test "$NATIVE" = "1"; then
+    ext=cmx
+else
+    ext=cmo
+fi
+
+echo "$INCLUDES" | while read include; do
+    base="$include/$module"
+    if test -f "$base".ml -o -f "$base".mly -o -f "$base".mll -o -d "$base"; then
+        echo "$base"."$ext"
+        break
+    elif test -f "$base".mli; then
+        echo "$base".cmi
+        break
+    fi
+done