-#!/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