X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=tools%2Focamlmoduledep.sh;h=2833671766cf2acf15d797991580a034fbda57e7;hp=3102e1ecc147db0f9758ab236fe4dcc7db659582;hb=d7019c01a47613e258fccb127e6085cb91d26546;hpb=f7a43114461b09d79c94a0da51ffbe1aea43dc55 diff --git a/tools/ocamlmoduledep.sh b/tools/ocamlmoduledep.sh index 3102e1e..2833671 100755 --- a/tools/ocamlmoduledep.sh +++ b/tools/ocamlmoduledep.sh @@ -4,30 +4,30 @@ PROG="$0" CMDLINE="$*" usage() { - echo "$PROG [-native] [-I dir .. -I dir] Module" + echo "$PROG [-inter] [-native] [-I dir .. -I dir] Module" } INCLUDES="" -MODULE="" +MODULES="" NATIVE=0 +INTER=0 +OCAMLWHERE=$(ocamlc -where) while true; do case $1 in -I) - dir=`echo "$2" | sed "s:^+:$(ocamlc -where)/:"` + dir=`echo "$2" | sed "s:^+:${OCAMLWHERE}/:"` INCLUDES="$INCLUDES -$2" +$dir" shift ;; -native) NATIVE=1 ;; + -inter) + INTER=1 + ;; [A-Z]*) - if test -z "$MODULE"; then - MODULE=$1 - else - usage - exit 1 - fi + MODULES="$MODULES $1" ;; *) echo "ERROR: '$1'" @@ -38,20 +38,31 @@ $2" 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 + +for MODULE in $MODULES; do + module="$(echo ${MODULE} | sed -e 's:\(.*\):\l\1:')" + echo "$INCLUDES" | while read include; do + if test -z "$include"; then continue; fi + base="${include}/${module}" + if test \( "$INTER" = "1" \) -a \( -f "$base".mli \) ; then + ## if we want to depend only on cmi of a module + /bin/echo -n "${base}"."cmi " + elif test -f "$base".ml -o -f "$base".mly -o -f "$base".mll -o -f "$base".pack -o -f "$base".ml.str; then + ## else we depend on the implementation + /bin/echo -n "${base}"."${ext} " + break + elif test -f "${base}".mli; then + ## and fall back on depending on the cmi if the cmx is not available + ## (which prevents cross-module inlining in the case of cmx) + /bin/echo -n "${base}"."cmi " + break + fi + done done +echo