This page explains how to make a OPAM package accessible from a local repository.
It means that the package won't directly be accessible from the official OPAM repository, but the user will need to opam repo add
your local repository.
The running example will be to make an opam package for a library called Foo.
This repository contains data used by OPAM to build Foo. Two files are necesary at the end, index.tar.gz and urls.txt. We will detail their content later. First, let us see how a package is represented for OPAM.
Let us make a directory packages containing the (possibly several) packages you want OPAM to be aware of. Here, let us call our package foo. Directory packages thus contains a directory foo.
Our package foo may have several accessible versions. Each version is stored into a directory foo.version within directory foo. Let us assume that foo has two versions 1.0 and 1.1: directory foo thus contains foo.1.0 and foo.1.1
Finally each version directory must have three files:
-
url: the url where to find the library. For instance
git: "https://github.com/Foo#1.0"
-
descr: a description of the library
-
opam: a file describing various data about the library, such as its dependencies and how to compile it. For instance
opam-version: "1.2.2" maintainer: "Jean-Michel Jarre <jean-michel.jarre@lip6.fr>" authors: [ "Jean-Michel Jarre <jean-michel.jarre@lip6.fr>" "Dorothée <dorothee.lip6.fr>" ] homepage: "https://github.com/Foo" bug-reports: "https://github.com/Foo/issues" license: "LGPL" dev-repo: "https://github.com/Foo" build: ["make"] install: ["make" "install"] build-test: ["make" "test"] remove: ["ocamlfind" "remove" "foo"] depends: [ "base-unix" "ocamlbuild" {build} "ocamlfind" {build} "zarith" ] available: [ocaml-version >= "4.02.1" & ocaml-version < "4.06~"]
As said above, OPAM actually needs two files index.tar.gz and urls.txt.
-
index.tar.gz is simply an archive made of the directory packages defined above.
-
urls.txt contains a relative path to each file of packages with a checksum. For instance
packages/foo/foo.1.1/url c0330a844c91a19c01c1600e2f4b6880 0o664 packages/foo/foo.1.1/opam 709edbe12034f343663afcaf720af65e 0o664 packages/foo/foo.1.1/descr 655bf4375650f1717b8dd0047eaae7a4 0o664 packages/foo/foo.1.0/url 86cdba2bc7799fef2cedf49ead39011a 0o664 packages/foo/foo.1.0/opam 709edbe12034f343663afcaf720af65e 0o664 packages/foo/foo.1.0/descr 655bf4375650f1717b8dd0047eaae7a4 0o664
These two files can be generated by the following command, run at the repository root
opam-admin make
At the end, the opam-foo repository should have:
-
A directory packages containing files for each version of foo
-
A file urls.txt
-
A file index.tar.gz
To build the Foo library, the user has to add the opam-foo repository into OPAM (caution: the files must be directly downloadable from this link, hence the raw...
):
opam repo add foo https://raw.githubusercontent.com/opam-foo/master
Then, the library is installed simply by opam install foo
or opam install foo.1.1
to specify a particular version.