Plasma GitLab Archive
Projects Blog Knowledge

Defining additional predicates

Additional predicates can be simply used without any declaration, i.e. you can freely invent new predicates. One application of them is to express conditional linkage. For example, one may provide archives for various conditions, such as a production archive, and a development archive. A single new predicate, "development", would be sufficient to express this:

archive(byte) = "p_production.cma"
archive(byte,development) = "p_development.cma"

When linking, include a "-predicates development" argument in the compiler command to select the development archive, otherwise the production archive is taken.

Predicates could also be used to select among several implementations of the same module. Define simply one predicate per implementation, e.g. "p_impl1", "p_impl2", and "p_impl3", and specify the archives for every implementation separately:

archive(byte,p_impl1) = "p_impl1.cma"
archive(byte,p_impl2) = "p_impl2.cma"
archive(byte,p_impl3) = "p_impl3.cma"

In the case that the implementations have different dependencies, simply provide multiple "requires" variables:

requires(p_impl1) = "q"
requires(p_impl2) = "q,r"
requires(p_impl3) = "r,s"

Sometimes, the implementations require different linker options. In this case, define several versions of the "linkopts" variable just like in the "requires" example.

Note that predicates are global identifiers that can be potentially applied to every selected package. In the case that a predicate is only meaningful for a single package, it is common practice to choose the package name as prefix of the predicate name (e.g. "netstring_minimum" is a predicate usually only applied to the "netstring" package).

Predicates could be used to select which features of a library are linked. For example,

archive(byte) = "p_basic.cma"
archive(byte,p_extension) = "p_basic.cma p_ext.cma"
would add the p_ext.cma archive only if the p_extension predicate were set. It is considered as bad practice to select extensions of libraries by predicates. Findlib provides the construct of subpackages for this purpose.
This web site is published by Informatikb├╝ro Gerd Stolpmann
Powered by Caml