Merge commit 'ocaml3102'
[ocaml.git] / ocamlbuild / FAQ
blobb71516b9e3f14eb690f8244790222635d1cf8157
1 Q: I've a directory with examples and I want build all of them easily?
3 R:
5   You can use an .itarget file listing all products that you want.
7   $ cat examples.itarget
8   examples/a.byte
9   examples/b.byte
11   $ ocamlbuild examples.otarget
13   You can also have a dynamic rule that read the examples directory:
15   $ cat myocamlbuild.ml
16   open Ocamlbuild_plugin;;
18   dispatch begin function
19     | After_rules ->
20         let examples =
21           Array.fold_right begin fun f acc ->
22             if Pathname.get_extension f = "ml" then
23               ("examples" / Pathname.update_extension "byte" f) :: acc
24             else
25               acc
26           end (Pathname.readdir "examples") []
27         in
28         rule "All examples"
29           ~prod:"examples.otarget"
30           ~deps:examples
31           (fun _ _ -> Command.Nop)
32     | _ -> ()
33   end
35   $ ocamlbuild examples.otarget