1 # Works with rslide revision 8
2 # http://gallium.inria.fr/~pouillar/rslide/rslide
3 documentclass :beamer, :t, :compress, :red
4 usepackage :inputenc, :utf8
6 words "**OCaml**", "**ocamlbuild**", "_Makefile_"
8 title "ocamlbuild, a tool for automatic compilation of OCaml projects"
9 authors "Berke Durak", "Nicolas Pouillard"
11 > @@Berke.Durak@inria.fr@@
13 > @@Nicolas.Pouillard@inria.fr@@
18 beamer_header '\setbeamercolor*{titlelike}{parent=structure}'
21 tableofcontents 'sectionstyle=show/shaded',
22 'subsectionstyle=show/shaded/hide'
29 latex_only.small.code_inline(*a, &b)
30 html_only.code(*a, &b)
33 latex_only.small.code_inline(*a, &b)
34 html_only.code(*a, &b)
39 paragraph.huge1 "Warning: this presentation has a degraded style compared to the Beamer/PDF version"
46 slide "Why such a tool?", '<+->' do
47 * To make our OCaml life easier
48 * To stop writing poor MakefileS
49 * To have a tool that Just works™
52 slide "What does ocamlbuild handle?", '<+->' do
54 box "Regular OCaml projects of arbitrary size" do
55 > Trivially handled using the command line options.
58 box "Mostly regular OCaml projects with common exceptions" do
59 > Requires writing one tag file (__tags_) that declares those exceptions.
62 box "Almost any project" do
63 > Accomplished by writing an ocamlbuild plugin.
68 slide "What does ocamlbuild provide?" do
71 * Automated whole-project compilation
72 * Minimal recompilation
73 * Lots of useful targets (doc, debugging, profiling...)
74 * Supports multiple build directories
75 * Automatic and safe cleaning
76 * A source directory uncluttered by object files
77 * A portable tool shipped with OCaml
80 * Saves time and money!
85 h1 "Regular OCaml projects"
87 slide "What's a regular OCaml project?" do
88 box "It's a project that needs no exceptions from the standard rules:" do
89 * Has compilation units (_ml_ and _mli_ files)
90 * May have parsers and lexers (_mly_ and _mll_ files)
91 * May use packages, libraries and toplevels (_ml{pack,lib,top}_)
92 * May link with external libraries
93 * Has one main OCaml unit from which these units are reachable
97 slide "How difficult is it to build regular projects by hand?" do
98 box "OCaml has subtle compilation rules" do
99 * Interfaces (_.mli_) can be absent, yet buildable (_.mly_)
100 * Native and bytecode suffixes and settings differ
101 * Native packages are difficult to do (_-for-pack_)
102 * Linkage order must be correctly computed
103 * Include directories must be ordered
104 * _ocamldep_ gives partial information (too conservative)
108 slide "How does ocamlbuild manage all that?" do
109 > It has a lot of hand-crafted Ocaml-specific compilation logic!
110 box "A dynamic exploration approach", '<2>' do
111 * Start from the given targets
112 * Attempt to discover dependencies using _ocamldep_
113 * _ocamldep_ cannot always be trusted: backtrack if necessary
114 * Launch compilations and discover more dependencies
119 box "Many projects can be compiled with a single command:" do
120 * Menhir: _ocamlbuild -lib unix back.native_
121 * Hevea: _ocamlbuild latexmain.native_
122 * Ergo: _ocamlbuild main.native_
123 * Ocamlgraph: _ocamlbuild -cflags -for-pack,Ocamlgraph demo.native_
126 box "To be fair..." do
127 > Some of these projects require that a _version.ml_
128 or _stdlib.ml_ file be generated beforehand.
132 h1 "Dealing with exceptions to standard rules"
134 slide "What's an exception?" do
135 box "Files that need specific flags" do
136 * Warnings to be enabled or disabled
137 * Debugging (_-g_), profiling (_-p_), type annotation,
138 recursive types, _-linkall_, _-thread_, _-custom_...
141 * Units that need external C libraries
142 * Binaries that need external OCaml libraries
143 * Directories that must be included or excluded
144 * Dependencies that cannot be discovered
148 slide "_Make_ and exceptions" do
149 * The _make_ tool can't handle exceptions very well
150 * Needs exceptions to be encoded as specific rules
151 * This generally makes rules and exceptions tightly bound by variables
152 * This creates non-modular makefiles that don't *scale*
155 slide "The tags, our way to specify exceptions", 'fragile=singleslide' do
157 * The _tags file is made of lines
158 * Each line is made of a pattern and a list of signed tags
159 * A line adds or removes tags from matching files
160 * Patterns are boolean combinations of shell-like globbing expressions
163 : "funny.ml": rectypes
164 ~<**/*.ml*>~: warn_A, warn_error_A, debug, dtypes
165 ~<**/*.cmx>~: inline(9)
166 "foo.ml" or "bar.ml": warn_v, warn_error_v
167 "vendor.ml": -warn_A, -warn_error_A
168 <main.{byte,native}>: use_unix
169 "main.byte": use_dynlink, linkall
171 <satsolver.cm[io]>: precious
175 slide "How tags and rules give commands", 'fragile=singleslide' do
176 box "Files are tagged using tagging rules" do
178 : "foo/bar.ml": rectypes
181 box "Rules then produce commands with *tagged holes*" do
184 tags_for(ml)++"ocaml"++"compile"++"byte" in
185 Cmd(S[A"ocamlc";A"-c";T tagged_hole;P ml;A"-o";P cmo])
188 box "These holes are filled by command fragments (such as flags)" do
190 : flag ["ocaml"; "compile"; "byte"; "rectypes"]
196 slide "Tags and dependencies", 'fragile=singleslide' do
197 box "One can define dependencies triggered by combinations of tags" do
199 : dep ["ocaml"; "link"; "byte"; "program"; "plugin:foo"]
200 ["plugin/pluginlib.cma"; "plugin/plugin_foo.cmo"]
203 box "By tagging files we make things happen" do
205 : "test.byte": plugin:foo
210 h1 "Writing an ocamlbuild plugin"
212 slide "Not a specific language, but plain OCaml code" do
214 * Plugins are compiled on the fly
215 * Dynamic configuration is feasible
217 box "With a plugin one can:" do
218 * Extend rules (add new ones, override old ones)
219 * Add flags and dependencies based on tags
222 * Define the directory structure precisely
224 * Specify external libraries
228 slide "A plugin example" do
229 > Let's read it in live...
232 # slide "ocamlbuild scales" do
233 # > Indeed ocamlbuild is used as an experimental replacement in OCaml itself.
236 h1 "General features"
238 slide "Parallel execution where applicable" do
239 * You select the maximum number of jobs (_-j N_)
240 * Rules know how to ask for parallel targets
241 * The system keeps things scheduled correctly
242 * Example: Separate compilation of byte code
243 * (Optimal scheduling would require a static graph)
246 slide "A status bar for your visual comfort" do
248 * Compilation tools echo commands and their output
249 * This creates a long and boring output that scrolls too fast
250 * Here you can keep an eye on what is going on!
251 * It succinctly displays time, number of targets, and tags
252 * Command outputs are correctly multiplexed
253 * A trace of the commands executed is kept in a log file
254 * This log file can be used as the basis of a shell script
256 latex_only.example do
260 File.read("manual/trace.out").each do |line|
262 next if count % mod != 0
263 line.gsub!("\\", "|")
265 line.gsub!(/( +)/) { "\\hspace{#{0.49 * $1.size}em}" }
267 s = "\\only<#{count / mod}>{\\tt #{line}}%\n"
274 slide "Hygiene and sterilization" do
275 > ocamlbuild has a Hygiene Squad (HS) that checks your source tree for cleanliness
276 box "It has preconceived but useful cleanliness notions", '<1->' do
277 * Files dirty by default: _.cmi_, _.cmo_, _.cma_, _.cmx_...
278 * _ocamllex_/_ocamlyacc_ files: _.ml_ *if* _.mll_, _.ml_&_.mli_ *if* _.mly_...
280 box "If unsatisfied, the HS produces a sterilization script", '<2->' do
281 * Read it carefully (or work with versioning)
282 * Run at your own risks
284 box "HS can be told of exceptions", '<3->' do
285 > Files or directories tagged as __not_hygienic__ or _precious_.
289 slide "Some supported tools" do
290 box "_Menhir_ as an _ocamlyacc_ replacement", '<1->' do
291 * Enabled with the __use_menhir__ global tag or the __-use-menhir__ option
292 * Handles implicit dependencies using _--infer_
294 box "_Ocamldoc_ to build your doc", '<2->' do
295 * Separated construction using (_-dump_/_-load_)
296 * Handles ??HTML??, ??LaTeX??, ??Man??, ??Dot??, ??TeXi??
298 # box "_ocamlmklib_, _ocamlmktop_" do
299 # > Basic support using _.mllib_ and _.mltop_ files
301 box "_Camlp4_ aware", '<3->' do
302 * Tags allow to setup any installed _Camlp4_ preprocessor
303 * Fine grained dependencies help a lot...
310 box "ocamlbuild can be used in three ways:", '<1->' do
311 * With only command-line options for fully regular projects
312 * With the __tags_ file for intermediate projects
313 * With a plugin for the most complex projects
315 box "ocamlbuild saves your time by:", '<2->' do
316 * Building your project gently
317 * Compiling only as necessary
318 * Running commands in parallel
319 * Keeping your house clean
320 * Letting you concentrate on your code!
324 slide "Acknowledgments" do
325 box "For enlightening discussions about OCaml internals:", '<1->' do
329 box "For his insights about OCaml dependencies:", '<2->' do
332 box "For letting this happen:", '<3->' do
337 slide "Conclusion", '<+->' do
338 * ocamlbuild is not perfect but already damn useful
339 * Try it now! It's in OCaml 3.10!