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