Previous Contents Next

Dependency Analysis

Dependency analysis of a set of implementation and interface files that make up an Objective CAML application pursues a double end. The first is to get a global view of the interdependencies between modules. The second is to use this information in order to recompile only the absolutely necessary files after modifications of certain files.

The ocamldep command takes a set of .ml and .mli files and outputs the dependencies between files in Makefile1 format.

These dependencies originate from global declarations in other modules, either by using dot.notation (e.g. M1.f) or by opening a module (e.g. open M1).

Suppose the following files exist: :

let print_vect v =
for i = 0 to Array.length v do
Printf.printf "%f " v.(i)

and :

let init n e =
let v = Array.create 4 3.14 in
Dp.print_vect v;

Given the name of these files, the ocamldep command will output the following dependencies:
$ ocamldep array.mli printf.mli
dp.cmo: array.cmi printf.cmi 
dp.cmx: array.cmx printf.cmx 
d1.cmo: array.cmi dp.cmo 
d1.cmx: array.cmx dp.cmx 
array.cmo: array.cmi 
array.cmx: array.cmi 
printf.cmo: printf.cmi 
printf.cmx: printf.cmi 
The dependencies are determined for both the bytecode and the native compiler. The output is to be read in the following manner: production of the file dp.cmo depends on the files array.cmi and printf.cmi. Files with the extension .cmi depend on files with the same name and extension .mli. And the same holds by analogy for .ml files with .cmo and .cmx files.

The object files of the distribution do not show up in the dependency lists. In fact, if ocamldep does not find the files and in the current directory, it will find them in the library directory of the installation and produce the following output:
$ ocamldep
d1.cmo: dp.cmo 
d1.cmx: dp.cmx 
To give new file search paths to the ocamldep command, the -I directory option is used, which adds a directory to the list of include directories.

Previous Contents Next