1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
<?xml version="1.0"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"/usr/share/sgml/docbook/dtd/xml/4.4/docbookx.dtd" [
<!ENTITY % included SYSTEM "included.ent">
%included;
]>
<chapter id="scratch">
<title>Scratch</title>
<!-- Parts that have been removed from the doc, maybe we can add it back -->
<para>
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:
<programlisting>
build-stamp:
dh_testdir
if [ -x /usr/bin/ocamlopt ]; then \
$(MAKE) opt; \
else \
$(MAKE) all; \
fi
</programlisting>
</para>
<para>The following is a snippet of a sample <filename>debian/control</filename>:
<programlisting>
Package: spamoracle-byte
Architecture: all
Depends: ocaml-base-${F:OCamlABI}
Provides: spamoracle
Conflicts: spamoracle
Replaces: spamoracle
</programlisting>
</para>
<para>The following its pairing <filename>debian/rules</filename> snippet:
<programlisting>
OCAMLABI := $(shell ocamlc -version)
...
binary-indep: build install
dh_gencontrol -i -- -VF:OCamlABI="$(OCAMLABI)"
</programlisting>
</para>
<para>
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-&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:
<programlisting>
Package: approx
Architecture: any
Depends: ${shlibs:Depends}, ${F:OCamlRun}, adduser, bzip2, curl
</programlisting>
and the corresponding <filename>debian/rules</filename> contains:
<programlisting>
OCAMLABI = $(shell ocamlc -version)
BYTECODE = $(shell [ -x /usr/bin/ocamlopt ] || echo yes)
OCAMLRUN = $(if $(BYTECODE),ocaml-base-$(OCAMLABI))
...
binary-arch:
...
dh_gencontrol -- -VF:OCamlRun="$(OCAMLRUN)"
</programlisting>
</para>
<section>
<title>Handling dependencies on OCaml</title>
<para>
Some parts of the package need to know the current version of OCaml. For
example, libraries should be installed
<filename>&ocaml-sys-dir;/</filename>. However, this path should not be
hardcoded. Previous version of the packaging scheme install libraries into
versionned standard library directory. So path should not be hardcoded,
instead <filename>.in</filename> files should be used where
<varname>@OCamlStdlibDir@</varname> and
<varname>@OCamlDllDir@</varname> are replaced at
<emphasis>build-time</emphasis> by the current OCaml version.</para>
<para>
For example, the package <filename>ocaml-mad</filename> would normally
contain a file <filename>libmad-ocaml-dev.install</filename> for
installing files with <filename>dh_install</filename>, containing:
<programlisting>
usr/lib/ocaml/&ocaml-version;/mad/META
usr/lib/ocaml/&ocaml-version;/mad/*.a
usr/lib/ocaml/&ocaml-version;/mad/*.cm*
usr/lib/ocaml/&ocaml-version;/mad/*.ml*
</programlisting>
In order to avoid the explicit mention of the version of OCaml (&ocaml-version;), the package actually contains instead a file <filename>libmad-ocaml-dev.install.in</filename> which contains:
<programlisting>
usr/lib/ocaml/@OCamlABI@/mad/META
usr/lib/ocaml/@OCamlABI@/mad/*.a
usr/lib/ocaml/@OCamlABI@/mad/*.cm*
usr/lib/ocaml/@OCamlABI@/mad/*.ml*
</programlisting>
The string <varname>@OCamlABI@</varname> is substituted at build-time by the version of OCaml.
</para>
<para>
The only exception to this rule (properly handled by the example above) is
the <filename>debian/control</filename> file, which should never be
generated at build-time. As explained in <ulink
url='#bytecode-native-prog'/>, the dependency should nevertheless not
hardcode the version of OCaml: the <filename>debian/control</filename> file
should have a <varname>Depends: ocaml-base-${F:OCamlABI}</varname>
which is filled by a <code>dh_gencontrol -s --
-VF:OCamlABI="$(OCAMLABI)"</code> in the
<filename>debian/rules</filename> file. </para>
</section>
</chapter>
|