2833671766cf2acf15d797991580a034fbda57e7
[tatoo.git] / tools / ocamlmoduledep.sh
1 #!/bin/sh
2
3
4 PROG="$0"
5 CMDLINE="$*"
6 usage() {
7     echo "$PROG [-inter] [-native] [-I dir .. -I dir] Module"
8 }
9
10 INCLUDES=""
11 MODULES=""
12 NATIVE=0
13 INTER=0
14 OCAMLWHERE=$(ocamlc -where)
15 while true; do
16     case $1 in
17         -I)
18             dir=`echo "$2" | sed "s:^+:${OCAMLWHERE}/:"`
19             INCLUDES="$INCLUDES
20 $dir"
21             shift
22             ;;
23         -native)
24             NATIVE=1
25             ;;
26         -inter)
27             INTER=1
28             ;;
29         [A-Z]*)
30                 MODULES="$MODULES $1"
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 if test "$NATIVE" = "1"; then
42     ext=cmx
43 else
44     ext=cmo
45 fi
46
47
48 for MODULE in $MODULES; do
49     module="$(echo ${MODULE} | sed -e 's:\(.*\):\l\1:')"
50     echo "$INCLUDES" | while read include; do
51         if test -z "$include"; then continue; fi
52         base="${include}/${module}"
53         if test  \( "$INTER" = "1" \) -a \( -f "$base".mli \) ; then
54             ## if we want to depend only on cmi of a module
55             /bin/echo -n  "${base}"."cmi "
56         elif test -f "$base".ml -o -f "$base".mly -o -f "$base".mll -o -f "$base".pack -o -f "$base".ml.str; then
57             ## else we depend on the implementation 
58             /bin/echo -n  "${base}"."${ext} "
59             break
60         elif test -f "${base}".mli; then
61             ## and fall back on depending on the cmi if the cmx is not available
62             ## (which prevents cross-module inlining in the case of cmx)
63             /bin/echo -n  "${base}"."cmi "
64             break
65         fi
66     done
67 done
68 echo