3102e1ecc147db0f9758ab236fe4dcc7db659582
[tatoo.git] / tools / ocamlmoduledep.sh
1 #!/bin/sh
2
3
4 PROG="$0"
5 CMDLINE="$*"
6 usage() {
7     echo "$PROG [-native] [-I dir .. -I dir] Module"
8 }
9
10 INCLUDES=""
11 MODULE=""
12 NATIVE=0
13 while true; do
14     case $1 in
15         -I)
16             dir=`echo "$2" | sed "s:^+:$(ocamlc -where)/:"`
17             INCLUDES="$INCLUDES
18 $2"
19             shift
20             ;;
21         -native)
22             NATIVE=1
23             ;;
24         [A-Z]*)
25             if test -z "$MODULE"; then
26                 MODULE=$1
27             else
28                 usage
29                 exit 1
30             fi
31             ;;
32         *)
33             echo "ERROR: '$1'"
34             usage
35             exit 2
36             ;;
37     esac
38     shift
39     if test "$#" -eq 0; then break; fi
40 done
41 module="$(echo $MODULE | cut -b1 | tr A-Z a-z)$(echo $MODULE | cut -b2-)"
42 if test "$NATIVE" = "1"; then
43     ext=cmx
44 else
45     ext=cmo
46 fi
47
48 echo "$INCLUDES" | while read include; do
49     base="$include/$module"
50     if test -f "$base".ml -o -f "$base".mly -o -f "$base".mll -o -d "$base"; then
51         echo "$base"."$ext"
52         break
53     elif test -f "$base".mli; then
54         echo "$base".cmi
55         break
56     fi
57 done