OCaml package guidelines

Arch package guidelines

32-bitCLRCMakeCrossDKMSEclipseElectronFontFree PascalGNOMEGoHaskellJavaKDEKernelLispMesonMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyRustShellVCSWebWine

Writing PKGBUILDs for software written in OCaml.

Package naming

For libraries, use ocaml-modulename. For applications, use the program name. In either case, the name should be entirely lowercase.

File placement


OCaml libraries should be installed under /usr/lib/ocaml. Installation in /usr/lib/ocaml/site-lib is deprecated.

OCaml libraries should be installed using ocaml-findlib. ocaml-findlib includes library metadata in the package that makes it easy to manage libraries. It is a de-facto standard and a lot of OCaml software now requires it.

ocaml-findlib extracts necessary data from a file named META that should be included in the source archive. If this file is not included, one should either be obtained from the corresponding Debian, Ubuntu, or Fedora package, or created for the package by the maintainer. A request to include the file should also be made to the upstream developers of the package.

The OCAMLFIND_DESTDIR variable should be used when installing packages with ocaml-findlib. See the example PKGBUILD below for details.


OCaml packages that install executables using OASIS ignore DESTDIR. This is a known limitation of OASIS (issue #493). One way to enable DESTDIR-like functionality is to run the configure script with the --destdir argument, like so:

OCaml bytecode and levels

OCaml can run code on multiple "levels", the top level interprets OCaml Code without compiling, the bytecode level creates machine independent bytecode and the native level creates machine code binaries (just like C/C++).

When building OCaml Packages you need to be aware if the build process is compiling native machine code, bytecode, or as in many cases both. This creates a number of situations which can cause problems with package options and the right dependencies.

If bytecode is produced at all then the PKGBUILD must contain the following to protect the bytecode:


If the package does not contain bytecode and only distributes a binary, then is not needed as a dependency, but it of course is required as a makedepends since the package provides the OCaml compiler. If the package contains both native code and bytecode then should be a dependency and a makedepends.

OCaml code is rarely (if ever) distributed as bytecode only and will almost always include native code: the only case where using any as the arch is advisable is when only un-compiled source code is distributed, usually with a library, though many libraries still distribute native code.

The moral of the story here is to be aware of what it is you are distributing, chances are your package contains both native machine code and bytecode.

Example PKGBUILD using Dune

Dune is a new build system that is becoming more and more used by OCaml projects.

One thing to be aware is that a single project can build several "packages" in the OPAM/findlib sense, each with its own directory in . See for an example. For release builds, all "packages" have to be explicitly listed.

# Contributor: Your Name <youremail@domain.com>

pkgname=ocaml-<package name>
pkgdesc="An OCaml Package"

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  # The "-p" flag is necessary for release builds, see the Dune manpage. Dune will complain if you forget some packages.
  dune build -p package1,package1-extension,package2

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  DESTDIR="${pkgdir}" dune install --prefix "/usr" --libdir "lib/ocaml"

  # Dune installs documentation in /usr/doc, fix that.
  install -dm755 "${pkgdir}/usr/share/"
  mv "${pkgdir}/usr/doc" "${pkgdir}/usr/share/"

Example PKGBUILD using plain findlib

Keep in mind that many OCaml Packages will often need extra parameters passed to make and . Also remember to remove the option and change the architecture if the package does not produce bytecode.

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.