1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
<!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.08">
<LINK rel="stylesheet" type="text/css" href="manual.css">
<TITLE>
Dependency generator (ocamldep)
</TITLE>
</HEAD>
<BODY >
<A HREF="manual026.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="manual028.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<H1 CLASS="chapter"><A NAME="htoc146">Chapter 13</A> Dependency generator (ocamldep)</H1> <A NAME="c:camldep"></A>
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>
<H2 CLASS="section"><A NAME="htoc147">13.1</A> Options</H2>
The following command-line option is recognized by <TT>ocamldep</TT>.
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description"><B><TT>-I</TT> <I>directory</I></B><DD CLASS="dd-description">
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 CLASS="dt-description"><TT><B>-native</B></TT><DD CLASS="dd-description">
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.)<BR>
<BR>
<DT CLASS="dt-description" style="background-color:yellow; color:red"><TT><B>-version</B></TT><DD CLASS="dd-description" style="background-color:yellow; color:red">
Print version and exit.</DL>
<H2 CLASS="section"><A NAME="htoc148">13.2</A> A typical Makefile</H2>
Here is a template <TT>Makefile</TT> for a Objective Caml program.
<PRE CLASS="verbatim">
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="Up"></A>
<A HREF="manual028.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
|