<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14"> <TITLE> Dependency generator (ocamldep) </TITLE> </HEAD> <BODY TEXT=black BGCOLOR=white> <A HREF="manual026.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual028.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> <HR> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#2de52d"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc138"><B><FONT SIZE=6>Chapter 13</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=6>Dependency generator (ocamldep)</FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="c:camldep"></A> <BR> The <TT>ocamldep</TT> command scans a set of Objective Caml source files (<TT>.ml</TT> and <TT>.mli</TT> files) for references to external compilation units, and outputs dependency lines in a format suitable for the <TT>make</TT> utility. This ensures that <TT>make</TT> will compile the source files in the correct order, and recompile those files that need to when a source file is modified.<BR> <BR> The typical usage is: <PRE> ocamldep <I>options</I> *.mli *.ml > .depend </PRE> where <TT>*.mli *.ml</TT> expands to all source files in the current directory and <TT>.depend</TT> is the file that should contain the dependencies. (See below for a typical <TT>Makefile</TT>.)<BR> <BR> Dependencies are generated both for compiling with the bytecode compiler <TT>ocamlc</TT> and with the native-code compiler <TT>ocamlopt</TT>.<BR> <BR> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc139"><B><FONT SIZE=5>13.1</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>Options</FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE><BR> The following command-line option is recognized by <TT>ocamldep</TT>. <DL COMPACT=compact><DT><B><TT>-I</TT> <I>directory</I></B><DD> Add the given directory to the list of directories searched for source files. If a source file <TT>foo.ml</TT> mentions an external compilation unit <TT>Bar</TT>, a dependency on that unit's interface <TT>bar.cmi</TT> is generated only if the source for <TT>bar</TT> is found in the current directory or in one of the directories specified with <TT>-I</TT>. Otherwise, <TT>Bar</TT> is assumed to be a module from the standard library, and no dependencies are generated. For programs that span multiple directories, it is recommended to pass <TT>ocamldep</TT> the same <TT>-I</TT> options that are passed to the compiler.<BR> <BR> <DT><B><TT>-native</TT></B><DD> Generate dependencies for a pure native-code program (no bytecode version). When an implementation file (<TT>.ml</TT> file) has no explicit interface file (<TT>.mli</TT> file), <TT>ocamldep</TT> generates dependencies on the bytecode compiled file (<TT>.cmo</TT> file) to reflect interface changes. This can cause unnecessary bytecode recompilations for programs that are compiled to native-code only. The flag <TT>-native</TT> causes dependencies on native compiled files (<TT>.cmx</TT>) to be generated instead of on <TT>.cmo</TT> files. (This flag makes no difference if all source files have explicit <TT>.mli</TT> interface files.)</DL> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66ff66"><DIV ALIGN=center><TABLE> <TR><TD><A NAME="htoc140"><B><FONT SIZE=5>13.2</FONT></B></A></TD> <TD WIDTH="100%" ALIGN=center><B><FONT SIZE=5>A typical Makefile</FONT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE><BR> Here is a template <TT>Makefile</TT> for a Objective Caml program. <PRE> OCAMLC=ocamlc OCAMLOPT=ocamlopt OCAMLDEP=ocamldep INCLUDES= # all relevant -I options here OCAMLFLAGS=$(INCLUDES) # add other options for ocamlc here OCAMLOPTFLAGS=$(INCLUDES) # add other options for ocamlopt here # prog1 should be compiled to bytecode, and is composed of three # units: mod1, mod2 and mod3. # The list of object files for prog1 PROG1_OBJS=mod1.cmo mod2.cmo mod3.cmo prog1: $(PROG1_OBJS) $(OCAMLC) -o prog1 $(OCAMLFLAGS) $(PROG1_OBJS) # prog2 should be compiled to native-code, and is composed of two # units: mod4 and mod5. # The list of object files for prog2 PROG2_OBJS=mod4.cmx mod5.cmx prog2: $(PROG2_OBJS) $(OCAMLOPT) -o prog2 $(OCAMLFLAGS) $(PROG2_OBJS) # Common rules .SUFFIXES: .ml .mli .cmo .cmi .cmx .ml.cmo: $(OCAMLC) $(OCAMLFLAGS) -c $< .mli.cmi: $(OCAMLC) $(OCAMLFLAGS) -c $< .ml.cmx: $(OCAMLOPT) $(OCAMLOPTFLAGS) -c $< # Clean up clean: rm -f prog1 prog2 rm -f *.cm[iox] # Dependencies depend: $(OCAMLDEP) $(INCLUDES) *.mli *.ml > .depend include .depend </PRE> <HR> <A HREF="manual026.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual028.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> </BODY> </HTML>