FIX #1861: floating-point constants for infinity and NaN in via-C
[ghc-hetmet.git] / docs / users_guide / packages.xml
1 <?xml version="1.0" encoding="iso-8859-1"?>
2   <sect1 id="packages">
3  <title>
4 Packages
5  </title>
6   <indexterm><primary>packages</primary></indexterm>
7   
8   <para>A package is a library of Haskell modules known to the
9     compiler.  GHC comes with several packages: see the accompanying
10     <ulink url="../libraries/index.html">library
11     documentation</ulink>.  More packages to install can be obtained
12     from <ulink
13     url="http://hackage.haskell.org/packages/hackage.html">HackageDB</ulink>.</para>
14
15   <para>Using a package couldn't be simpler: if you're using
16     <option>--make</option> or GHCi, then most of the installed packages will be
17     automatically available to your program without any further options.  The
18     exceptions to this rule are covered below in <xref
19       linkend="using-packages" />.</para>
20
21   <para>Building your own packages is also quite straightforward: we provide
22     the <ulink url="http://www.haskell.org/cabal/">Cabal</ulink> infrastructure which
23     automates the process of configuring, building, installing and distributing
24     a package.  All you need to do is write a simple configuration file, put a
25     few files in the right places, and you have a package.  See the
26     <ulink url="../Cabal/index.html">Cabal documentation</ulink>
27     for details, and also the Cabal libraries (<ulink url="../libraries/Cabal/Distribution-Simple.html">Distribution.Simple</ulink>,
28     for example).</para>
29
30   <sect2 id="using-packages">
31   <title>Using Packages
32   </title>
33     <indexterm><primary>packages</primary>
34       <secondary>using</secondary></indexterm>
35     
36     <para>GHC only knows about packages that are
37       <emphasis>installed</emphasis>. To see which packages are installed, use
38       the <literal>ghc-pkg</literal> command:</para>
39
40 <screen>
41 $ ghc-pkg list
42 /usr/lib/ghc-6.4/package.conf:
43     base-1.0, haskell98-1.0, template-haskell-1.0, mtl-1.0, unix-1.0,
44     Cabal-1.0, haskell-src-1.0, parsec-1.0, network-1.0,
45     QuickCheck-1.0, HUnit-1.1, fgl-1.0, X11-1.1, HGL-3.1, OpenGL-2.0,
46     GLUT-2.0, stm-1.0, readline-1.0, (lang-1.0), (concurrent-1.0),
47     (posix-1.0), (util-1.0), (data-1.0), (text-1.0), (net-1.0),
48     (hssource-1.0), rts-1.0
49       </screen>
50
51     <para>An installed package is either <emphasis>exposed</emphasis> or <emphasis>hidden</emphasis>
52       by default.      Packages hidden by default are listed in
53       parentheses (eg. <literal>(lang-1.0)</literal>) in the output above.  Command-line flags, described below, allow you to expose a hidden package
54       or hide an exposed one.
55       Only modules from exposed packages may be imported by your Haskell code; if
56       you try to import a module from a hidden package, GHC will emit an error
57       message.</para>
58
59     <para>To see which modules are provided by a package use the
60       <literal>ghc-pkg</literal> command (see <xref linkend="package-management"/>):</para>
61     
62 <screen>
63 $ ghc-pkg field network exposed-modules
64 exposed-modules: Network.BSD,
65                  Network.CGI,
66                  Network.Socket,
67                  Network.URI,
68                  Network
69 </screen>
70
71     <para>The GHC command line options that control packages are:</para>
72
73     <variablelist>
74       <varlistentry>
75         <term>
76           <option>-package <replaceable>P</replaceable></option>
77           <indexterm><primary><option>-package</option></primary></indexterm>
78         </term>
79         <listitem>
80           <para>This option causes the installed
81             package <replaceable>P</replaceable> to be exposed.  The
82             package <replaceable>P</replaceable> can be specified in
83             full with its version number
84             (e.g. <literal>network-1.0</literal>) or the version
85             number can be omitted if there is only one version of the
86             package installed. If there are multiple versions
87             of <replaceable>P</replaceable> installed, then all other
88             versions will become hidden.</para>
89
90           <para>The <option>-package <replaceable>P</replaceable></option>
91             option also causes package <replaceable>P</replaceable> to
92             be linked into the resulting executable or shared
93             object. Whether a packages' library is linked statically
94             or dynamically is controlled by the flag
95             pair <option>-static</option>/<option>-dynamic</option>.</para>
96
97           <para>In <option>&ndash;&ndash;make</option> mode
98             and <option>&ndash;&ndash;interactive</option> mode (see
99             <xref linkend="modes" />), the compiler normally
100             determines which packages are required by the current
101             Haskell modules, and links only those.  In batch mode
102             however, the dependency information isn't available, and
103             explicit
104             <option>-package</option> options must be given when linking. The one other time you might need to use
105             <option>-package</option> to force linking a package is
106             when the package does not contain any Haskell modules (it
107             might contain a C library only, for example).  In that
108             case, GHC will never discover a dependency on it, so it
109             has to be mentioned explicitly.</para>
110
111           <para>For example, to link a program consisting of objects
112             <filename>Foo.o</filename> and <filename>Main.o</filename>, where
113             we made use of the <literal>network</literal> package, we need to
114             give GHC the <literal>-package</literal> flag thus:  
115
116 <screen>$ ghc -o myprog Foo.o Main.o -package network</screen>
117
118             The same flag is necessary even if we compiled the modules from
119             source, because GHC still reckons it's in batch mode: 
120
121 <screen>$ ghc -o myprog Foo.hs Main.hs -package network</screen></para>
122         </listitem>
123       </varlistentry>
124       
125       <varlistentry>
126         <term><option>-hide-all-packages</option>
127         <indexterm><primary><option>-hide-package</option></primary>
128           </indexterm></term>
129         <listitem>
130           <para>Ignore the exposed flag on installed packages, and hide them
131             all by default.  If you use
132             this flag, then any packages you require (including
133             <literal>base</literal>) need to be explicitly exposed using
134             <option>-package</option> options.</para>
135
136           <para>This is a good way to insulate your program from
137             differences in the globally exposed packages, and being
138             explicit about package dependencies is a Good Thing.
139             Cabal always passes the
140             <option>-hide-all-packages</option> flag to GHC, for
141             exactly this reason.</para>
142         </listitem>
143       </varlistentry>
144
145       <varlistentry>
146         <term><option>-hide-package</option> <replaceable>P</replaceable>
147         <indexterm><primary><option>-hide-package</option></primary>
148           </indexterm></term>
149         <listitem>
150           <para>This option does the opposite of <option>-package</option>: it
151             causes the specified package to be <firstterm>hidden</firstterm>,
152             which means that none of its modules will be available for import
153             by Haskell <literal>import</literal> directives.</para>
154
155           <para>Note that the package might still end up being linked into the
156             final program, if it is a dependency (direct or indirect) of
157             another exposed package.</para>
158         </listitem>
159       </varlistentry>
160
161       <varlistentry>
162         <term><option>-ignore-package</option> <replaceable>P</replaceable>
163         <indexterm><primary><option>-ignore-package</option></primary>
164           </indexterm></term>
165         <listitem>
166           <para>Causes the compiler to behave as if package
167             <replaceable>P</replaceable>, and any packages that depend on
168             <literal>P</literal>, are not installed at all.</para>
169
170           <para>Saying <literal>-ignore-package P</literal> is the same as
171             giving <literal>-hide-package</literal> flags for
172             <literal>P</literal> and all the packages that depend on
173             <literal>P</literal>.  Sometimes we don't know ahead of time which
174             packages will be installed that depend on <literal>P</literal>,
175             which is when the <literal>-ignore-package</literal> flag can be
176             useful.</para>
177         </listitem>
178       </varlistentry>
179
180       <varlistentry>
181         <term><option>-package-name</option> <replaceable>foo</replaceable>
182         <indexterm><primary><option>-package-name</option></primary>
183           </indexterm></term>
184         <listitem>
185           <para>Tells GHC the the module being compiled forms part of
186             package <replaceable>foo</replaceable>.
187             If this flag is omitted (a very common case) then the
188             default package <literal>main</literal> is assumed.</para>
189             <para>Note: the argument to <option>-package-name</option>
190             should be the full package identifier for the package,
191             that is it should include the version number.  For example:
192             <literal>-package mypkg-1.2</literal>.</para>
193         </listitem>
194       </varlistentry>
195     </variablelist>
196   </sect2>
197
198   <sect2 id="package-main">
199     <title>The main package</title>
200
201   <para>Every complete Haskell program must define <literal>main</literal> in 
202    module <literal>Main</literal> 
203    in package <literal>main</literal>.   (Omitting the <option>-package-name</option> flag compiles
204    code for package <literal>main</literal>.) Failure to do so leads to a somewhat obscure
205    link-time error of the form:
206 <programlisting>
207 /usr/bin/ld: Undefined symbols:
208 _ZCMain_main_closure
209 ___stginit_ZCMain
210 </programlisting>
211 </para>
212
213   </sect2>
214
215   <sect2 id="package-overlaps">
216     <title>Consequences of packages</title>
217
218     <para>It is possible that by using packages you might end up with
219     a program that contains two modules with the same name: perhaps
220     you used a package P that has a <emphasis>hidden</emphasis> module
221     M, and there is also a module M in your program.  Or perhaps the
222     dependencies of packages that you used contain some overlapping
223     modules.  Perhaps the program even contains multiple versions of a
224     certain package, due to dependencies from other packages.</para>
225
226     <para>None of these scenarios gives rise to an error on its
227     own<footnote><para>it used to in GHC 6.4, but not since
228     6.6</para></footnote>, but they may have some interesting
229     consequences.  For instance, if you have a type
230     <literal>M.T</literal> from version 1 of package
231     <literal>P</literal>, then this is <emphasis>not</emphasis> the
232     same as the type <literal>M.T</literal> from version 2 of package
233     <literal>P</literal>, and GHC will report an error if you try to
234     use one where the other is expected.</para>
235
236     <para>Formally speaking, in Haskell 98, an entity (function, type
237     or class) in a program is uniquely identified by the pair of the
238     module name in which it is defined and its name.  In GHC, an
239     entity is uniquely defined by a triple: package, module, and
240     name.</para>
241   </sect2>
242
243   <sect2 id="package-databases">
244     <title>Package Databases</title>
245       
246     <para>A package database is a file, normally called
247       <literal>package.conf</literal> which contains descriptions of installed
248       packages.  GHC usually knows about two package databases:</para>
249
250     <itemizedlist>
251       <listitem>
252         <para>The global package database, which comes with your GHC
253           installation.</para>
254       </listitem>
255       <listitem>
256         <para>A package database private to each user.  On Unix
257           systems this will be
258           <filename>$HOME/.ghc/<replaceable>arch</replaceable>-<replaceable>os</replaceable>-<replaceable>version</replaceable>/package.conf</filename>, and on
259           Windows it will be something like
260           <filename>C:\Documents&nbsp;And&nbsp;Settings\<replaceable>user</replaceable>\ghc</filename>.
261           The <literal>ghc-pkg</literal> tool knows where this file should be
262           located, and will create it if it doesn't exist (see <xref linkend="package-management" />).</para>
263       </listitem>
264     </itemizedlist>
265
266     <para>When GHC starts up, it reads the contents of these two package
267       databases, and builds up a list of the packages it knows about.  You can
268       see GHC's package table by running GHC with the <option>-v</option>
269       flag.</para> 
270
271     <para>Package databases may overlap: for example, packages in the user
272       database will override those of the same name in the global
273       database.</para> 
274
275     <para>You can control the loading of package databases using the following
276       GHC options:</para> 
277
278     <variablelist>
279       <varlistentry>
280         <term>
281           <option>-package-conf <replaceable>file</replaceable></option>
282           <indexterm><primary><option>-package-conf</option></primary></indexterm>
283         </term>
284         <listitem>
285           <para>Read in the package configuration file
286             <replaceable>file</replaceable> in addition to the system
287             default file and the user's local file.  Packages in additional
288             files read this way will override those in the global and user
289             databases.</para>
290         </listitem>
291       </varlistentry>
292
293       <varlistentry>
294         <term><option>-no-user-package-conf</option>
295           <indexterm><primary><option>-no-user-package-conf</option></primary>
296           </indexterm>
297         </term>
298         <listitem>
299           <para>Prevent loading of the user's local package database.</para>
300         </listitem>
301       </varlistentry>
302     </variablelist>
303
304     <para>To create a new package database, just create
305       a new file and put the string
306       <quote><literal>[]</literal></quote> in it.  Packages can be
307       added to the file using the
308       <literal>ghc-pkg</literal> tool, described in <xref
309       linkend="package-management"/>.</para>
310
311     <sect3 id="ghc-package-path">
312       <title>The <literal>GHC_PACKAGE_PATH</literal> environment variable</title>
313       <indexterm><primary>Environment variable</primary><secondary><literal>GHC_PACKAGE_PATH</literal></secondary>
314       </indexterm>
315       <indexterm><primary><literal>GHC_PACKAGE_PATH</literal></primary></indexterm>
316       <para>The <literal>GHC_PACKAGE_PATH</literal> environment variable may be
317         set to a <literal>:</literal>-separated (<literal>;</literal>-separated
318         on Windows) list of files containing package databases.  This list of
319         package databases is used by GHC and ghc-pkg, with earlier databases in
320         the list overriding later ones.  This order was chosen to match the
321         behaviour of the <literal>PATH</literal> environment variable; think of
322         it as a list of package databases that are searched left-to-right for
323         packages.</para>
324
325       <para>If <literal>GHC_PACKAGE_PATH</literal> ends in a separator, then
326         the default user and system package databases are appended, in that
327         order. e.g. to augment the usual set of packages with a database of
328         your own, you could say (on Unix):
329 <screen>
330 $ export GHC_PACKAGE_PATH=$HOME/.my-ghc-packages.conf:</screen>
331         (use <literal>;</literal> instead of <literal>:</literal> on
332         Windows).</para>
333
334       <para>To check whether your <literal>GHC_PACKAGE_PATH</literal> setting
335         is doing the right thing, <literal>ghc-pkg list</literal> will list all
336         the databases in use, in the reverse order they are searched.</para>
337       
338     </sect3>
339   </sect2>
340
341   <sect2 id="building-packages">
342     <title>Building a package from Haskell source</title>
343     <indexterm><primary>packages</primary>
344       <secondary>building</secondary></indexterm>
345
346     <para>We don't recommend building packages the hard way.  Instead, use the
347       <ulink url="../Cabal/index.html">Cabal</ulink> infrastructure
348       if possible.  If your package is particularly complicated or requires a
349       lot of configuration, then you might have to fall back to the low-level
350       mechanisms, so a few hints for those brave souls follow.</para>
351     
352     <para>You need to build an "installed package info" file for
353       passing to <literal>ghc-pkg</literal> when installing your
354       package.  The contents of this file are described in
355       <xref linkend="installed-pkg-info" />.</para>
356
357     <para>The Haskell code in a package may be built into one or more
358       archive libraries (e.g. <filename>libHSfoo.a</filename>), or a
359       single shared object
360       (e.g. <filename>libHSfoo.dll/.so/.dylib</filename>).  The
361       restriction to a single shared object is because the package
362       system is used to tell the compiler when it should make an
363       inter-shared-object call rather than an intra-shared-object-call
364       call (inter-shared-object calls require an extra
365       indirection).</para>
366     <itemizedlist>
367       <listitem><para>Building a static library is done by using the
368           <literal>ar</literal> tool, like so:</para>
369
370 <screen>ar cqs libHSfoo-1.0.a A.o B.o C.o ...</screen>
371
372           <para>where <filename>A.o</filename>,
373             <filename>B.o</filename> and so on are the compiled Haskell
374             modules, and <filename>libHSfoo.a</filename> is the library you
375             wish to create.  The syntax may differ slightly on your system,
376             so check the documentation if you run into difficulties.</para>
377       </listitem>
378       <listitem>
379         <para>Versions of the Haskell libraries for use with GHCi may also
380           abe included: GHCi cannot load <literal>.a</literal> files
381           directly, instead it will look for an object file
382           called <filename>HSfoo.o</filename> and load that.  On some
383           systems, the <literal>ghc-pkg</literal> tool can automatically
384           build the GHCi version of each library, see
385           <xref linkend="package-management"/>.  To build these libraries
386           by hand from the <literal>.a</literal> archive, it is possible
387           to use GNU <command>ld</command> as follows:</para>
388
389 <screen>ld -r &ndash;&ndash;whole-archive -o HSfoo.o libHSfoo.a</screen>
390
391         <para>(replace
392           <literal>&ndash;&ndash;whole-archive</literal> with
393           <literal>&ndash;all_load</literal> on MacOS X)</para>
394       </listitem>
395       <listitem>
396         <para>When building the package as shared object, GHC wraps
397           out the underlying linker so that the user gets a common
398           interface to all shared object variants that are supported
399           by GHC (DLLs, ELF DSOs, and Mac OS dylibs). The shared
400           object must be named in specific way for two reasons: (1)
401           the name must contain the GHC compiler version, so that two
402           library variants don't collide that are compiled by
403           different versions of GHC and that therefore are most likely
404           incompatible with respect to calling conventions, (2) it
405           must be different from the static name otherwise we would
406           not be able to control the linker as precisely as necessary
407           to make
408           the <option>-static</option>/<option>-dynamic</option> flags
409           work, see <xref linkend="options-linker" />.</para>
410
411 <screen>ghc -shared libHSfoo-1.0-ghc<replaceable>GHCVersion</replaceable>.so A.o B.o C.o</screen>
412         <para>Using GHC's version number in the shared object name
413           allows different library versions compiled by different GHC
414           versions to be installed in standard system locations,
415           e.g. under *nix /usr/lib. To obtain the version number of
416           GHC invoke <literal>ghc --numeric-version</literal> and use
417           its output in place
418           of <replaceable>GHCVersion</replaceable>. See also
419           <xref linkend="options-codegen" /> on how object files must
420           be prepared for shared object linking.</para>
421       </listitem>
422     </itemizedlist>
423
424      <para>GHC does not maintain detailed cross-package dependency
425        information.  It does remember which modules in other packages
426        the current module depends on, but not which things within
427        those imported things.</para>
428     
429      <para>To compile a module which is to be part of a new package,
430       use the <literal>-package-name</literal> option (<xref linkend="using-packages"/>).
431       Failure to use the <literal>-package-name</literal> option
432       when compiling a package will probably result in disaster, but
433       you will only discover later when you attempt to import modules
434       from the package.  At this point GHC will complain that the
435       package name it was expecting the module to come from is not the
436       same as the package name stored in the <literal>.hi</literal>
437       file.</para>
438
439     <para>It is worth noting with shared objects, when each package
440       is built as a single shared object file, since a reference to a shared object costs an extra
441       indirection, intra-package references are cheaper than
442       inter-package references. Of course, this applies to the
443       <filename>main</filename> package as well.</para>
444     </sect2>
445
446   <sect2 id="package-management">
447     <title>Package management (the <literal>ghc-pkg</literal> command)</title>
448     <indexterm><primary>packages</primary>
449       <secondary>management</secondary></indexterm>
450     
451     <para>The <literal>ghc-pkg</literal> tool allows packages to be
452       added or removed from a package database.  By default,
453       the system-wide package database is modified, but alternatively
454       the user's local package database or another specified
455       file can be used.</para>
456
457     <para>To see what package databases are in use, say
458       <literal>ghc-pkg&nbsp;list</literal>.  The stack of databases that
459       <literal>ghc-pkg</literal> knows about can be modified using the
460       <literal>GHC_PACKAGE_PATH</literal> environment variable (see <xref
461         linkend="ghc-package-path" />, and using
462         <literal>--package-conf</literal> options on the
463         <literal>ghc-pkg</literal> command line.</para>
464
465     <para>When asked to modify a database, <literal>ghc-pkg</literal> modifies
466       the global database by default.  Specifying <option>--user</option>
467       causes it to act on the user database, or <option>--package-conf</option>
468       can be used to act on another database entirely.  When multiple of these
469       options are given, the rightmost one is used as the database to act
470       upon.</para>
471
472    <para>Commands that query the package database (list, latest,
473      describe, field) operate on the list of databases specified by
474      the flags <option>--user</option>, <option>--global</option>, and
475      <option>--package-conf</option>.  If none of these flags are
476      given, the default is <option>--global</option>
477      <option>--user</option>.</para>
478
479     <para>If the environment variable <literal>GHC_PACKAGE_PATH</literal> is
480       set, and its value does not end in a separator (<literal>:</literal> on
481       Unix, <literal>;</literal> on Windows), then the last database is
482       considered to be the global database, and will be modified by default by
483       <literal>ghc-pkg</literal>.  The intention here is that
484       <literal>GHC_PACKAGE_PATH</literal> can be used to create a virtual
485       package environment into which Cabal packages can be installed without
486       setting anything other than <literal>GHC_PACKAGE_PATH</literal>.</para>
487
488     <para>The <literal>ghc-pkg</literal> program may be run in the ways listed
489       below.  Where a package name is required, the package can be named in
490       full including the version number 
491       (e.g. <literal>network-1.0</literal>), or without the version number.
492       Naming a package without the version number matches all versions of the
493       package; the specified action will be applied to all the matching
494       packages.  A package specifier that matches all version of the package
495       can also be written <replaceable>pkg</replaceable><literal>-*</literal>,
496       to make it clearer that multiple packages are being matched.</para>
497
498     <variablelist>
499       <varlistentry>
500         <term><literal>ghc-pkg register <replaceable>file</replaceable></literal></term>
501         <listitem>
502           <para>Reads a package specification from
503             <replaceable>file</replaceable> (which may be &ldquo;<literal>-</literal>&rdquo;
504             to indicate standard input),
505             and adds it to the database of installed packages.  The syntax of
506             <replaceable>file</replaceable> is given in <xref
507               linkend="installed-pkg-info" />.</para>
508
509           <para>The package specification must be a package that isn't already
510             installed.</para>
511         </listitem>
512       </varlistentry>
513
514       <varlistentry>
515         <term><literal>ghc-pkg update <replaceable>file</replaceable></literal></term>
516         <listitem>
517           <para>The same as <literal>register</literal>, except that if a
518             package of the same name is already installed, it is
519             replaced by the new one.</para>
520         </listitem>
521       </varlistentry>
522
523       <varlistentry>
524         <term><literal>ghc-pkg unregister <replaceable>P</replaceable></literal></term>
525         <listitem>
526           <para>Remove the specified package from the database.</para>
527         </listitem>
528       </varlistentry>
529
530       <varlistentry>
531         <term><literal>ghc-pkg expose <replaceable>P</replaceable></literal></term>
532         <listitem>
533           <para>Sets the <literal>exposed</literal> flag for package
534             <replaceable>P</replaceable> to <literal>True</literal>.</para>
535         </listitem>
536       </varlistentry>
537
538       <varlistentry>
539         <term><literal>ghc-pkg check</literal></term>
540         <listitem>
541           <para>Check consistency of dependencies in the package
542           database, and report packages that have missing
543           dependencies.</para>
544         </listitem>
545       </varlistentry>
546
547       <varlistentry>
548         <term><literal>ghc-pkg hide <replaceable>P</replaceable></literal></term>
549         <listitem>
550           <para>Sets the <literal>exposed</literal> flag for package
551             <replaceable>P</replaceable> to <literal>False</literal>.</para>
552         </listitem>
553       </varlistentry>
554
555       <varlistentry>
556         <term><literal>ghc-pkg list [<replaceable>P</replaceable>] [<option>--simple-output</option>]</literal></term>
557         <listitem>
558           <para>This option displays the currently installed
559             packages, for each of the databases known to
560             <literal>ghc-pkg</literal>.  That includes the global database, the
561             user's local database, and any further files specified using the
562             <option>-f</option> option on the command line.</para>
563
564           <para>Hidden packages (those for which the <literal>exposed</literal>
565             flag is <literal>False</literal>) are shown in parentheses in the
566             list of packages.</para>
567
568           <para>If an optional package identifier <replaceable>P</replaceable>
569             is given, then only packages matching that identifier are
570             shown.</para>
571           
572           <para>If the option <option>--simple-output</option> is given, then
573             the packages are listed on a single line separated by spaces, and
574             the database names are not included.  This is intended to make it
575             easier to parse the output of <literal>ghc-pkg list</literal> using
576             a script.</para>
577         </listitem>
578       </varlistentry>
579
580       <varlistentry>
581         <term><literal>ghc-pkg latest <replaceable>P</replaceable></literal></term>
582         <listitem>
583           <para>Prints the latest available version of package
584             <replaceable>P</replaceable>.</para>
585         </listitem>
586       </varlistentry>
587
588       <varlistentry>
589         <term><literal>ghc-pkg describe <replaceable>P</replaceable></literal></term>
590         <listitem>
591           <para>Emit the full description of the specified package.  The
592             description is in the form of an
593             <literal>InstalledPackageInfo</literal>, the same as the input file
594             format for <literal>ghc-pkg register</literal>.  See <xref
595               linkend="installed-pkg-info" /> for details.</para>
596         </listitem>
597       </varlistentry>
598
599       <varlistentry>
600         <term><literal>ghc-pkg field <replaceable>P</replaceable> <replaceable>field</replaceable></literal></term>
601         <listitem>
602           <para>Show just a single field of the installed package description
603             for <literal>P</literal>.</para>
604         </listitem>
605       </varlistentry>
606     </variablelist>
607
608     <para>Additionally, the following flags are accepted by
609       <literal>ghc-pkg</literal>:</para>
610
611     <variablelist>
612       <varlistentry>
613         <term>
614           <option>&ndash;&ndash;auto-ghci-libs</option><indexterm><primary><option>&ndash;&ndash;auto-ghci-libs</option></primary>
615           </indexterm>
616         </term>
617         <listitem>
618           <para>Automatically generate the GHCi
619             <filename>.o</filename> version of each
620             <filename>.a</filename> Haskell library, using GNU ld (if
621             that is available).  Without this option,
622             <literal>ghc-pkg</literal> will warn if GHCi versions of
623             any Haskell libraries in the package don't exist.</para>
624             
625             <para>GHCi <literal>.o</literal> libraries don't
626             necessarily have to live in the same directory as the
627             corresponding <literal>.a</literal> library.  However,
628             this option will cause the GHCi library to be created in
629             the same directory as the <literal>.a</literal>
630             library.</para>
631         </listitem>
632       </varlistentry>
633
634       <varlistentry>
635         <term>
636           <option>-f</option> <replaceable>file</replaceable>
637           <indexterm><primary><option>-f</option></primary>
638           </indexterm>
639         </term>
640         <term>
641           <option>-package-conf</option> <replaceable>file</replaceable>
642           <indexterm><primary><option>-package-conf</option></primary>
643           </indexterm>
644         </term>
645         <listitem>
646           <para>Adds <replaceable>file</replaceable> to the stack of package
647             databases.  Additionally, <replaceable>file</replaceable> will
648             also be the database modified by a <literal>register</literal>,
649             <literal>unregister</literal>, <literal>expose</literal> or
650             <literal>hide</literal> command, unless it is overridden by a later
651             <option>--package-conf</option>, <option>--user</option> or
652             <option>--global</option> option.</para>
653         </listitem>
654       </varlistentry>
655
656       <varlistentry>
657         <term>
658           <option>&ndash;&ndash;force</option>
659           <indexterm><primary>
660               <option>&ndash;&ndash;force</option>
661             </primary></indexterm>
662         </term>
663         <listitem>
664           <para>Causes <literal>ghc-pkg</literal> to ignore missing
665             dependencies, directories and libraries when registering a package,
666             and just go ahead and add it anyway.  This might be useful if your
667             package installation system needs to add the package to
668             GHC before building and installing the files.</para>
669         </listitem>
670       </varlistentry>
671
672       <varlistentry>
673         <term>
674           <option>&ndash;&ndash;global</option><indexterm><primary><option>&ndash;&ndash;global</option></primary>
675           </indexterm>
676         </term>
677         <listitem>
678           <para>Operate on the global package database (this is the default).
679             This flag affects the <literal>register</literal>,
680             <literal>update</literal>, <literal>unregister</literal>,
681             <literal>expose</literal>, and <literal>hide</literal>
682             commands.</para>
683         </listitem>
684       </varlistentry>
685
686       <varlistentry>
687         <term>
688           <option>&ndash;&ndash;help</option><indexterm><primary><option>&ndash;&ndash;help</option></primary>
689           </indexterm>
690         </term>
691         <term>
692           <option>-?</option><indexterm><primary><option>-?</option></primary>
693           </indexterm>
694         </term>
695         <listitem>
696           <para>Outputs the command-line syntax.</para>
697         </listitem>
698       </varlistentry>
699
700       <varlistentry>
701         <term>
702           <option>&ndash;&ndash;user</option><indexterm><primary><option>&ndash;&ndash;user</option></primary>
703           </indexterm>
704         </term>
705         <listitem>
706           <para>Operate on the current user's local package database.
707             This flag affects the <literal>register</literal>,
708             <literal>update</literal>, <literal>unregister</literal>,
709             <literal>expose</literal>, and <literal>hide</literal>
710             commands.</para>
711         </listitem>
712       </varlistentry>
713
714       <varlistentry>
715         <term>
716           <option>-V</option><indexterm><primary><option>-V</option></primary>
717           </indexterm>
718         </term>
719         <term>
720           <option>&ndash;&ndash;version</option><indexterm><primary><option>&ndash;&ndash;version</option></primary>
721           </indexterm>
722         </term>
723         <listitem>
724           <para>Output the <literal>ghc-pkg</literal> version number.</para>
725         </listitem>
726       </varlistentry>
727     </variablelist>
728
729     <para>When modifying the package database
730       <replaceable>file</replaceable>, a copy of the original file is
731       saved in <replaceable>file</replaceable><literal>.old</literal>,
732       so in an emergency you can always restore the old settings by
733       copying the old file back again.</para>
734
735   </sect2>
736   
737   <sect2 id="installed-pkg-info">
738     <title>
739       <literal>InstalledPackageInfo</literal>: a package specification
740     </title>
741
742     <para>A package specification is a Haskell record; in particular, it is the
743       record <ulink
744         url="../libraries/Cabal/Distribution-InstalledPackageInfo.html#%tInstalledPackageInfo">InstalledPackageInfo</ulink> in the module Distribution.InstalledPackageInfo, which is part of the Cabal package distributed with GHC.</para>
745
746     <para>An <literal>InstalledPackageInfo</literal> has a human
747       readable/writable syntax.  The functions
748       <literal>parseInstalledPackageInfo</literal> and
749       <literal>showInstalledPackageInfo</literal> read and write this syntax
750       respectively.  Here's an example of the
751       <literal>InstalledPackageInfo</literal> for the <literal>unix</literal> package:</para>
752
753 <screen>
754 $ ghc-pkg describe unix
755 name: unix
756 version: 1.0
757 license: BSD3
758 copyright:
759 maintainer: libraries@haskell.org
760 stability:
761 homepage:
762 package-url:
763 description:
764 category:
765 author:
766 exposed: True
767 exposed-modules: System.Posix,
768                  System.Posix.DynamicLinker.Module,
769                  System.Posix.DynamicLinker.Prim,
770                  System.Posix.Directory,
771                  System.Posix.DynamicLinker,
772                  System.Posix.Env,
773                  System.Posix.Error,
774                  System.Posix.Files,
775                  System.Posix.IO,
776                  System.Posix.Process,
777                  System.Posix.Resource,
778                  System.Posix.Temp,
779                  System.Posix.Terminal,
780                  System.Posix.Time,
781                  System.Posix.Unistd,
782                  System.Posix.User,
783                  System.Posix.Signals.Exts
784 import-dirs: /usr/lib/ghc-6.4/libraries/unix
785 library-dirs: /usr/lib/ghc-6.4/libraries/unix
786 hs-libraries: HSunix
787 extra-libraries: HSunix_cbits, dl
788 include-dirs: /usr/lib/ghc-6.4/libraries/unix/include
789 includes: HsUnix.h
790 depends: base-1.0
791 </screen>
792
793     <para>The full <ulink url="../Cabal/index.html">Cabal documentation</ulink>
794       is still in preparation (at time of writing), so in the meantime
795       here is a brief description of the syntax of this file:</para>
796
797     <para>A package description consists of a number of field/value pairs.  A
798       field starts with the field name in the left-hand column followed by a
799       &ldquo;<literal>:</literal>&rdquo;, and the value continues until the next line that begins in the
800       left-hand column, or the end of file.</para>
801
802     <para>The syntax of the value depends on the field.   The various field
803       types are:</para>
804
805     <variablelist>
806       <varlistentry>
807         <term>freeform</term>
808         <listitem>
809           <para>Any arbitrary string, no interpretation or parsing is
810             done.</para>
811         </listitem>
812       </varlistentry>
813       <varlistentry>
814         <term>string</term>
815         <listitem>
816           <para>A sequence of non-space characters, or a sequence of arbitrary
817             characters surrounded by quotes <literal>"...."</literal>.</para>
818         </listitem>
819       </varlistentry>
820       <varlistentry>
821         <term>string list</term>
822         <listitem>
823           <para>A sequence of strings, separated by commas.  The sequence may
824             be empty.</para>
825         </listitem>
826       </varlistentry>
827     </variablelist>
828
829     <para>In addition, there are some fields with special syntax (e.g. package
830       names, version, dependencies).</para>
831
832     <para>The allowed fields, with their types, are:</para>
833         
834     <variablelist>
835       <varlistentry>
836         <term>
837           <literal>name</literal>
838           <indexterm><primary><literal>name</literal></primary><secondary>package specification</secondary></indexterm>
839         </term>
840         <listitem>
841           <para>The package's name (without the version).</para>
842         </listitem>
843       </varlistentry>
844       
845       <varlistentry>
846         <term>
847           <literal>version</literal>
848           <indexterm><primary><literal>version</literal></primary><secondary>package specification</secondary></indexterm>
849         </term>
850         <listitem>
851           <para>The package's version, usually in the form
852             <literal>A.B</literal> (any number of components are allowed).</para>
853         </listitem>
854       </varlistentry>
855       
856       <varlistentry>
857         <term>
858           <literal>license</literal>
859           <indexterm><primary><literal>auto</literal></primary><secondary>package specification</secondary></indexterm>
860         </term>
861         <listitem>
862           <para>(string) The type of license under which this package is distributed.
863             This field is a value of the <ulink
864         url="../libraries/Cabal/Distribution-License.html#t:License"><literal>License</literal></ulink> type.</para>
865         </listitem>
866       </varlistentry>
867
868         <varlistentry>
869           <term>
870             <literal>license-file</literal>
871             <indexterm><primary><literal>license-file</literal></primary><secondary>package specification</secondary></indexterm>
872           </term>
873           <listitem>
874             <para>(optional string) The name of a file giving detailed license
875             information for this package.</para>
876           </listitem>
877         </varlistentry>
878
879         <varlistentry>
880           <term>
881             <literal>copyright</literal>
882             <indexterm><primary><literal>copyright</literal></primary><secondary>package specification</secondary></indexterm>
883           </term>
884           <listitem>
885             <para>(optional freeform) The copyright string.</para>
886           </listitem>
887         </varlistentry>
888
889         <varlistentry>
890           <term>
891             <literal>maintainer</literal>
892             <indexterm><primary><literal>maintainer</literal></primary><secondary>package specification</secondary></indexterm>
893           </term>
894           <listitem>
895             <para>(optinoal freeform) The email address of the package's maintainer.</para>
896           </listitem>
897         </varlistentry>
898
899         <varlistentry>
900           <term>
901             <literal>stability</literal>
902             <indexterm><primary><literal>stability</literal></primary><secondary>package specification</secondary></indexterm>
903           </term>
904           <listitem>
905             <para>(optional freeform) A string describing the stability of the package
906             (eg. stable, provisional or experimental).</para>
907           </listitem>
908         </varlistentry>
909
910         <varlistentry>
911           <term>
912             <literal>homepage</literal>
913             <indexterm><primary><literal>homepage</literal></primary><secondary>package specification</secondary></indexterm>
914           </term>
915           <listitem>
916             <para>(optional freeform) URL of the package's home page.</para>
917           </listitem>
918         </varlistentry>
919
920       <varlistentry>
921         <term>
922             <literal>package-url</literal>
923             <indexterm><primary><literal>package-url</literal></primary><secondary>package specification</secondary></indexterm>
924           </term>
925           <listitem>
926             <para>(optional freeform) URL of a downloadable distribution for this
927             package.  The distribution should be a Cabal package.</para>
928           </listitem>
929         </varlistentry>
930
931         <varlistentry>
932           <term>
933             <literal>description</literal>
934             <indexterm><primary><literal>description</literal></primary><secondary>package specification</secondary></indexterm>
935           </term>
936           <listitem>
937             <para>(optional freeform) Description of the package.</para>
938           </listitem>
939         </varlistentry>
940
941       <varlistentry>
942           <term>
943             <literal>category</literal>
944             <indexterm><primary><literal>category</literal></primary><secondary>package specification</secondary></indexterm>
945           </term>
946           <listitem>
947             <para>(optinoal freeform) Which category the package belongs to.  This field
948             is for use in conjunction with a future centralised package
949             distribution framework, tentatively titled Hackage.</para>
950           </listitem>
951         </varlistentry>
952
953         <varlistentry>
954           <term>
955             <literal>author</literal>
956             <indexterm><primary><literal>author</literal></primary><secondary>package specification</secondary></indexterm>
957           </term>
958           <listitem>
959             <para>(optional freeform) Author of the package.</para>
960           </listitem>
961         </varlistentry>
962
963         <varlistentry>
964           <term>
965             <literal>exposed</literal>
966             <indexterm><primary><literal>exposed</literal></primary><secondary>package specification</secondary></indexterm>
967           </term>
968           <listitem>
969             <para>(bool) Whether the package is exposed or not.</para>
970           </listitem>
971         </varlistentry>
972
973         <varlistentry>
974           <term>
975             <literal>exposed-modules</literal>
976             <indexterm><primary><literal>exposed-modules</literal></primary><secondary>package specification</secondary></indexterm>
977           </term>
978           <listitem>
979             <para>(string list) modules exposed by this package.</para>
980           </listitem>
981         </varlistentry>
982
983         <varlistentry>
984           <term>
985             <literal>hidden-modules</literal>
986             <indexterm><primary><literal>hidden-modules</literal></primary><secondary>package specification</secondary></indexterm>
987           </term>
988           <listitem>
989             <para>(string list) modules provided by this package,
990             but not exposed to the programmer.  These modules cannot be
991             imported, but they are still subject to the overlapping constraint:
992             no other package in the same program may provide a module of the
993             same name.</para>
994         </listitem>
995         </varlistentry>
996
997         <varlistentry>
998           <term>
999             <literal>import-dirs</literal>
1000             <indexterm><primary><literal>import-dirs</literal></primary><secondary>package specification</secondary></indexterm>
1001           </term>
1002           <listitem>
1003             <para>(string list) A list of directories containing interface files
1004             (<literal>.hi</literal> files) for this package.</para>
1005
1006             <para>If the package contains profiling libraries, then
1007             the interface files for those library modules should have
1008             the suffix <literal>.p_hi</literal>.  So the package can
1009             contain both normal and profiling versions of the same
1010             library without conflict (see also
1011             <literal>library_dirs</literal> below).</para>
1012           </listitem>
1013         </varlistentry>
1014
1015         <varlistentry>
1016           <term>
1017             <literal>library-dirs</literal>
1018             <indexterm><primary><literal>library-dirs</literal></primary><secondary>package specification</secondary></indexterm>
1019           </term>
1020           <listitem>
1021             <para>(string list) A list of directories containing libraries for this
1022             package.</para>
1023           </listitem>
1024         </varlistentry>
1025
1026         <varlistentry>
1027           <term>
1028             <literal>hs-libraries</literal>
1029             <indexterm><primary><literal>hs-libraries</literal></primary><secondary>package specification</secondary></indexterm>
1030           </term>
1031           <listitem>
1032             <para>(string list) A list of libraries containing Haskell code for this
1033             package, with the <literal>.a</literal> or
1034             <literal>.dll</literal> suffix omitted.  When packages are
1035             built as libraries, the
1036             <literal>lib</literal> prefix is also omitted.</para>
1037
1038             <para>For use with GHCi, each library should have an
1039             object file too.  The name of the object file does
1040             <emphasis>not</emphasis> have a <literal>lib</literal>
1041             prefix, and has the normal object suffix for your
1042             platform.</para>
1043
1044             <para>For example, if we specify a Haskell library as
1045             <filename>HSfoo</filename> in the package spec, then the
1046             various flavours of library that GHC actually uses will be
1047             called:</para>
1048             <variablelist>
1049               <varlistentry>
1050                 <term><filename>libHSfoo.a</filename></term>
1051                 <listitem>
1052                   <para>The name of the library on Unix and Windows
1053                   (mingw) systems.  Note that we don't support
1054                   building dynamic libraries of Haskell code on Unix
1055                   systems.</para>
1056                 </listitem>
1057               </varlistentry>
1058               <varlistentry>
1059                 <term><filename>HSfoo.dll</filename></term>
1060                 <listitem>
1061                   <para>The name of the dynamic library on Windows
1062                   systems (optional).</para>
1063                 </listitem>
1064               </varlistentry>
1065               <varlistentry>
1066                 <term><filename>HSfoo.o</filename></term>
1067                 <term><filename>HSfoo.obj</filename></term>
1068                 <listitem>
1069                   <para>The object version of the library used by
1070                   GHCi.</para>
1071                 </listitem>
1072               </varlistentry>
1073             </variablelist>
1074           </listitem>
1075         </varlistentry>
1076
1077         <varlistentry>
1078           <term>
1079             <literal>extra-libraries</literal>
1080             <indexterm><primary><literal>extra-libraries</literal></primary><secondary>package specification</secondary></indexterm>
1081           </term>
1082           <listitem>
1083             <para>(string list) A list of extra libraries for this package.  The
1084             difference between <literal>hs-libraries</literal> and
1085             <literal>extra-libraries</literal> is that
1086             <literal>hs-libraries</literal> normally have several
1087             versions, to support profiling, parallel and other build
1088             options.  The various versions are given different
1089             suffixes to distinguish them, for example the profiling
1090             version of the standard prelude library is named
1091             <filename>libHSbase_p.a</filename>, with the
1092             <literal>_p</literal> indicating that this is a profiling
1093             version.  The suffix is added automatically by GHC for
1094             <literal>hs-libraries</literal> only, no suffix is added
1095             for libraries in
1096             <literal>extra-libraries</literal>.</para>
1097
1098             <para>The libraries listed in
1099             <literal>extra-libraries</literal> may be any libraries
1100             supported by your system's linker, including dynamic
1101             libraries (<literal>.so</literal> on Unix,
1102             <literal>.DLL</literal> on Windows).</para>
1103
1104             <para>Also, <literal>extra-libraries</literal> are placed
1105             on the linker command line after the
1106             <literal>hs-libraries</literal> for the same package.  If
1107             your package has dependencies in the other direction (i.e.
1108             <literal>extra-libraries</literal> depends on
1109             <literal>hs-libraries</literal>), and the libraries are
1110             static, you might need to make two separate
1111             packages.</para>
1112           </listitem>
1113         </varlistentry>
1114
1115         <varlistentry>
1116           <term>
1117             <literal>include-dirs</literal>
1118             <indexterm><primary><literal>include-dirs</literal></primary><secondary>package specification</secondary></indexterm>
1119           </term>
1120           <listitem>
1121             <para>(string list) A list of directories containing C includes for this
1122             package.</para>
1123           </listitem>
1124         </varlistentry>
1125
1126         <varlistentry>
1127           <term>
1128            <literal>includes</literal>
1129            <indexterm><primary><literal>includes</literal></primary><secondary>package specification</secondary></indexterm>
1130           </term>
1131           <listitem>
1132             <para>(string list) A list of files to include for via-C compilations
1133             using this package.  Typically the include file(s) will
1134             contain function prototypes for any C functions used in
1135             the package, in case they end up being called as a result
1136             of Haskell functions from the package being
1137             inlined.</para>
1138           </listitem>
1139         </varlistentry>
1140
1141         <varlistentry>
1142           <term>
1143             <literal>depends</literal>
1144             <indexterm><primary><literal>depends</literal></primary><secondary>package specification</secondary></indexterm>
1145           </term>
1146           <listitem>
1147             <para>(package name list) Packages on which this package depends.  This field contains
1148             packages with explicit versions are required, except that when
1149             submitting a package to <literal>ghc-pkg register</literal>, the
1150             versions will be filled in if they are unambiguous.</para>
1151           </listitem>
1152         </varlistentry>
1153
1154         <varlistentry>
1155           <term>
1156             <literal>hugs-options</literal>
1157             <indexterm><primary><literal>hugs-options</literal></primary><secondary>package specification</secondary></indexterm>
1158           </term>
1159           <listitem>
1160             <para>(string list) Options to pass to Hugs for this package.</para>
1161           </listitem>
1162         </varlistentry>
1163
1164         <varlistentry>
1165           <term>
1166             <literal>cc-options</literal>
1167             <indexterm><primary><literal>cc-options</literal></primary><secondary>package specification</secondary></indexterm>
1168           </term>
1169           <listitem>
1170             <para>(string list) Extra arguments to be added to the gcc command line
1171             when this package is being used (only for via-C
1172             compilations).</para>
1173           </listitem>
1174         </varlistentry>
1175
1176         <varlistentry>
1177           <term>
1178             <literal>ld-options</literal>
1179             <indexterm><primary><literal>ld-options</literal></primary><secondary>package specification</secondary></indexterm>
1180           </term>
1181           <listitem>
1182             <para>(string list) Extra arguments to be added to the
1183             <command>gcc</command> command line (for linking) when
1184             this package is being used.</para>
1185           </listitem>
1186         </varlistentry>
1187         
1188         <varlistentry>
1189           <term>
1190             <literal>framework-dirs</literal>
1191             <indexterm><primary><literal>framework-dirs</literal></primary><secondary>package specification</secondary></indexterm>
1192           </term>
1193           <listitem>
1194             <para>(string list) On Darwin/MacOS X, a list of directories containing
1195             frameworks for this package. This corresponds to the
1196             <option>-framework-path</option> option. It is ignored on all other
1197             platforms.</para>
1198           </listitem>
1199         </varlistentry>
1200
1201         <varlistentry>
1202           <term>
1203             <literal>frameworks</literal>
1204             <indexterm><primary><literal>frameworks</literal></primary><secondary>package specification</secondary></indexterm>
1205           </term>
1206           <listitem>
1207             <para>(string list) On Darwin/MacOS X, a list of frameworks to link to. This
1208             corresponds to the <option>-framework</option> option. Take a look
1209             at Apple's developer documentation to find out what frameworks
1210             actually are. This entry is ignored on all other platforms.</para>
1211           </listitem>
1212         </varlistentry>
1213
1214         <varlistentry>
1215           <term>
1216             <literal>haddock-interfaces</literal>
1217             <indexterm><primary><literal>haddock-interfaces</literal></primary><secondary>package specification</secondary></indexterm>
1218           </term>
1219           <listitem>
1220             <para>(string list) A list of filenames containing <ulink
1221               url="http://www.haskell.org/haddock/">Haddock</ulink> interface
1222             files (<literal>.haddock</literal> files) for this package.</para>
1223           </listitem>
1224         </varlistentry>
1225
1226         <varlistentry>
1227           <term>
1228             <literal>haddock-html</literal>
1229             <indexterm><primary><literal>haddock-html</literal></primary><secondary>package specification</secondary></indexterm>
1230           </term>
1231           <listitem>
1232             <para>(optional string) The directory containing the Haddock-generated HTML
1233             for this package.</para>
1234           </listitem>
1235         </varlistentry>
1236       </variablelist>
1237       
1238 <!--  This isn't true any more.  I'm not sure if we still need it -SDM
1239       <para>
1240       The <literal>ghc-pkg</literal> tool performs expansion of
1241       environment variables occurring in input package specifications.
1242       So, if the <literal>mypkg</literal> was added to the package
1243       database as follows:
1244       </para>
1245 <screen>
1246   $ installdir=/usr/local/lib ghc-pkg -a &lt; mypkg.pkg
1247 </screen>
1248
1249       <para>
1250       The occurrence of <literal>${installdir}</literal> is replaced
1251       with <literal>/usr/local/lib</literal> in the package data that
1252       is added for <literal>mypkg</literal>.
1253       </para>
1254       
1255       <para>
1256       This feature enables the distribution of package specification
1257       files that can be easily configured when installing.
1258       </para>
1259
1260       <para>For examples of more package specifications, take a look
1261       at the <literal>package.conf</literal> in your GHC
1262       installation.</para>
1263
1264 -->
1265
1266     </sect2>
1267   </sect1>
1268
1269 <!-- Emacs stuff:
1270      ;;; Local Variables: ***
1271      ;;; mode: xml ***
1272      ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***
1273      ;;; End: ***
1274  -->