are also a good way to provide convenient access to a Haskell
layer over a C library.</para>
- <para>GHC comes with several packages (see <xref
- linkend="book-hslibs">), and packages can be added to or removed
+ <para>GHC comes with several packages (see the accompanying
+ library documentation), and packages can be added to or removed
from an existing GHC installation, using the supplied
<literal>ghc-pkg</literal><indexterm><primary><literal>ghc-pkg</literal></primary>
</indexterm> tool, described in <xref
<listitem>
<para>A package has a name
- (e.g. <filename>std</filename>)</para>
+ (e.g. <filename>base</filename>)</para>
</listitem>
<listitem>
<para>The Haskell code in a package may be built into one or
- more archive libraries (e.g. <filename>libHSfoo.a</filename>),
- or a single DLL on Windows
- (e.g. <filename>HSfoo.dll</filename>). The restriction to a
- single DLL on Windows is that the package system is used to
- tell the compiler when it should make an inter-DLL call
- rather than an intra-DLL call (inter-DLL calls require an
- extra indirection). <emphasis>Building packages as DLLs
- doesn't work at the moment; see <XRef
- LinkEnd="win32-dlls-create"> for the gory details.</emphasis>
+ more archive libraries
+ (e.g. <filename>libHSfoo.a</filename>), or a single DLL on
+ Windows (e.g. <filename>HSfoo.dll</filename>). The
+ restriction to a single DLL on Windows is because the
+ package system is used to tell the compiler when it should
+ make an inter-DLL call rather than an intra-DLL call
+ (inter-DLL calls require an extra
+ indirection). <emphasis>Building packages as DLLs doesn't
+ work at the moment; see <XRef LinkEnd="win32-dlls-create">
+ for the gory details.</emphasis>
</para>
+ <para>Building a static library is done by using the
+ <literal>ar</literal> tool, like so:</para>
+
+<screen>ar cqs libHSfoo.a A.o B.o C.o ...</screen>
+
+ <para>where <filename>A.o</filename>,
+ <filename>B.o</filename> and so on are the compiled Haskell
+ modules, and <filename>libHSfoo.a</filename> is the library
+ you wish to create. The syntax may differ slightly on your
+ system, so check the documentation if you run into
+ difficulties.</para>
+
<para>Versions of the Haskell libraries for use with GHCi
may also be included: GHCi cannot load <literal>.a</literal>
files directly, instead it will look for an object file
- called <filename>HSfoo.o</filename> and load that. The
- <literal>ghc-pkg</literal> tool can automatically build the
- GHCi version of each library, see <xref
- linkend="package-management">. To build these libraries by
- hand from the <literal>.a</literal> archive, it is possible
- to use GNU <command>ld</command> as follows:</para>
+ called <filename>HSfoo.o</filename> and load that. On some
+ systems, the <literal>ghc-pkg</literal> tool can
+ automatically build the GHCi version of each library, see
+ <xref linkend="package-management">. To build these
+ libraries by hand from the <literal>.a</literal> archive, it
+ is possible to use GNU <command>ld</command> as
+ follows:</para>
<screen>ld -r ––whole-archive -o HSfoo.o libHSfoo.a</screen>
</listitem>
<para>The <literal>ghc-pkg</literal> tool allows packages to be
added or removed from a package configuration file. By default,
the system-wide configuration file is used, but alternatively
- packages can be added or removed from a user-specified
+ packages can be added, updated or removed from a user-specified
configuration file using the <option>––config-file</option>
option. An empty package configuration file consists of the
string <quote><literal>[]</literal></quote>.</para>
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>––force</option></term>
+ <indexterm><primary><option>––force</option></primary></indexterm>
+ <listitem>
+ <para>Causes <literal>ghc-pkg</literal> to ignore missing
+ directories and libraries when adding a package, and just
+ go ahead and add it anyway. This might be useful if your
+ package installation system needs to add the package to
+ GHC before building and installing the files.</para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>When modifying the configuration file
<screen>
Package {
name = "mypkg",
- import_dirs = ["/usr/local/lib/imports/mypkg"],
+ import_dirs = ["${installdir}/imports/mypkg"],
source_dirs = [],
- library_dirs = ["/usr/local/lib"],
+ library_dirs = ["${installdir}"],
hs_libraries = ["HSmypkg" ],
extra_libraries = ["HSmypkg_cbits"],
include_dirs = [],
<listitem>
<para>A list of directories containing interface files
(<literal>.hi</literal> files) for this package.</para>
+
+ <para>If the package contains profiling libraries, then
+ the interface files for those library modules should have
+ the suffix <literal>.p_hi</literal>. So the package can
+ contain both normal and profiling versions of the same
+ library without conflict (see also
+ <literal>library_dirs</literal> below).</para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename>libHSfoo.a</filename></term>
<listitem>
- <para>The name of the library on Unix
+ <para>The name of the library on Unix and Windows
+ (mingw) systems. Note that we don't support
+ building dynamic libraries of Haskell code on Unix
systems.</para>
</listitem>
</varlistentry>
<term><filename>HSfoo.dll</filename></term>
<listitem>
<para>The name of the dynamic library on Windows
- systems.</para>
+ systems (optional).</para>
</listitem>
</varlistentry>
<varlistentry>
for libraries in
<literal>extra_libraries</literal>.</para>
+ <para>The libraries listed in
+ <literal>extra_libraries</literal> may be any libraries
+ supported by your system's linker, including dynamic
+ libraries (<literal>.so</literal> on Unix,
+ <literal>.DLL</literal> on Windows).</para>
+
<para>Also, <literal>extra_libraries</literal> are placed
on the linker command line after the
<literal>hs_libraries</literal> for the same package. If
(for linking) when this package is being used.</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><literal>framework_dirs</literal></term>
+ <indexterm><primary><literal>framework_dirs</literal></primary>
+ <secondary>package specification</secondary></indexterm>
+ <listitem>
+ <para>On Darwin/MacOS X, a list of directories containing frameworks for this
+ package. This corresponds to the <option>-framework-path</option> option.
+ It is ignored on all other platforms.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>extra_frameworks</literal></term>
+ <indexterm><primary><literal>extra_frameworks</literal></primary>
+ <secondary>package specification</secondary></indexterm>
+ <listitem>
+ <para>On Darwin/MacOS X, a list of frameworks to link to. This corresponds to the
+ <option>-framework</option> option. Take a look at Apple's developer documentation
+ to find out what frameworks actually are. This entry is ignored on all other platforms.</para>
+ </listitem>
+ </varlistentry>
</variablelist>
+
+ <para>
+ The <literal>ghc-pkg</literal> tool performs expansion of
+ environment variables occurring in input package specifications.
+ So, if the <literal>mypkg</literal> was added to the package
+ database as follows:
+ </para>
+<screen>
+ $ installdir=/usr/local/lib ghc-pkg -a < mypkg.pkg
+</screen>
+
+ <para>
+ The occurrence of <literal>${installdir}</literal> is replaced
+ with <literal>/usr/local/lib</literal> in the package data that
+ is added for <literal>mypkg</literal>.
+ </para>
+
+ <para>
+ This feature enables the distribution of package specification
+ files that can be easily configured when installing.
+ </para>
<para>For examples of more package specifications, take a look
at the <literal>package.conf</literal> in your GHC