Debian OCaml Packaging Policy for OCaml 3.10.2
Prev | Chapter 2. Packaging OCaml Programs | Next

# 2.3. Bytecode and native versions of programs

As explained in Section 1.2, native OCaml compilers are not available everywhere. For architectures missing native compiler, a bytecode version of the program should be provided.

The package's `debian/rules` should build the native code executable if supported on the architecture it is built on, and fall back to building the bytecode version if no working native code compiler is available. Exceptions to this are the executables who are small or not time critical, which may be built only as bytecode. It is the decision of the individual maintainers to choose this, maybe guided by the practice of the upstream author.

The availability of the native compiler can be tested in the `debian/rules` file by testing the possibility of executing `/usr/bin/ocamlopt`, and build the bytecode version or the native version of the program according to the result of the test. This is a sample snippet of `debian/rules` doing so:

    	build-stamp:
    		dh_testdir

    		if [ -x /usr/bin/ocamlopt ]; then \
    			$(MAKE) opt; \
    		else \
    			$(MAKE) all; \
    		fi

The bytecode versions are portable. In order to spare the buildds and the Debian archive, bytecode versions should be compiled once for all for big packages (which either take a lot of place on disks or take a lot of time to build). For example, the `spamoracle` package provides the `spamoracle-byte` package which is `Architecture: all` and contains the bytecode version of spamoracle, and the `spamoracle` package which contains the native version of spamoracle and is available only where a native OCaml compiler is available (`Architecture: amd64 i386 kfreebsd-i386 powerpc sparc`).

Bytecode versions of the programs should depend on `ocaml-base-nox-3.10.2` (or `ocaml-base-3.10.2` the program either uses the Graphics or the LablTk module). In order for the package to be able to be rebuilt or even binNMUed without a change in the packaging, this version should not be hardcoded in the `debian/control` file. Instead, the package should depend on `ocaml-base-nox-${F:OCamlABI}` and use OCAMLABI := $(shell ocamlc -version) and dh_gencontrol -- -VF:OCamlABI="$(OCAMLABI)" in the `debian/rules` file.

The following is a snippet of a sample `debian/control`:

    	Package: spamoracle-byte
    	Architecture: all
    	Depends: ocaml-base-nox-${F:OCamlABI}
    	Provides: spamoracle
    	Conflicts: spamoracle
    	Replaces: spamoracle

The following its pairing `debian/rules` snippet:

    	OCAMLABI := $(shell ocamlc -version)
    	...
    	binary-indep: build install
    	dh_gencontrol -i -- -VF:OCamlABI="$(OCAMLABI)"

In the case where there is only one package, which provides either a native version where available or a bytecode version otherwise, the dependency on `ocaml-base-nox-3.10.2` should be added only when the package is built in native mode. For example, the `debian/control` of `approx` contains:

    	Package: approx
    	Architecture: any
    	Depends: ${shlibs:Depends}, ${F:OCamlRun}, adduser, bzip2, curl

and the corresponding `debian/rules` contains:

    	OCAMLABI = $(shell ocamlc -version)
    	BYTECODE = $(shell [ -x /usr/bin/ocamlopt ] || echo yes)
    	OCAMLRUN = $(if $(BYTECODE),ocaml-base-nox-$(OCAMLABI))
    	...
    	binary-arch:
    		...
    		dh_gencontrol -- -VF:OCamlRun="$(OCAMLRUN)"

Prev | Home | Next
Bytecode Packages | Up | Packaging OCaml libraries