X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=tools%2Fodeps.sh;fp=tools%2Fodeps.sh;h=2443c21d390e83f2b9869c0d3cf1fbe0465b8c63;hp=0000000000000000000000000000000000000000;hb=8af68de11421dacc2f77a8398dcb48c75a5ff3b1;hpb=9efb3171eb9f70c92d7814a56684ef5f1eedf004 diff --git a/tools/odeps.sh b/tools/odeps.sh new file mode 100755 index 0000000..2443c21 --- /dev/null +++ b/tools/odeps.sh @@ -0,0 +1,87 @@ +#!/bin/sh +#Save the parameters + +PROG="$0" +CMDLINE="$*" +usage() { + echo "$PROG [ocamldep ... ]" +} + +OPTIONS="" +INCLUDES="" +ARGS="" +NATIVE=0 +while true; do + case $1 in + -ppopt) + OPTIONS="$OPTIONS $1 $2" + shift + ;; + -I) + OPTIONS="$OPTIONS $1 $2" + INCLUDES="$INCLUDES $2" + shift + ;; + -native) + NATIVE=1 + OPTIONS="$OPTIONS $1" + ;; + *.ml*) + ARGS="$ARGS $1" + ;; + *) + OPTIONS="$OPTIONS $1" + ;; + esac + if test "$#" -eq 0; then break; else shift; fi +done + +if test "$NATIVE" -eq 1; then + OEXT="cmx" +else + OEXT="cmo" +fi +IEXT="cmi" + +for src in $ARGS; do + $OPTIONS -modules "$src" | while read file deps; do + if test -z "$file"; then continue; fi + file=${file%:} + if test "$file" != "${file%.mli}"; then + ext="$IEXT" + base="${file%.mli}" + src_ext="mli" + else + ext="$OEXT" + base="${file%.ml}" + src_ext="ml" + fi + dependencies="" + for dep in $deps; do + modbase=$(echo $dep | sed 's/\(.*\)/\l\1/') + for dir in $INCLUDES; do + dir=${dir%/} #remove trailing slash, if any + #Interfaces or bytecode objects depends on other compile interfaces + #if they exists, otherwise they depend on the object + if test \( "$ext" = "cmi" -o "$ext" = "cmo" \) -a -f "$dir"/"$modbase".mli ; then + dependencies="$dependencies $dir/$modbase".cmi + break + elif test -f "$dir"/"$modbase".ml -o -f "$dir"/"$modbase".mly -o -f "$dir"/"$modbase".mll -o -d "$dir"/"$modbase"; then + dependencies="$dependencies $dir/$modbase"."$ext" + break + fi + done + done + #finally add the cmi as dependency of the cmo/cmx, + #if the .mli exists + if test "$ext" != "cmi" -a -f "$base".mli ; then + dependencies=" ${base}.cmi${dependencies}" + fi + #output a phony dependency between the cmi and the cmx/cmo if there is no .mli + if test "$ext" != "cmi" -a ! -f "$base".mli; then + echo "${base}.cmi: ${base}.${ext}" + fi + echo "${base}.${ext}:${dependencies}" + done + +done