Update the output of the reference implementation to the new format.
[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 MODULES=""
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                 MODULES="$MODULES $1"
26             ;;
27         *)
28             echo "ERROR: '$1'"
29             usage
30             exit 2
31             ;;
32     esac
33     shift
34     if test "$#" -eq 0; then break; fi
35 done
36 if test "$NATIVE" = "1"; then
37     ext=cmx
38 else
39     ext=cmo
40 fi
41
42 for MODULE in $MODULES; do
43     module="$(echo $MODULE | cut -b1 | tr A-Z a-z)$(echo $MODULE | cut -b2-)"
44     echo "$INCLUDES" | while read include; do
45         base="$include/$module"
46         if test -z "$include"; then continue; fi
47         if test -f "$base".ml -o -f "$base".mly -o -f "$base".mll -o -f "$base".pack; then
48             echo -n "$base"."$ext "
49             break
50         elif test -f "$base".mli; then
51             echo -n "$base"."cmi "
52             break
53         fi
54     done
55 done
56 echo