1 <?xml version="1.0" encoding="iso-8859-1"?>
6 <indexterm><primary>packages</primary></indexterm>
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
13 url="http://hackage.haskell.org/packages/hackage.html">HackageDB</ulink>.</para>
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>
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>,
30 <sect2 id="using-packages">
33 <indexterm><primary>packages</primary>
34 <secondary>using</secondary></indexterm>
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>
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
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
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>
63 $ ghc-pkg field network exposed-modules
64 exposed-modules: Network.BSD,
71 <para>The GHC command line options that control packages are:</para>
76 <option>-package <replaceable>P</replaceable></option>
77 <indexterm><primary><option>-package</option></primary></indexterm>
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>
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>
97 <para>In <option>––make</option> mode
98 and <option>––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
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>
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:
116 <screen>$ ghc -o myprog Foo.o Main.o -package network</screen>
118 The same flag is necessary even if we compiled the modules from
119 source, because GHC still reckons it's in batch mode:
121 <screen>$ ghc -o myprog Foo.hs Main.hs -package network</screen></para>
126 <term><option>-hide-all-packages</option>
127 <indexterm><primary><option>-hide-package</option></primary>
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>
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>
146 <term><option>-hide-package</option> <replaceable>P</replaceable>
147 <indexterm><primary><option>-hide-package</option></primary>
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>
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>
162 <term><option>-ignore-package</option> <replaceable>P</replaceable>
163 <indexterm><primary><option>-ignore-package</option></primary>
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>
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
181 <term><option>-package-name</option> <replaceable>foo</replaceable>
182 <indexterm><primary><option>-package-name</option></primary>
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>
198 <sect2 id="package-main">
199 <title>The main package</title>
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:
207 /usr/bin/ld: Undefined symbols:
215 <sect2 id="package-overlaps">
216 <title>Consequences of packages</title>
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>
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>
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
243 <sect2 id="package-databases">
244 <title>Package Databases</title>
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>
252 <para>The global package database, which comes with your GHC
256 <para>A package database private to each user. On Unix
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 And 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>
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>
271 <para>Package databases may overlap: for example, packages in the user
272 database will override those of the same name in the global
275 <para>You can control the loading of package databases using the following
281 <option>-package-conf <replaceable>file</replaceable></option>
282 <indexterm><primary><option>-package-conf</option></primary></indexterm>
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
294 <term><option>-no-user-package-conf</option>
295 <indexterm><primary><option>-no-user-package-conf</option></primary>
299 <para>Prevent loading of the user's local package database.</para>
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>
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>
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
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):
330 $ export GHC_PACKAGE_PATH=$HOME/.my-ghc-packages.conf:</screen>
331 (use <literal>;</literal> instead of <literal>:</literal> on
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>
341 <sect2 id="building-packages">
342 <title>Building a package from Haskell source</title>
343 <indexterm><primary>packages</primary>
344 <secondary>building</secondary></indexterm>
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>
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>
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
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
367 <listitem><para>Building a static library is done by using the
368 <literal>ar</literal> tool, like so:</para>
370 <screen>ar cqs libHSfoo-1.0.a A.o B.o C.o ...</screen>
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>
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>
389 <screen>ld -r ––whole-archive -o HSfoo.o libHSfoo.a</screen>
392 <literal>––whole-archive</literal> with
393 <literal>–all_load</literal> on MacOS X)</para>
396 <para>When building the package as shared library, GHC can be used to
397 perform the link step. This hides some of the details
398 out the underlying linker and provides a common
399 interface to all shared object variants that are supported
400 by GHC (DLLs, ELF DSOs, and Mac OS dylibs). The shared
401 object must be named in specific way for two reasons: (1)
402 the name must contain the GHC compiler version, so that two
403 library variants don't collide that are compiled by
404 different versions of GHC and that therefore are most likely
405 incompatible with respect to calling conventions, (2) it
406 must be different from the static name otherwise we would
407 not be able to control the linker as precisely as necessary
409 the <option>-static</option>/<option>-dynamic</option> flags
410 work, see <xref linkend="options-linker" />.</para>
412 <screen>ghc -shared libHSfoo-1.0-ghc<replaceable>GHCVersion</replaceable>.so A.o B.o C.o</screen>
413 <para>Using GHC's version number in the shared object name
414 allows different library versions compiled by different GHC
415 versions to be installed in standard system locations,
416 e.g. under *nix /usr/lib. To obtain the version number of
417 GHC invoke <literal>ghc --numeric-version</literal> and use
419 of <replaceable>GHCVersion</replaceable>. See also
420 <xref linkend="options-codegen" /> on how object files must
421 be prepared for shared object linking.</para>
425 <para>GHC does not maintain detailed cross-package dependency
426 information. It does remember which modules in other packages
427 the current module depends on, but not which things within
428 those imported things.</para>
430 <para>To compile a module which is to be part of a new package,
431 use the <literal>-package-name</literal> option (<xref linkend="using-packages"/>).
432 Failure to use the <literal>-package-name</literal> option
433 when compiling a package will probably result in disaster, but
434 you will only discover later when you attempt to import modules
435 from the package. At this point GHC will complain that the
436 package name it was expecting the module to come from is not the
437 same as the package name stored in the <literal>.hi</literal>
440 <para>It is worth noting with shared objects, when each package
441 is built as a single shared object file, since a reference to a shared object costs an extra
442 indirection, intra-package references are cheaper than
443 inter-package references. Of course, this applies to the
444 <filename>main</filename> package as well.</para>
447 <sect2 id="package-management">
448 <title>Package management (the <literal>ghc-pkg</literal> command)</title>
449 <indexterm><primary>packages</primary>
450 <secondary>management</secondary></indexterm>
452 <para>The <literal>ghc-pkg</literal> tool allows packages to be
453 added or removed from a package database. By default,
454 the system-wide package database is modified, but alternatively
455 the user's local package database or another specified
456 file can be used.</para>
458 <para>To see what package databases are in use, say
459 <literal>ghc-pkg list</literal>. The stack of databases that
460 <literal>ghc-pkg</literal> knows about can be modified using the
461 <literal>GHC_PACKAGE_PATH</literal> environment variable (see <xref
462 linkend="ghc-package-path" />, and using
463 <literal>--package-conf</literal> options on the
464 <literal>ghc-pkg</literal> command line.</para>
466 <para>When asked to modify a database, <literal>ghc-pkg</literal> modifies
467 the global database by default. Specifying <option>--user</option>
468 causes it to act on the user database, or <option>--package-conf</option>
469 can be used to act on another database entirely. When multiple of these
470 options are given, the rightmost one is used as the database to act
473 <para>Commands that query the package database (list, latest,
474 describe, field) operate on the list of databases specified by
475 the flags <option>--user</option>, <option>--global</option>, and
476 <option>--package-conf</option>. If none of these flags are
477 given, the default is <option>--global</option>
478 <option>--user</option>.</para>
480 <para>If the environment variable <literal>GHC_PACKAGE_PATH</literal> is
481 set, and its value does not end in a separator (<literal>:</literal> on
482 Unix, <literal>;</literal> on Windows), then the last database is
483 considered to be the global database, and will be modified by default by
484 <literal>ghc-pkg</literal>. The intention here is that
485 <literal>GHC_PACKAGE_PATH</literal> can be used to create a virtual
486 package environment into which Cabal packages can be installed without
487 setting anything other than <literal>GHC_PACKAGE_PATH</literal>.</para>
489 <para>The <literal>ghc-pkg</literal> program may be run in the ways listed
490 below. Where a package name is required, the package can be named in
491 full including the version number
492 (e.g. <literal>network-1.0</literal>), or without the version number.
493 Naming a package without the version number matches all versions of the
494 package; the specified action will be applied to all the matching
495 packages. A package specifier that matches all version of the package
496 can also be written <replaceable>pkg</replaceable><literal>-*</literal>,
497 to make it clearer that multiple packages are being matched.</para>
501 <term><literal>ghc-pkg register <replaceable>file</replaceable></literal></term>
503 <para>Reads a package specification from
504 <replaceable>file</replaceable> (which may be “<literal>-</literal>”
505 to indicate standard input),
506 and adds it to the database of installed packages. The syntax of
507 <replaceable>file</replaceable> is given in <xref
508 linkend="installed-pkg-info" />.</para>
510 <para>The package specification must be a package that isn't already
516 <term><literal>ghc-pkg update <replaceable>file</replaceable></literal></term>
518 <para>The same as <literal>register</literal>, except that if a
519 package of the same name is already installed, it is
520 replaced by the new one.</para>
525 <term><literal>ghc-pkg unregister <replaceable>P</replaceable></literal></term>
527 <para>Remove the specified package from the database.</para>
532 <term><literal>ghc-pkg expose <replaceable>P</replaceable></literal></term>
534 <para>Sets the <literal>exposed</literal> flag for package
535 <replaceable>P</replaceable> to <literal>True</literal>.</para>
540 <term><literal>ghc-pkg check</literal></term>
542 <para>Check consistency of dependencies in the package
543 database, and report packages that have missing
549 <term><literal>ghc-pkg hide <replaceable>P</replaceable></literal></term>
551 <para>Sets the <literal>exposed</literal> flag for package
552 <replaceable>P</replaceable> to <literal>False</literal>.</para>
557 <term><literal>ghc-pkg list [<replaceable>P</replaceable>] [<option>--simple-output</option>]</literal></term>
559 <para>This option displays the currently installed
560 packages, for each of the databases known to
561 <literal>ghc-pkg</literal>. That includes the global database, the
562 user's local database, and any further files specified using the
563 <option>-f</option> option on the command line.</para>
565 <para>Hidden packages (those for which the <literal>exposed</literal>
566 flag is <literal>False</literal>) are shown in parentheses in the
567 list of packages.</para>
569 <para>If an optional package identifier <replaceable>P</replaceable>
570 is given, then only packages matching that identifier are
573 <para>If the option <option>--simple-output</option> is given, then
574 the packages are listed on a single line separated by spaces, and
575 the database names are not included. This is intended to make it
576 easier to parse the output of <literal>ghc-pkg list</literal> using
582 <term><literal>ghc-pkg find-module <replaceable>M</replaceable> [<option>--simple-output</option>]</literal></term>
584 <para>This option lists registered packages exposing module
585 <replaceable>M</replaceable>. Examples:</para>
587 $ ghc-pkg find-module Var
588 c:/fptools/validate/ghc/driver/package.conf.inplace:
591 $ ghc-pkg find-module Data.Sequence
592 c:/fptools/validate/ghc/driver/package.conf.inplace:
595 <para>Otherwise, it behaves like <literal>ghc-pkg list</literal>,
596 including options.</para>
602 <term><literal>ghc-pkg latest <replaceable>P</replaceable></literal></term>
604 <para>Prints the latest available version of package
605 <replaceable>P</replaceable>.</para>
610 <term><literal>ghc-pkg describe <replaceable>P</replaceable></literal></term>
612 <para>Emit the full description of the specified package. The
613 description is in the form of an
614 <literal>InstalledPackageInfo</literal>, the same as the input file
615 format for <literal>ghc-pkg register</literal>. See <xref
616 linkend="installed-pkg-info" /> for details.</para>
618 <para>If the pattern matches multiple packages, the
619 description for each package is emitted, separated by the
620 string <literal>---</literal> on a line by itself.</para>
625 <term><literal>ghc-pkg field <replaceable>P</replaceable> <replaceable>field</replaceable>[,<replaceable>field</replaceable>]*</literal></term>
627 <para>Show just a single field of the installed package description
628 for <literal>P</literal>. Multiple fields can be selected by separating
629 them with commas</para>
634 <term><literal>ghc-pkg dump</literal></term>
636 <para>Emit the full description of every package, in the
637 form of an <literal>InstalledPackageInfo</literal>.
638 Multiple package descriptions are separated by the
639 string <literal>---</literal> on a line by itself.</para>
641 <para>This is almost the same as <literal>ghc-pkg describe '*'</literal>, except that <literal>ghc-pkg dump</literal>
642 is intended for use by tools that parse the results, so
643 for example where <literal>ghc-pkg describe '*'</literal>
644 will emit an error if it can't find any packages that
645 match the pattern, <literal>ghc-pkg dump</literal> will
646 simply emit nothing.</para>
652 Substring matching is supported for <replaceable>M</replaceable> in
653 <literal>find-module</literal> and for <replaceable>P</replaceable> in
654 <literal>list</literal>, <literal>describe</literal>, and
655 <literal>field</literal>, where a <literal>'*'</literal> indicates open
656 substring ends (<literal>prefix*</literal>, <literal>*suffix</literal>,
657 <literal>*infix*</literal>). Examples (output omitted):
660 -- list all regex-related packages
661 ghc-pkg list '*regex*' --ignore-case
662 -- list all string-related packages
663 ghc-pkg list '*string*' --ignore-case
664 -- list OpenGL-related packages
665 ghc-pkg list '*gl*' --ignore-case
666 -- list packages exporting modules in the Data hierarchy
667 ghc-pkg find-module 'Data.*'
668 -- list packages exporting Monad modules
669 ghc-pkg find-module '*Monad*'
670 -- list names and maintainers for all packages
671 ghc-pkg field '*' name,maintainer
672 -- list location of haddock htmls for all packages
673 ghc-pkg field '*' haddock-html
674 -- dump the whole database
678 <para>Additionally, the following flags are accepted by
679 <literal>ghc-pkg</literal>:</para>
684 <option>––auto-ghci-libs</option><indexterm><primary><option>––auto-ghci-libs</option></primary>
688 <para>Automatically generate the GHCi
689 <filename>.o</filename> version of each
690 <filename>.a</filename> Haskell library, using GNU ld (if
691 that is available). Without this option,
692 <literal>ghc-pkg</literal> will warn if GHCi versions of
693 any Haskell libraries in the package don't exist.</para>
695 <para>GHCi <literal>.o</literal> libraries don't
696 necessarily have to live in the same directory as the
697 corresponding <literal>.a</literal> library. However,
698 this option will cause the GHCi library to be created in
699 the same directory as the <literal>.a</literal>
706 <option>-f</option> <replaceable>file</replaceable>
707 <indexterm><primary><option>-f</option></primary>
711 <option>-package-conf</option> <replaceable>file</replaceable>
712 <indexterm><primary><option>-package-conf</option></primary>
716 <para>Adds <replaceable>file</replaceable> to the stack of package
717 databases. Additionally, <replaceable>file</replaceable> will
718 also be the database modified by a <literal>register</literal>,
719 <literal>unregister</literal>, <literal>expose</literal> or
720 <literal>hide</literal> command, unless it is overridden by a later
721 <option>--package-conf</option>, <option>--user</option> or
722 <option>--global</option> option.</para>
728 <option>––force</option>
730 <option>––force</option>
731 </primary></indexterm>
734 <para>Causes <literal>ghc-pkg</literal> to ignore missing
735 dependencies, directories and libraries when registering a package,
736 and just go ahead and add it anyway. This might be useful if your
737 package installation system needs to add the package to
738 GHC before building and installing the files.</para>
744 <option>––global</option><indexterm><primary><option>––global</option></primary>
748 <para>Operate on the global package database (this is the default).
749 This flag affects the <literal>register</literal>,
750 <literal>update</literal>, <literal>unregister</literal>,
751 <literal>expose</literal>, and <literal>hide</literal>
758 <option>––help</option><indexterm><primary><option>––help</option></primary>
762 <option>-?</option><indexterm><primary><option>-?</option></primary>
766 <para>Outputs the command-line syntax.</para>
772 <option>––user</option><indexterm><primary><option>––user</option></primary>
776 <para>Operate on the current user's local package database.
777 This flag affects the <literal>register</literal>,
778 <literal>update</literal>, <literal>unregister</literal>,
779 <literal>expose</literal>, and <literal>hide</literal>
786 <option>-V</option><indexterm><primary><option>-V</option></primary>
790 <option>––version</option><indexterm><primary><option>––version</option></primary>
794 <para>Output the <literal>ghc-pkg</literal> version number.</para>
799 <para>When modifying the package database
800 <replaceable>file</replaceable>, a copy of the original file is
801 saved in <replaceable>file</replaceable><literal>.old</literal>,
802 so in an emergency you can always restore the old settings by
803 copying the old file back again.</para>
807 <sect2 id="installed-pkg-info">
809 <literal>InstalledPackageInfo</literal>: a package specification
812 <para>A package specification is a Haskell record; in particular, it is the
814 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>
816 <para>An <literal>InstalledPackageInfo</literal> has a human
817 readable/writable syntax. The functions
818 <literal>parseInstalledPackageInfo</literal> and
819 <literal>showInstalledPackageInfo</literal> read and write this syntax
820 respectively. Here's an example of the
821 <literal>InstalledPackageInfo</literal> for the <literal>unix</literal> package:</para>
824 $ ghc-pkg describe unix
829 maintainer: libraries@haskell.org
837 exposed-modules: System.Posix,
838 System.Posix.DynamicLinker.Module,
839 System.Posix.DynamicLinker.Prim,
840 System.Posix.Directory,
841 System.Posix.DynamicLinker,
846 System.Posix.Process,
847 System.Posix.Resource,
849 System.Posix.Terminal,
853 System.Posix.Signals.Exts
854 import-dirs: /usr/lib/ghc-6.4/libraries/unix
855 library-dirs: /usr/lib/ghc-6.4/libraries/unix
857 extra-libraries: HSunix_cbits, dl
858 include-dirs: /usr/lib/ghc-6.4/libraries/unix/include
863 <para>The full <ulink url="../Cabal/index.html">Cabal documentation</ulink>
864 is still in preparation (at time of writing), so in the meantime
865 here is a brief description of the syntax of this file:</para>
867 <para>A package description consists of a number of field/value pairs. A
868 field starts with the field name in the left-hand column followed by a
869 “<literal>:</literal>”, and the value continues until the next line that begins in the
870 left-hand column, or the end of file.</para>
872 <para>The syntax of the value depends on the field. The various field
877 <term>freeform</term>
879 <para>Any arbitrary string, no interpretation or parsing is
886 <para>A sequence of non-space characters, or a sequence of arbitrary
887 characters surrounded by quotes <literal>"...."</literal>.</para>
891 <term>string list</term>
893 <para>A sequence of strings, separated by commas. The sequence may
899 <para>In addition, there are some fields with special syntax (e.g. package
900 names, version, dependencies).</para>
902 <para>The allowed fields, with their types, are:</para>
907 <literal>name</literal>
908 <indexterm><primary><literal>name</literal></primary><secondary>package specification</secondary></indexterm>
911 <para>The package's name (without the version).</para>
917 <literal>version</literal>
918 <indexterm><primary><literal>version</literal></primary><secondary>package specification</secondary></indexterm>
921 <para>The package's version, usually in the form
922 <literal>A.B</literal> (any number of components are allowed).</para>
928 <literal>license</literal>
929 <indexterm><primary><literal>auto</literal></primary><secondary>package specification</secondary></indexterm>
932 <para>(string) The type of license under which this package is distributed.
933 This field is a value of the <ulink
934 url="../libraries/Cabal/Distribution-License.html#t:License"><literal>License</literal></ulink> type.</para>
940 <literal>license-file</literal>
941 <indexterm><primary><literal>license-file</literal></primary><secondary>package specification</secondary></indexterm>
944 <para>(optional string) The name of a file giving detailed license
945 information for this package.</para>
951 <literal>copyright</literal>
952 <indexterm><primary><literal>copyright</literal></primary><secondary>package specification</secondary></indexterm>
955 <para>(optional freeform) The copyright string.</para>
961 <literal>maintainer</literal>
962 <indexterm><primary><literal>maintainer</literal></primary><secondary>package specification</secondary></indexterm>
965 <para>(optinoal freeform) The email address of the package's maintainer.</para>
971 <literal>stability</literal>
972 <indexterm><primary><literal>stability</literal></primary><secondary>package specification</secondary></indexterm>
975 <para>(optional freeform) A string describing the stability of the package
976 (eg. stable, provisional or experimental).</para>
982 <literal>homepage</literal>
983 <indexterm><primary><literal>homepage</literal></primary><secondary>package specification</secondary></indexterm>
986 <para>(optional freeform) URL of the package's home page.</para>
992 <literal>package-url</literal>
993 <indexterm><primary><literal>package-url</literal></primary><secondary>package specification</secondary></indexterm>
996 <para>(optional freeform) URL of a downloadable distribution for this
997 package. The distribution should be a Cabal package.</para>
1003 <literal>description</literal>
1004 <indexterm><primary><literal>description</literal></primary><secondary>package specification</secondary></indexterm>
1007 <para>(optional freeform) Description of the package.</para>
1013 <literal>category</literal>
1014 <indexterm><primary><literal>category</literal></primary><secondary>package specification</secondary></indexterm>
1017 <para>(optinoal freeform) Which category the package belongs to. This field
1018 is for use in conjunction with a future centralised package
1019 distribution framework, tentatively titled Hackage.</para>
1025 <literal>author</literal>
1026 <indexterm><primary><literal>author</literal></primary><secondary>package specification</secondary></indexterm>
1029 <para>(optional freeform) Author of the package.</para>
1035 <literal>exposed</literal>
1036 <indexterm><primary><literal>exposed</literal></primary><secondary>package specification</secondary></indexterm>
1039 <para>(bool) Whether the package is exposed or not.</para>
1045 <literal>exposed-modules</literal>
1046 <indexterm><primary><literal>exposed-modules</literal></primary><secondary>package specification</secondary></indexterm>
1049 <para>(string list) modules exposed by this package.</para>
1055 <literal>hidden-modules</literal>
1056 <indexterm><primary><literal>hidden-modules</literal></primary><secondary>package specification</secondary></indexterm>
1059 <para>(string list) modules provided by this package,
1060 but not exposed to the programmer. These modules cannot be
1061 imported, but they are still subject to the overlapping constraint:
1062 no other package in the same program may provide a module of the
1069 <literal>import-dirs</literal>
1070 <indexterm><primary><literal>import-dirs</literal></primary><secondary>package specification</secondary></indexterm>
1073 <para>(string list) A list of directories containing interface files
1074 (<literal>.hi</literal> files) for this package.</para>
1076 <para>If the package contains profiling libraries, then
1077 the interface files for those library modules should have
1078 the suffix <literal>.p_hi</literal>. So the package can
1079 contain both normal and profiling versions of the same
1080 library without conflict (see also
1081 <literal>library_dirs</literal> below).</para>
1087 <literal>library-dirs</literal>
1088 <indexterm><primary><literal>library-dirs</literal></primary><secondary>package specification</secondary></indexterm>
1091 <para>(string list) A list of directories containing libraries for this
1098 <literal>hs-libraries</literal>
1099 <indexterm><primary><literal>hs-libraries</literal></primary><secondary>package specification</secondary></indexterm>
1102 <para>(string list) A list of libraries containing Haskell code for this
1103 package, with the <literal>.a</literal> or
1104 <literal>.dll</literal> suffix omitted. When packages are
1105 built as libraries, the
1106 <literal>lib</literal> prefix is also omitted.</para>
1108 <para>For use with GHCi, each library should have an
1109 object file too. The name of the object file does
1110 <emphasis>not</emphasis> have a <literal>lib</literal>
1111 prefix, and has the normal object suffix for your
1114 <para>For example, if we specify a Haskell library as
1115 <filename>HSfoo</filename> in the package spec, then the
1116 various flavours of library that GHC actually uses will be
1120 <term><filename>libHSfoo.a</filename></term>
1122 <para>The name of the library on Unix and Windows
1123 (mingw) systems. Note that we don't support
1124 building dynamic libraries of Haskell code on Unix
1129 <term><filename>HSfoo.dll</filename></term>
1131 <para>The name of the dynamic library on Windows
1132 systems (optional).</para>
1136 <term><filename>HSfoo.o</filename></term>
1137 <term><filename>HSfoo.obj</filename></term>
1139 <para>The object version of the library used by
1149 <literal>extra-libraries</literal>
1150 <indexterm><primary><literal>extra-libraries</literal></primary><secondary>package specification</secondary></indexterm>
1153 <para>(string list) A list of extra libraries for this package. The
1154 difference between <literal>hs-libraries</literal> and
1155 <literal>extra-libraries</literal> is that
1156 <literal>hs-libraries</literal> normally have several
1157 versions, to support profiling, parallel and other build
1158 options. The various versions are given different
1159 suffixes to distinguish them, for example the profiling
1160 version of the standard prelude library is named
1161 <filename>libHSbase_p.a</filename>, with the
1162 <literal>_p</literal> indicating that this is a profiling
1163 version. The suffix is added automatically by GHC for
1164 <literal>hs-libraries</literal> only, no suffix is added
1166 <literal>extra-libraries</literal>.</para>
1168 <para>The libraries listed in
1169 <literal>extra-libraries</literal> may be any libraries
1170 supported by your system's linker, including dynamic
1171 libraries (<literal>.so</literal> on Unix,
1172 <literal>.DLL</literal> on Windows).</para>
1174 <para>Also, <literal>extra-libraries</literal> are placed
1175 on the linker command line after the
1176 <literal>hs-libraries</literal> for the same package. If
1177 your package has dependencies in the other direction (i.e.
1178 <literal>extra-libraries</literal> depends on
1179 <literal>hs-libraries</literal>), and the libraries are
1180 static, you might need to make two separate
1187 <literal>include-dirs</literal>
1188 <indexterm><primary><literal>include-dirs</literal></primary><secondary>package specification</secondary></indexterm>
1191 <para>(string list) A list of directories containing C includes for this
1198 <literal>includes</literal>
1199 <indexterm><primary><literal>includes</literal></primary><secondary>package specification</secondary></indexterm>
1202 <para>(string list) A list of files to include for via-C compilations
1203 using this package. Typically the include file(s) will
1204 contain function prototypes for any C functions used in
1205 the package, in case they end up being called as a result
1206 of Haskell functions from the package being
1213 <literal>depends</literal>
1214 <indexterm><primary><literal>depends</literal></primary><secondary>package specification</secondary></indexterm>
1217 <para>(package name list) Packages on which this package depends. This field contains
1218 packages with explicit versions are required, except that when
1219 submitting a package to <literal>ghc-pkg register</literal>, the
1220 versions will be filled in if they are unambiguous.</para>
1226 <literal>hugs-options</literal>
1227 <indexterm><primary><literal>hugs-options</literal></primary><secondary>package specification</secondary></indexterm>
1230 <para>(string list) Options to pass to Hugs for this package.</para>
1236 <literal>cc-options</literal>
1237 <indexterm><primary><literal>cc-options</literal></primary><secondary>package specification</secondary></indexterm>
1240 <para>(string list) Extra arguments to be added to the gcc command line
1241 when this package is being used (only for via-C
1242 compilations).</para>
1248 <literal>ld-options</literal>
1249 <indexterm><primary><literal>ld-options</literal></primary><secondary>package specification</secondary></indexterm>
1252 <para>(string list) Extra arguments to be added to the
1253 <command>gcc</command> command line (for linking) when
1254 this package is being used.</para>
1260 <literal>framework-dirs</literal>
1261 <indexterm><primary><literal>framework-dirs</literal></primary><secondary>package specification</secondary></indexterm>
1264 <para>(string list) On Darwin/MacOS X, a list of directories containing
1265 frameworks for this package. This corresponds to the
1266 <option>-framework-path</option> option. It is ignored on all other
1273 <literal>frameworks</literal>
1274 <indexterm><primary><literal>frameworks</literal></primary><secondary>package specification</secondary></indexterm>
1277 <para>(string list) On Darwin/MacOS X, a list of frameworks to link to. This
1278 corresponds to the <option>-framework</option> option. Take a look
1279 at Apple's developer documentation to find out what frameworks
1280 actually are. This entry is ignored on all other platforms.</para>
1286 <literal>haddock-interfaces</literal>
1287 <indexterm><primary><literal>haddock-interfaces</literal></primary><secondary>package specification</secondary></indexterm>
1290 <para>(string list) A list of filenames containing <ulink
1291 url="http://www.haskell.org/haddock/">Haddock</ulink> interface
1292 files (<literal>.haddock</literal> files) for this package.</para>
1298 <literal>haddock-html</literal>
1299 <indexterm><primary><literal>haddock-html</literal></primary><secondary>package specification</secondary></indexterm>
1302 <para>(optional string) The directory containing the Haddock-generated HTML
1303 for this package.</para>
1308 <!-- This isn't true any more. I'm not sure if we still need it -SDM
1310 The <literal>ghc-pkg</literal> tool performs expansion of
1311 environment variables occurring in input package specifications.
1312 So, if the <literal>mypkg</literal> was added to the package
1313 database as follows:
1316 $ installdir=/usr/local/lib ghc-pkg -a < mypkg.pkg
1320 The occurrence of <literal>${installdir}</literal> is replaced
1321 with <literal>/usr/local/lib</literal> in the package data that
1322 is added for <literal>mypkg</literal>.
1326 This feature enables the distribution of package specification
1327 files that can be easily configured when installing.
1330 <para>For examples of more package specifications, take a look
1331 at the <literal>package.conf</literal> in your GHC
1332 installation.</para>
1340 ;;; Local Variables: ***
1342 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***