2
<title>Creating Packages for OCaml Programs</title>
4
Any package providing executables built from OCaml source should conform to the following guidelines.
8
The source package should, if possible, use the name of the upstream
9
package without modifications.
13
Programs which are not particularly CPU hungry should be
14
compiled into bytecode form, and the corresponding binary packages
15
should be <code>Architecture: all</code> in order to minimize
16
archive usage and avoid the need of rebuilding them on all
17
architectures. See <xref linkend="bytecode-prog" /> for details on
18
this kind of packages.
23
should be compiled into native form on architectures where the native
24
compiler is available, and into bytecode on other architectures.
25
See <xref linkend="bytecode-native-prog" /> for details on how to achieve
26
this. The corresponding binary packages should be <code>Architecture:
27
any</code> and will need to be built on any architecture.
31
All bytecode executables should be linked dynamically against the shared libraries for C bindings, so as to not bloat the archive.
32
<!-- ZACK: which cases? -->
33
<!--However, there may be special cases, were using statically linked bytecode is necessary, in these cases, it is naturally ok to link statically.-->
34
That said, often the upstream authors will favor statically linked bytecode executables, because so they don't need to worry about the presence of the dll stub libraries and such. This is not a valid reason to use statically linked bytecode in a Debian package.
35
<!-- ZACK: related to the commented stuff above -->
36
<!--If statically linked bytecode is provided, a justification of this use should be provided in the <filename>README.Debian</filename> file.-->
40
<section id="bytecode-prog">
41
<title>Bytecode Packages</title>
43
A bytecode package has all
44
its binaries compiled into bytecode. It depends on a package
45
containing the OCaml runtime system. By consequence, such a package
46
has its architecture field set to <code>all</code>.
50
A bytecode package must depend on
51
<filename>ocaml-base-nox-&ocaml-version;</filename> (or
52
<filename>ocaml-base-&ocaml-version;</filename> if the program either
53
uses the <code>Graphics</code> or the <code>LablTk</code> module). In
54
order for the package to be able to be rebuilt or even binNMUed
55
without a change in the packaging, <emphasis>this version should not
56
be hardcoded in the <filename>debian/control</filename>
57
file.</emphasis> Instead, the package should depend on
58
<varname>ocaml-base-nox-${F:OCamlABI}</varname> and use <code>OCAMLABI
59
:= $(shell ocamlc -version)</code> and <code>dh_gencontrol --
60
-VF:OCamlABI="$(OCAMLABI)"</code> in the
61
<filename>debian/rules</filename> file.
65
A bytecode package must build-depend-indep on
66
<filename>ocaml-nox-&ocaml-version;</filename> (or
67
<filename>ocaml-&ocaml-version;</filename> if the program either uses
68
the <code>Graphics</code> or the <code>LablTk</code> module). The
69
current version number of OCaml should <emphasis>not</emphasis> be hardcoded
70
into the build-dependency (this is a deviation from a practice which
71
used be recommended but is depreciated now). Of course, if it is
72
necessary to ensure that the version of OCaml has a certain value then
73
version constraints can be used. However, this should be justified by
74
the requirements of the compilation of the program.
78
Bytecode programs which are compiled by <userinput>ocamlc -custom</userinput> must not be stripped. In particular, their package should be excluded from the <command>dh_strip</command> script. When compiled this way, an elf executable is generated containing the ocaml interpreter, and the bytecode of the program in a section which is removed when the program is stripped. For more information, see the bug <ulink url="http://bugs.debian.org/256900">256900</ulink>. An override for the lintian warning is considered as acceptable in this situation.
82
Bytecode programs should not be compiled for debugging, i.e. they should not
83
be compiled passing the <option>-g</option> option to
84
<command>ocamlc</command> (or <command>ocamlc.opt</command>).
89
<section id="bytecode-native-prog">
90
<title>Bytecode and native versions of programs</title>
92
As explained in <xref linkend='bytecode-native' />, native OCaml compilers are not available everywhere. For architectures missing native compiler, a bytecode version of the program should be provided.
96
The package's <filename>debian/rules</filename> 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.
100
The availability of the native compiler can be tested in the <filename>debian/rules</filename> file by testing the possibility of executing <filename>/usr/bin/ocamlopt</filename>, 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 <filename>debian/rules</filename> doing so:
105
if [ -x /usr/bin/ocamlopt ]; then \
114
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 <filename>spamoracle</filename> package provides the <filename>spamoracle-byte</filename> package which is <varname>Architecture: all</varname> and contains the bytecode version of spamoracle, and the <filename>spamoracle</filename> package which contains the native version of spamoracle and is available only where a native OCaml compiler is available (<varname>Architecture: amd64 i386 kfreebsd-i386 powerpc sparc</varname>).
118
Bytecode versions of the programs should depend on <filename>ocaml-base-nox-&ocaml-version;</filename> (or <filename>ocaml-base-&ocaml-version;</filename> the program either uses the <code>Graphics</code> or the <code>LablTk</code> module). In order for the package to be able to be rebuilt or even binNMUed without a change in the packaging, <emphasis>this version should not be hardcoded in the <filename>debian/control</filename> file.</emphasis> Instead, the package should depend on <varname>ocaml-base-nox-${F:OCamlABI}</varname> and use <code>OCAMLABI := $(shell ocamlc -version)</code> and <code>dh_gencontrol -- -VF:OCamlABI="$(OCAMLABI)"</code> in the <filename>debian/rules</filename> file.
121
<para>The following is a snippet of a sample <filename>debian/control</filename>:
123
Package: spamoracle-byte
125
Depends: ocaml-base-nox-${F:OCamlABI}
127
Conflicts: spamoracle
131
<para>The following its pairing <filename>debian/rules</filename> snippet:
133
OCAMLABI := $(shell ocamlc -version)
135
binary-indep: build install
136
dh_gencontrol -i -- -VF:OCamlABI="$(OCAMLABI)"
141
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 <varname>ocaml-base-nox-&ocaml-version;</varname> should be added only when the package is built in native mode. For example, the <filename>debian/control</filename> of <filename>approx</filename> contains:
145
Depends: ${shlibs:Depends}, ${F:OCamlRun}, adduser, bzip2, curl
147
and the corresponding <filename>debian/rules</filename> contains:
149
OCAMLABI = $(shell ocamlc -version)
150
BYTECODE = $(shell [ -x /usr/bin/ocamlopt ] || echo yes)
151
OCAMLRUN = $(if $(BYTECODE),ocaml-base-nox-$(OCAMLABI))
155
dh_gencontrol -- -VF:OCamlRun="$(OCAMLRUN)"