From Building OCaml code that uses list comprehension post, I can use _tags
file to execute ocamlbuild
with less build options.
$ cat _tags
<**/*> : package(camlp4),syntax(camlp4o),package(pa_comprehension)
From the Batteries introduction, I also need to have _tags file to use Batteries package.
<*>: package(batteries)
Why the first example uses <**/*>
when the second example uses <*>
? In general, what's the purpose of _tags file in ocamlbuild? Do you have some good tutorials on it?
A _tags
file in addition to myocamlbuild.ml
forms the root of the ocamlbuild
compilation system.
ocamlbuild
is a very generic tool, that can compile anything. It is driven by a solver, that according to the target, set by a user, finds a solution that can satisfy the target. The solution is a chain of rules that are applied to files. Files can be tagged by tags. Tags can alter rules. For example, it can add flags, like enabling profiling or linking to a library.
A _tags
file provides a mechanism to assign tags to files and it has a simple grammar:
pattern ":" tag "," {tag}.
What is to the left of :
is actually a pattern or regular expression. Each file that matches the expression will be assigned with all tags that occur to the right of :
.
<**/*>
means for all files in this folder, and all subfolders, there is a shortcut for this: true
. <*>
means for all files on this folder (without descending into subfolders). Other examples are <*.ml>
, <*.cmx>
or <**/*.cma>
(btw or
can also be used to build a pattern).
OCamlbuild is documented in OCaml Manual, also there is a dump of old wiki, with lots of information.
But the fun part is that usually you do not need to know this in order to use OCaml. There is an OASIS
tool that will automate all tasks, and create _tags
file for you from a simple and high-level definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With