installing-packages.rst 59.9 KB
Newer Older
1 2 3
Configuration
=============

4 5
.. highlight:: cabal

6 7 8 9 10 11 12 13
Overview
--------

The global configuration file for ``cabal-install`` is
``~/.cabal/config``. If you do not have this file, ``cabal`` will create
it for you on the first call to ``cabal update``. Alternatively, you can
explicitly ask ``cabal`` to create it for you using

14 15 16
.. code-block:: console

    $ cabal user-config update
17

18 19 20 21
You can change the location of the global configuration file by specifying
either ``--config-file=FILE`` on the command line or by setting the
``CABAL_CONFIG`` environment variable.

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
Most of the options in this configuration file are also available as
command line arguments, and the corresponding documentation can be used
to lookup their meaning. The created configuration file only specifies
values for a handful of options. Most options are left at their default
value, which it documents; for instance,

::

    -- executable-stripping: True

means that the configuration file currently does not specify a value for
the ``executable-stripping`` option (the line is commented out), and
that the default is ``True``; if you wanted to disable stripping of
executables by default, you would change this line to

::

    executable-stripping: False

You can also use ``cabal user-config update`` to migrate configuration
files created by older versions of ``cabal``.

44 45 46 47 48 49 50 51 52 53 54
Environment variables
---------------------

Various environment variables affect ``cabal-install``.

``CABAL_CONFIG``
   The variable to find global configuration file.

``CABAL_DIR``
   Default content directory for ``cabal-install`` files.
   Default value is ``getAppUserDataDirectory "cabal"``, which is
55
   ``$HOME/.cabal`` on unix systems and ``%APPDATA%\cabal`` in Windows.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

   .. note::

       The CABAL_DIR might be dropped in the future, when
       ``cabal-install`` starts to use XDG Directory specification.

``CABAL_BUILDDIR``
    The override for default ``dist`` build directory.
    Note, the nix-style builds build directory (``dist-newstyle``)
    is not affected by this environment variable.

Configuration file discovery
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1. If ``$CABAL_CONFIG`` is set use it,
2. otherwise if ``$CABAL_DIR`` is set use ``$CABAL_DIR/config``
3. otherwise use ``getAppUserDirectory "cabal"``

If the configuration file doesn't exist ``cabal-install``
will generate the default one, with directories based on
``$CABAL_DIR`` (if set) or ``getAppUserDirectory "cabal"`` prefix.

.. note:

    If ``$CABAL_CONFIG`` is set, but the file doesn't exist,
    one will be generated with ``$CABAL_DIR`` or ``getAppUserDirectory "cabal"``
    based prefixes. In other words not the prefixes based on a
    directory part of ``$CABAL_CONFIG`` path.

85 86 87
Repository specification
------------------------

88
An important part of the configuration is the specification of the
89 90 91 92 93 94 95 96 97 98 99 100
repository. When ``cabal`` creates a default config file, it configures
the repository to be the central Hackage server:

::

    repository hackage.haskell.org
      url: http://hackage.haskell.org/

The name of the repository is given on the first line, and can be
anything; packages downloaded from this repository will be cached under
``~/.cabal/packages/hackage.haskell.org`` (or whatever name you specify;
you can change the prefix by changing the value of
101
:cfg-field:`remote-repo-cache`). If you want, you can configure multiple
102 103 104 105
repositories, and ``cabal`` will combine them and be able to download
packages from any of them.

Using secure repositories
106
^^^^^^^^^^^^^^^^^^^^^^^^^
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

For repositories that support the TUF security infrastructure (this
includes Hackage), you can enable secure access to the repository by
specifying:

::

    repository hackage.haskell.org
      url: http://hackage.haskell.org/
      secure: True
      root-keys: <root-key-IDs>
      key-threshold: <key-threshold>

The ``<root-key-IDs>`` and ``<key-threshold>`` values are used for
bootstrapping. As part of the TUF infrastructure the repository will
contain a file ``root.json`` (for instance,
http://hackage.haskell.org/root.json) which the client needs to do
verification. However, how can ``cabal`` verify the ``root.json`` file
*itself*? This is known as bootstrapping: if you specify a list of root
key IDs and a corresponding threshold, ``cabal`` will verify that the
downloaded ``root.json`` file has been signed with at least
``<key-threshold>`` keys from your set of ``<root-key-IDs>``.

You can, but are not recommended to, omit these two fields. In that case
``cabal`` will download the ``root.json`` field and use it without
verification. Although this bootstrapping step is then unsafe, all
subsequent access is secure (provided that the downloaded ``root.json``
selinger's avatar
selinger committed
134
was not tampered with). Of course, adding ``root-keys`` and
135 136 137 138 139 140
``key-threshold`` to your repository specification only shifts the
problem, because now you somehow need to make sure that the key IDs you
received were the right ones. How that is done is however outside the
scope of ``cabal`` proper.

More information about the security infrastructure can be found at
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
https://github.com/haskell/hackage-security.

Local no-index repositories
^^^^^^^^^^^^^^^^^^^^^^^^^^^

It's possible to use a directory of `.tar.gz` package files as a local package
repository.

::

    repository my-local-repository
      url: file+noindex:///absolute/path/to/directory

``cabal`` will construct the index automatically from the
``package-name-version.tar.gz`` files in the directory, and will use optional
corresponding ``package-name-version.cabal`` files as new revisions.

The index is cached inside the given directory. If the directory is not
writable, you can append ``#shared-cache`` fragment to the URI,
then the cache will be stored inside the :cfg-field:`remote-repo-cache` directory.
The part of the path will be used to determine the cache key part.

163 164 165 166 167
.. note::
    ``cabal-install`` creates a ``.cache`` file, and will aggressively use
    it contents if it exists. Therefore if you change the contents of
    the directory, remember to wipe the cache too.

168 169 170 171
.. note::
    The URI scheme ``file:`` is interpreted as a remote repository,
    as described in the previous sections, thus requiring manual construction
    of ``01-index.tar`` file.
172 173

Legacy repositories
174
^^^^^^^^^^^^^^^^^^^
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

Currently ``cabal`` supports two kinds of “legacy” repositories. The
first is specified using

::

    remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive

This is just syntactic sugar for

::

    repository hackage.haskell.org
      url: hackage.haskell.org:http://hackage.haskell.org/packages/archive

although, in (and only in) the specific case of Hackage, the URL
``http://hackage.haskell.org/packages/archive`` will be silently
translated to ``http://hackage.haskell.org/``.

194
The second kind of legacy repositories are so-called “(legacy) local”
195 196 197 198 199 200 201 202 203 204 205 206
repositories:

::

    local-repo: my-local-repo:/path/to/local/repo

This can be used to access repositories on the local file system.
However, the layout of these local repositories is different from the
layout of remote repositories, and usage of these local repositories is
deprecated.

Secure local repositories
207
^^^^^^^^^^^^^^^^^^^^^^^^^
208 209 210 211

If you want to use repositories on your local file system, it is
recommended instead to use a *secure* local repository:

212
::
213 214 215 216 217 218 219 220

    repository my-local-repo
      url: file:/path/to/local/repo
      secure: True
      root-keys: <root-key-IDs>
      key-threshold: <key-threshold>

The layout of these secure local repos matches the layout of remote
221
repositories exactly; the :hackage-pkg:`hackage-repo-tool`
222 223
can be used to create and manage such repositories.

224 225
.. _installing-packages:

226 227 228
Building and installing packages
================================

229 230
.. highlight:: console

231 232 233
After you've unpacked a Cabal package, you can build it by moving into
the root directory of the package and running the ``cabal`` tool there:

234 235 236
::

    $ cabal [command] [option...]
237 238 239 240 241 242

The *command* argument selects a particular step in the build/install
process.

You can also get a summary of the command syntax with

243 244 245
::

    $ cabal help
246 247 248 249

Alternatively, you can also use the ``Setup.hs`` or ``Setup.lhs``
script:

250 251 252
::

    $ runhaskell Setup.hs [command] [option...]
253 254 255

For the summary of the command syntax, run:

256 257 258
::

    $ cabal help
259 260 261

or

262 263 264
::

    $ runhaskell Setup.hs --help
265 266 267 268

Building and installing a system package
----------------------------------------

269
::
270

271 272 273
    $ runhaskell Setup.hs configure --ghc
    $ runhaskell Setup.hs build
    $ runhaskell Setup.hs install
274 275 276 277 278 279 280 281 282

The first line readies the system to build the tool using GHC; for
example, it checks that GHC exists on the system. The second line
performs the actual building, while the last both copies the build
results to some permanent place and registers the package with GHC.

Building and installing a user package
--------------------------------------

283
::
284

285 286 287
    $ runhaskell Setup.hs configure --user
    $ runhaskell Setup.hs build
    $ runhaskell Setup.hs install
288 289

The package is installed under the user's home directory and is
290
registered in the user's package database (:option:`setup configure --user`).
291 292 293 294 295

Installing packages from Hackage
--------------------------------

The ``cabal`` tool also can download, configure, build and install a
296
Hackage_ package and all of its
297 298 299 300
dependencies in a single step. To do this, run:

::

301
   $ cabal install [PACKAGE...]
302 303

To browse the list of available packages, visit the
304
Hackage_ web site.
305 306 307 308 309 310 311 312 313 314 315


Creating a binary package
-------------------------

When creating binary packages (e.g. for Red Hat or Debian) one needs to
create a tarball that can be sent to another system for unpacking in the
root directory:

::

316 317 318 319
    $ runhaskell Setup.hs configure --prefix=/usr
    $ runhaskell Setup.hs build
    $ runhaskell Setup.hs copy --destdir=/tmp/mypkg
    $ tar -czf mypkg.tar.gz /tmp/mypkg/
320 321 322 323 324

If the package contains a library, you need two additional steps:

::

325 326
    $ runhaskell Setup.hs register --gen-script
    $ runhaskell Setup.hs unregister --gen-script
327 328 329 330 331 332 333 334 335 336

This creates shell scripts ``register.sh`` and ``unregister.sh``, which
must also be sent to the target system. After unpacking there, the
package must be registered by running the ``register.sh`` script. The
``unregister.sh`` script would be used in the uninstall procedure of the
package. Similar steps may be used for creating binary packages for
Windows.

The following options are understood by all commands:

337 338 339 340
.. program:: setup

.. option:: --help, -h or -?

341
    List the available options for the command.
342 343 344

.. option:: --verbose=n or -v n

345 346 347
    Set the verbosity level (0-3). The normal level is 1; a missing *n*
    defaults to 2.

348 349 350 351 352 353 354 355 356
    There is also an extended version of this command which can be
    used to fine-tune the verbosity of output.  It takes the
    form ``[silent|normal|verbose|debug]``\ *flags*, where *flags*
    is a list of ``+`` flags which toggle various aspects of
    output.  At the moment, only ``+callsite`` and ``+callstack``
    are supported, which respectively toggle call site and call
    stack printing (these are only supported if Cabal
    is built with a sufficiently recent GHC.)

357 358 359 360
The various commands and the additional options they support are
described below. In the simple build infrastructure, any other options
will be reported as errors.

361 362
.. _setup-configure:

363 364 365
setup configure
---------------

366 367
.. program:: setup configure

368 369 370 371 372 373 374 375 376 377 378 379 380 381
Prepare to build the package. Typically, this step checks that the
target platform is capable of building the package, and discovers
platform-specific features that are needed during the build.

The user may also adjust the behaviour of later stages using the options
listed in the following subsections. In the simple build infrastructure,
the values supplied via these options are recorded in a private file
read by later stages.

If a user-supplied ``configure`` script is run (see the section on
`system-dependent
parameters <developing-packages.html#system-dependent-parameters>`__ or
on `complex
packages <developing-packages.html#more-complex-packages>`__), it is
382
passed the :option:`--with-hc-pkg`, :option:`--prefix`, :option:`--bindir`,
Christiaan Baaij's avatar
Christiaan Baaij committed
383
:option:`--libdir`, :option:`--dynlibdir`, :option:`--datadir`, :option:`--libexecdir` and
384 385 386
:option:`--sysconfdir` options. In addition the value of the
:option:`--with-compiler` option is passed in a :option:`--with-hc-pkg` option
and all options specified with :option:`--configure-option` are passed on.
387

388 389 390 391 392 393 394
.. note::
   `GNU autoconf places restrictions on paths, including the directory
   that the package is built from.
   <https://www.gnu.org/software/autoconf/manual/autoconf.html#File-System-Conventions>`_
   The errors produced when this happens can be obscure; Cabal attempts to
   detect and warn in this situation, but it is not perfect.

395
In Cabal 2.0, support for a single positional argument was added to
396 397
``setup configure`` This makes Cabal configure the specific component to
be configured. Specified names can be qualified with ``lib:`` or
398 399 400 401
``exe:`` in case just a name is ambiguous (as would be the case for a
package named ``p`` which has a library and an executable named ``p``.)
This has the following effects:

402
-  Subsequent invocations of ``cabal build``, ``register``, etc. operate only
403 404 405 406
   on the configured component.

-  Cabal requires all "internal" dependencies (e.g., an executable
   depending on a library defined in the same package) must be found in
407
   the set of databases via :option:`--package-db` (and related flags): these
408
   dependencies are assumed to be up-to-date. A dependency can be
409
   explicitly specified using :option:`--dependency` simply by giving the name
410 411 412 413 414
   of the internal library; e.g., the dependency for an internal library
   named ``foo`` is given as
   ``--dependency=pkg-internal=pkg-1.0-internal-abcd``.

-  Only the dependencies needed for the requested component are
415 416
   required. Similarly, when :option:`--exact-configuration` is specified,
   it's only necessary to specify :option:`--dependency` for the component.
417 418 419
   (As mentioned previously, you *must* specify internal dependencies as
   well.)

420 421
-  Internal ``build-tool-depends`` and ``build-tools`` dependencies are expected
   to be in the ``PATH`` upon subsequent invocations of ``setup``.
422 423 424 425 426

Full details can be found in the `Componentized Cabal
proposal <https://github.com/ezyang/ghc-proposals/blob/master/proposals/0000-componentized-cabal.rst>`__.

Programs used for building
427
^^^^^^^^^^^^^^^^^^^^^^^^^^
428 429 430 431

The following options govern the programs used to process the source
files of a package:

432 433
.. option:: --ghc or -g, --jhc, --lhc, --uhc

434 435 436 437
    Specify which Haskell implementation to use to build the package. At
    most one of these flags may be given. If none is given, the
    implementation under which the setup script was compiled or
    interpreted is used.
438 439 440

.. option:: --with-compiler=path or -w *path*

441 442 443 444
    Specify the path to a particular compiler. If given, this must match
    the implementation selected above. The default is to search for the
    usual name of the selected implementation.

445
    This flag also sets the default value of the :option:`--with-hc-pkg`
446 447
    option to the package tool for this compiler. Check the output of
    ``setup configure -v`` to ensure that it finds the right package
448 449 450
    tool (or use :option:`--with-hc-pkg` explicitly).

.. option:: --with-hc-pkg=path
451 452 453

    Specify the path to the package tool, e.g. ``ghc-pkg``. The package
    tool must be compatible with the compiler specified by
454
    :option:`--with-compiler`. If this option is omitted, the default value is
455
    determined from the compiler selected.
456 457 458

.. option:: --with-prog=path

459 460 461 462 463 464 465
    Specify the path to the program *prog*. Any program known to Cabal
    can be used in place of *prog*. It can either be a fully path or the
    name of a program that can be found on the program search path. For
    example: ``--with-ghc=ghc-6.6.1`` or
    ``--with-cpphs=/usr/local/bin/cpphs``. The full list of accepted
    programs is not enumerated in this user guide. Rather, run
    ``cabal install --help`` to view the list.
466 467 468

.. option:: --prog-options=options

469 470 471 472 473 474 475
    Specify additional options to the program *prog*. Any program known
    to Cabal can be used in place of *prog*. For example:
    ``--alex-options="--template=mytemplatedir/"``. The *options* is
    split into program options based on spaces. Any options containing
    embedded spaced need to be quoted, for example
    ``--foo-options='--bar="C:\Program File\Bar"'``. As an alternative
    that takes only one option at a time but avoids the need to quote,
476 477 478 479
    use :option:`--prog-option` instead.

.. option:: --prog-option=option

480 481
    Specify a single additional option to the program *prog*. For
    passing an option that contain embedded spaces, such as a file name
482 483 484
    with embedded spaces, using this rather than :option:`--prog-options`
    means you do not need an additional level of quoting. Of course if you
    are using a command shell you may still need to quote, for example
485 486
    ``--foo-options="--bar=C:\Program File\Bar"``.

487 488
All of the options passed with either :option:`--prog-options`
or :option:`--prog-option` are passed in the order they were
489 490 491
specified on the configure command line.

Installation paths
492
^^^^^^^^^^^^^^^^^^
493 494 495 496

The following options govern the location of installed files from a
package:

497 498
.. option:: --prefix=dir

499 500 501 502 503 504 505 506 507
    The root of the installation. For example for a global install you
    might use ``/usr/local`` on a Unix system, or ``C:\Program Files``
    on a Windows system. The other installation paths are usually
    subdirectories of *prefix*, but they don't have to be.

    In the simple build system, *dir* may contain the following path
    variables: ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``,
    ``$os``, ``$arch``, ``$abi``, ``$abitag``

508 509
.. option:: --bindir=dir

510 511 512 513
    Executables that the user might invoke are installed here.

    In the simple build system, *dir* may contain the following path
    variables: ``$prefix``, ``$pkgid``, ``$pkg``, ``$version``,
514
    ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag``
515

516 517
.. option:: --libdir=dir

518 519 520 521 522 523 524
    Object-code libraries are installed here.

    In the simple build system, *dir* may contain the following path
    variables: ``$prefix``, ``$bindir``, ``$pkgid``, ``$pkg``,
    ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``,
    ``$abitag``

Christiaan Baaij's avatar
Christiaan Baaij committed
525 526 527 528 529 530 531 532 533 534 535 536
.. option:: --dynlibdir=dir

    Dynamic libraries are installed here.

    By default, this is set to `$libdir/$abi`, which is usually not equal to
    `$libdir/$libsubdir`.

    In the simple build system, *dir* may contain the following path
    variables: ``$prefix``, ``$bindir``, ``$libdir``, ``$pkgid``, ``$pkg``,
    ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``,
    ``$abitag``

537 538
.. option:: --libexecdir=dir

539 540 541 542 543 544 545 546
    Executables that are not expected to be invoked directly by the user
    are installed here.

    In the simple build system, *dir* may contain the following path
    variables: ``$prefix``, ``$bindir``, ``$libdir``, ``$libsubdir``,
    ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``, ``$os``,
    ``$arch``, ``$abi``, ``$abitag``

547 548
.. option:: --datadir=dir

549 550 551 552 553 554 555
    Architecture-independent data files are installed here.

    In the simple build system, *dir* may contain the following path
    variables: ``$prefix``, ``$bindir``, ``$libdir``, ``$libsubdir``,
    ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``, ``$os``,
    ``$arch``, ``$abi``, ``$abitag``

556 557
.. option:: --sysconfdir=dir

558 559 560 561 562 563 564 565 566 567
    Installation directory for the configuration files.

    In the simple build system, *dir* may contain the following path
    variables: ``$prefix``, ``$bindir``, ``$libdir``, ``$libsubdir``,
    ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``, ``$os``,
    ``$arch``, ``$abi``, ``$abitag``

In addition the simple build system supports the following installation
path options:

568 569
.. option:: --libsubdir=dir

570 571 572 573 574
    A subdirectory of *libdir* in which libraries are actually installed. For
    example, in the simple build system on Unix, the default *libdir* is
    ``/usr/local/lib``, and *libsubdir* contains the compiler ABI and package
    identifier,
    e.g. ``x86_64-linux-ghc-8.0.2/mypkg-0.1.0-IxQNmCA7qrSEQNkoHSF7A``, so
575
    libraries would be installed in
576
    ``/usr/local/lib/x86_64-linux-ghc-8.0.2/mypkg-0.1.0-IxQNmCA7qrSEQNkoHSF7A/``.
577 578

    *dir* may contain the following path variables: ``$pkgid``,
579 580 581 582 583
    ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``,
    ``$abitag``

.. option:: --libexecsubdir=dir

584 585 586 587 588
    A subdirectory of *libexecdir* in which private executables are
    installed. For example, in the simple build system on Unix, the default
    *libexecdir* is ``/usr/local/libexec``, and *libsubdir* is
    ``x86_64-linux-ghc-8.0.2/mypkg-0.1.0``, so private executables would be
    installed in ``/usr/local/libexec/x86_64-linux-ghc-8.0.2/mypkg-0.1.0/``
589 590

    *dir* may contain the following path variables: ``$pkgid``,
591 592 593
    ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``,
    ``$abitag``

594 595
.. option:: --datasubdir=dir

596 597 598 599 600 601 602
    A subdirectory of *datadir* in which data files are actually
    installed.

    *dir* may contain the following path variables: ``$pkgid``,
    ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``,
    ``$abitag``

603 604
.. option:: --docdir=dir

605 606 607 608 609 610 611
    Documentation files are installed relative to this directory.

    *dir* may contain the following path variables: ``$prefix``,
    ``$bindir``, ``$libdir``, ``$libsubdir``, ``$datadir``,
    ``$datasubdir``, ``$pkgid``, ``$pkg``, ``$version``, ``$compiler``,
    ``$os``, ``$arch``, ``$abi``, ``$abitag``

612 613
.. option:: --htmldir=dir

614 615 616 617 618 619 620
    HTML documentation files are installed relative to this directory.

    *dir* may contain the following path variables: ``$prefix``,
    ``$bindir``, ``$libdir``, ``$libsubdir``, ``$datadir``,
    ``$datasubdir``, ``$docdir``, ``$pkgid``, ``$pkg``, ``$version``,
    ``$compiler``, ``$os``, ``$arch``, ``$abi``, ``$abitag``

621 622
.. option:: --program-prefix=prefix

623 624 625 626 627 628
    Prepend *prefix* to installed program names.

    *prefix* may contain the following path variables: ``$pkgid``,
    ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``,
    ``$abitag``

629 630
.. option:: --program-suffix=suffix

631 632 633 634 635 636 637 638 639 640
    Append *suffix* to installed program names. The most obvious use for
    this is to append the program's version number to make it possible
    to install several versions of a program at once:
    ``--program-suffix='$version'``.

    *suffix* may contain the following path variables: ``$pkgid``,
    ``$pkg``, ``$version``, ``$compiler``, ``$os``, ``$arch``, ``$abi``,
    ``$abitag``

Path variables in the simple build system
641
"""""""""""""""""""""""""""""""""""""""""
642 643 644 645 646 647 648 649 650

For the simple build system, there are a number of variables that can be
used when specifying installation paths. The defaults are also specified
in terms of these variables. A number of the variables are actually for
other paths, like ``$prefix``. This allows paths to be specified
relative to each other rather than as absolute paths, which is important
for building relocatable packages (see `prefix
independence <#prefix-independence>`__).

651
$prefix
652 653 654
    The path variable that stands for the root of the installation. For
    an installation to be relocatable, all other installation paths must
    be relative to the ``$prefix`` variable.
655 656
$bindir
    The path variable that expands to the path given by the :option:`--bindir`
657
    configure option (or the default).
658 659 660 661
$libdir
    As above but for :option:`--libdir`
$libsubdir
    As above but for :option:`--libsubdir`
Christiaan Baaij's avatar
Christiaan Baaij committed
662 663
$dynlibdir
    As above but for :option:`--dynlibdir`
664 665 666 667 668 669 670
$datadir
    As above but for :option:`--datadir`
$datasubdir
    As above but for :option:`--datasubdir`
$docdir
    As above but for :option:`--docdir`
$pkgid
671
    The name and version of the package, e.g. ``mypkg-0.2``
672
$pkg
673
    The name of the package, e.g. ``mypkg``
674
$version
675
    The version of the package, e.g. ``0.2``
676
$compiler
677
    The compiler being used to build the package, e.g. ``ghc-6.6.1``
678
$os
679 680 681
    The operating system of the computer being used to build the
    package, e.g. ``linux``, ``windows``, ``osx``, ``freebsd`` or
    ``solaris``
682
$arch
683 684
    The architecture of the computer being used to build the package,
    e.g. ``i386``, ``x86_64``, ``ppc`` or ``sparc``
685
$abitag
686 687 688
    An optional tag that a compiler can use for telling incompatible
    ABI's on the same architecture apart. GHCJS encodes the underlying
    GHC version in the ABI tag.
689
$abi
690 691 692 693 694 695
    A shortcut for getting a path that completely identifies the
    platform in terms of binary compatibility. Expands to the same value
    as ``$arch-$os-compiler-$abitag`` if the compiler uses an abi tag,
    ``$arch-$os-$compiler`` if it doesn't.

Paths in the simple build system
696
""""""""""""""""""""""""""""""""
697 698 699

For the simple build system, the following defaults apply:

700 701 702 703
.. list-table:: Default installation paths

    * - Option
      - Unix Default
704
      - Windows Default
705 706
    * - :option:`--prefix` (global)
      - ``/usr/local``
707
      - ``%PROGRAMFILES%\Haskell``
708 709
    * - :option:`--prefix` (per-user)
      - ``$HOME/.cabal``
710
      - ``%APPDATA%\cabal``
711 712
    * - :option:`--bindir`
      - ``$prefix/bin``
713
      - ``$prefix\bin``
714 715
    * - :option:`--libdir`
      - ``$prefix/lib``
716
      - ``$prefix``
717 718
    * - :option:`--libsubdir` (others)
      - ``$pkgid/$compiler``
719
      - ``$pkgid\$compiler``
Christiaan Baaij's avatar
Christiaan Baaij committed
720 721 722
    * - :option:`--dynlibdir`
      - ``$libdir/$abi``
      - ``$libdir\$abi``
723 724
    * - :option:`--libexecdir`
      - ``$prefix/libexec``
725
      - ``$prefix\$pkgid``
726 727
    * - :option:`--datadir` (executable)
      - ``$prefix/share``
728
      - ``$prefix``
729 730
    * - :option:`--datadir` (library)
      - ``$prefix/share``
731
      - ``%PROGRAMFILES%\Haskell``
732 733 734 735 736
    * - :option:`--datasubdir`
      - ``$pkgid``
      - ``$pkgid``
    * - :option:`--docdir`
      - ``$datadir/doc/$pkgid``
737
      - ``$prefix\doc\$pkgid``
738 739
    * - :option:`--sysconfdir`
      - ``$prefix/etc``
740
      - ``$prefix\etc``
741 742
    * - :option:`--htmldir`
      - ``$docdir/html``
743
      - ``$docdir\html``
744 745 746 747 748 749
    * - :option:`--program-prefix`
      - (empty)
      - (empty)
    * - :option:`--program-suffix`
      - (empty)
      - (empty)
750 751

Prefix-independence
752
"""""""""""""""""""
753 754 755 756 757 758 759 760 761 762 763

On Windows it is possible to obtain the pathname of the running program.
This means that we can construct an installable executable package that
is independent of its absolute install location. The executable can find
its auxiliary files by finding its own path and knowing the location of
the other files relative to ``$bindir``. Prefix-independence is
particularly useful: it means the user can choose the install location
(i.e. the value of ``$prefix``) at install-time, rather than having to
bake the path into the binary when it is built.

In order to achieve this, we require that for an executable on Windows,
Christiaan Baaij's avatar
Christiaan Baaij committed
764
all of ``$bindir``, ``$libdir``, ``$dynlibdir``, ``$datadir`` and ``$libexecdir`` begin
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
with ``$prefix``. If this is not the case then the compiled executable
will have baked-in all absolute paths.

The application need do nothing special to achieve prefix-independence.
If it finds any files using ``getDataFileName`` and the `other functions
provided for the
purpose <developing-packages.html#accessing-data-files-from-package-code>`__,
the files will be accessed relative to the location of the current
executable.

A library cannot (currently) be prefix-independent, because it will be
linked into an executable whose file system location bears no relation
to the library package.

Controlling Flag Assignments
780
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
781 782 783 784 785

Flag assignments (see the `resolution of conditions and
flags <developing-packages.html#resolution-of-conditions-and-flags>`__)
can be controlled with the following command line options.

786 787
.. option:: -f flagname or -f -flagname

788 789 790 791
    Force the specified flag to ``true`` or ``false`` (if preceded with
    a ``-``). Later specifications for the same flags will override
    earlier, i.e., specifying ``-fdebug -f-debug`` is equivalent to
    ``-f-debug``
792 793 794

.. option:: --flags=flagspecs

795 796 797 798 799 800 801 802
    Same as ``-f``, but allows specifying multiple flag assignments at
    once. The parameter is a space-separated list of flag names (to
    force a flag to ``true``), optionally preceded by a ``-`` (to force
    a flag to ``false``). For example,
    ``--flags="debug -feature1 feature2"`` is equivalent to
    ``-fdebug -f-feature1 -ffeature2``.

Building Test Suites
803
^^^^^^^^^^^^^^^^^^^^
804

805 806
.. option:: --enable-tests

807 808 809 810 811
    Build the test suites defined in the package description file during
    the ``build`` stage. Check for dependencies required by the test
    suites. If the package is configured with this option, it will be
    possible to run the test suites with the ``test`` command after the
    package is built.
812 813 814

.. option:: --disable-tests

815 816 817 818
    (default) Do not build any test suites during the ``build`` stage.
    Do not check for dependencies required only by the test suites. It
    will not be possible to invoke the ``test`` command without
    reconfiguring the package.
819 820 821

.. option:: --enable-coverage

822 823 824
    Build libraries and executables (including test suites) with Haskell
    Program Coverage enabled. Running the test suites will automatically
    generate coverage reports with HPC.
825 826 827

.. option:: --disable-coverage

828 829 830
    (default) Do not enable Haskell Program Coverage.

Miscellaneous options
831
^^^^^^^^^^^^^^^^^^^^^
832

833 834
.. option:: --user

835 836 837 838 839 840 841
    Does a per-user installation. This changes the `default installation
    prefix <#paths-in-the-simple-build-system>`__. It also allow
    dependencies to be satisfied by the user's package database, in
    addition to the global database. This also implies a default of
    ``--user`` for any subsequent ``install`` command, as packages
    registered in the global database should not depend on packages
    registered in a user's database.
842 843 844

.. option:: --global

845 846 847 848
    (default) Does a global installation. In this case package
    dependencies must be satisfied by the global package database. All
    packages in the user's package database will be ignored. Typically
    the final installation step will require administrative privileges.
849 850 851

.. option:: --package-db=db

852 853 854 855 856 857 858
    Allows package dependencies to be satisfied from this additional
    package database *db* in addition to the global package database.
    All packages in the user's package database will be ignored. The
    interpretation of *db* is implementation-specific. Typically it will
    be a file or directory. Not all implementations support arbitrary
    package databases.

859 860
    This pushes an extra db onto the db stack. The :option:`--global` and
    :option:`--user` mode switches add the respective [Global] and [Global,
861 862 863 864 865 866 867
    User] dbs to the initial stack. There is a compiler-implementation
    constraint that the global db must appear first in the stack, and if
    the user one appears at all, it must appear immediately after the
    global db.

    To reset the stack, use ``--package-db=clear``.

868 869
.. option:: --ipid=ipid

870 871 872 873 874 875 876
    Specifies the *installed package identifier* of the package to be
    built; this identifier is passed on to GHC and serves as the basis
    for linker symbols and the ``id`` field in a ``ghc-pkg``
    registration. When a package has multiple components, the actual
    component identifiers are derived off of this identifier (e.g., an
    internal library ``foo`` from package ``p-0.1-abcd`` will get the
    identifier ``p-0.1-abcd-foo``.
877 878 879

.. option:: --cid=cid

880 881
    Specifies the *component identifier* of the component being built;
    this is only valid if you are configuring a single component.
882 883 884

.. option:: --default-user-config=file

885 886 887 888 889 890
    Allows a "default" ``cabal.config`` freeze file to be passed in
    manually. This file will only be used if one does not exist in the
    project directory already. Typically, this can be set from the
    global cabal ``config`` file so as to provide a default set of
    partial constraints to be used by projects, providing a way for
    users to peg themselves to stable package collections.
891 892 893

.. option:: --enable-optimization[=n] or -O [n]

894 895 896 897 898 899
    (default) Build with optimization flags (if available). This is
    appropriate for production use, taking more time to build faster
    libraries and programs.

    The optional *n* value is the optimisation level. Some compilers
    support multiple optimisation levels. The range is 0 to 2. Level 0
900 901 902 903 904
    is equivalent to :option:`--disable-optimization`, level 1 is the
    default if no *n* parameter is given. Level 2 is higher optimisation
    if the compiler supports it. Level 2 is likely to lead to longer
    compile times and bigger generated code.

905 906
    When optimizations are enabled, Cabal passes ``-O2`` to the C compiler.

907
.. option:: --disable-optimization
908 909 910 911

    Build without optimization. This is suited for development: building
    will be quicker, but the resulting library or programs will be
    slower.
912 913 914

.. option:: --enable-profiling

915 916 917 918 919 920 921 922 923
    Build libraries and executables with profiling enabled (for
    compilers that support profiling as a separate mode). For this to
    work, all libraries used by this package must also have been built
    with profiling support. For libraries this involves building an
    additional instance of the library in addition to the normal
    non-profiling instance. For executables it changes the single
    executable to be built in profiling mode.

    This flag covers both libraries and executables, but can be
924 925 926
    overridden by the :option:`--enable-library-profiling` flag.

    See also the :option:`--profiling-detail` flag below.
927

928
.. option:: --disable-profiling
929 930 931

    (default) Do not enable profiling in generated libraries and
    executables.
932 933 934 935

.. option:: --enable-library-profiling or -p

    As with :option:`--enable-profiling` above, but it applies only for
936 937 938
    libraries. So this generates an additional profiling instance of the
    library in addition to the normal non-profiling instance.

939
    The :option:`--enable-profiling` flag controls the profiling mode for both
940
    libraries and executables, but if different modes are desired for
941
    libraries versus executables then use :option:`--enable-library-profiling`
942 943
    as well.

944 945 946 947 948 949
.. option:: --disable-library-profiling

    (default) Do not generate an additional profiling version of the library.

.. option:: --profiling-detail[=level]

950 951 952 953 954 955 956
    Some compilers that support profiling, notably GHC, can allocate
    costs to different parts of the program and there are different
    levels of granularity or detail with which this can be done. In
    particular for GHC this concept is called "cost centers", and GHC
    can automatically add cost centers, and can do so in different ways.

    This flag covers both libraries and executables, but can be
957
    overridden by the :option:`--library-profiling-detail` flag.
958 959 960 961

    Currently this setting is ignored for compilers other than GHC. The
    levels that cabal currently supports are:

962
    default
963 964
        For GHC this uses ``exported-functions`` for libraries and
        ``toplevel-functions`` for executables.
965
    none
966
        No costs will be assigned to any code within this component.
967
    exported-functions
968 969 970
        Costs will be assigned at the granularity of all top level
        functions exported from each module. In GHC specifically, this
        is for non-inline functions.
971
    toplevel-functions
972 973 974 975
        Costs will be assigned at the granularity of all top level
        functions in each module, whether they are exported from the
        module or not. In GHC specifically, this is for non-inline
        functions.
976
    all-functions
977 978 979 980 981 982 983 984
        Costs will be assigned at the granularity of all functions in
        each module, whether top level or local. In GHC specifically,
        this is for non-inline toplevel or where-bound functions or
        values.

    This flag is new in Cabal-1.24. Prior versions used the equivalent
    of ``none`` above.

985 986 987
.. option:: --library-profiling-detail[=level]

    As with :option:`--profiling-detail` above, but it applies only for
988 989 990
    libraries.

    The level for both libraries and executables is set by the
991 992 993 994 995
    :option:`--profiling-detail` flag, but if different levels are desired
    for libraries versus executables then use
    :option:`--library-profiling-detail` as well.

.. option:: --enable-library-vanilla
996 997 998

    (default) Build ordinary libraries (as opposed to profiling
    libraries). This is independent of the
999
    :option:`--enable-library-profiling` option. If you enable both, you get
1000
    both.
1001 1002 1003

.. option:: --disable-library-vanilla

1004
    Do not build ordinary libraries. This is useful in conjunction with
1005
    :option:`--enable-library-profiling` to build only profiling libraries,
1006
    rather than profiling and ordinary libraries.
1007 1008 1009

.. option:: --enable-library-for-ghci

1010
    (default) Build libraries suitable for use with GHCi.
1011 1012 1013

.. option:: --disable-library-for-ghci

1014 1015 1016
    Not all platforms support GHCi and indeed on some platforms, trying
    to build GHCi libs fails. In such cases this flag can be used as a
    workaround.
1017 1018 1019

.. option:: --enable-split-objs

1020 1021 1022 1023 1024
    Use the GHC ``-split-objs`` feature when building the library. This
    reduces the final size of the executables that use the library by
    allowing them to link with only the bits that they use rather than
    the entire library. The downside is that building the library takes
    longer and uses considerably more memory.
1025 1026 1027

.. option:: --disable-split-objs

1028 1029 1030
    (default) Do not use the GHC ``-split-objs`` feature. This makes
    building the library quicker but the final executables that use the
    library will be larger.
1031 1032 1033

.. option:: --enable-executable-stripping

1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
    (default) When installing binary executable programs, run the
    ``strip`` program on the binary. This can considerably reduce the
    size of the executable binary file. It does this by removing
    debugging information and symbols. While such extra information is
    useful for debugging C programs with traditional debuggers it is
    rarely helpful for debugging binaries produced by Haskell compilers.

    Not all Haskell implementations generate native binaries. For such
    implementations this option has no effect.

1044 1045
.. option:: --disable-executable-stripping

1046 1047 1048 1049 1050 1051
    Do not strip binary executables during installation. You might want
    to use this option if you need to debug a program using gdb, for
    example if you want to debug the C parts of a program containing
    both Haskell and C code. Another reason is if your are building a
    package for a system which has a policy of managing the stripping
    itself (such as some Linux distributions).
1052 1053 1054

.. option:: --enable-shared

1055 1056
    Build shared library. This implies a separate compiler run to
    generate position independent code as required on most platforms.
1057 1058 1059

.. option:: --disable-shared

1060
    (default) Do not build shared library.
1061

Moritz Angermann's avatar
Moritz Angermann committed
1062 1063
.. option:: --enable-static

vedksah's avatar
vedksah committed
1064
   Build a static library. This passes ``-staticlib`` to GHC (available
Moritz Angermann's avatar
Moritz Angermann committed
1065 1066 1067 1068 1069 1070 1071
   for iOS, and with 8.4 more platforms).  The result is an archive ``.a``
   containing all dependent haskell libararies combined.

.. option:: --disable-static

    (default) Do not build a static library.

1072 1073
.. option:: --enable-executable-dynamic

1074 1075 1076
    Link dependent Haskell libraries into executables dynamically.
    The executable's library dependencies must have been
    built as shared objects. This implies :option:`--enable-shared`
1077 1078 1079 1080
    unless :option:`--disable-shared` is explicitly specified.

.. option:: --disable-executable-dynamic

1081 1082 1083
   (default) Link dependent Haskell libraries into executables statically.
   Non-Haskell (C) libraries are still linked dynamically, including libc,
   so the result is still not a fully static executable
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
1084
   unless :option:`--enable-executable-static` is given.
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094

.. option:: --enable-executable-static

    Build fully static executables.
    This link all dependent libraries into executables statically,
    including libc.

.. option:: --disable-executable-static

   (default) Do not build fully static executables.
1095 1096 1097

.. option:: --configure-option=str

1098 1099 1100 1101
    An extra option to an external ``configure`` script, if one is used
    (see the section on `system-dependent
    parameters <developing-packages.html#system-dependent-parameters>`__).
    There can be several of these options.
1102 1103 1104

.. option:: --extra-include-dirs[=dir]

1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
    An extra directory to search for C header files. You can use this
    flag multiple times to get a list of directories.

    You might need to use this flag if you have standard system header
    files in a non-standard location that is not mentioned in the
    package's ``.cabal`` file. Using this option has the same affect as
    appending the directory *dir* to the ``include-dirs`` field in each
    library and executable in the package's ``.cabal`` file. The
    advantage of course is that you do not have to modify the package at
    all. These extra directories will be used while building the package
    and for libraries it is also saved in the package registration
    information and used when compiling modules that use the library.

1118 1119
.. option:: --extra-lib-dirs[=dir]

1120 1121
    An extra directory to search for system libraries files. You can use
    this flag multiple times to get a list of directories.
1122 1123 1124

.. option:: --extra-framework-dirs[=dir]

1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
    An extra directory to search for frameworks (OS X only). You can use
    this flag multiple times to get a list of directories.

    You might need to use this flag if you have standard system
    libraries in a non-standard location that is not mentioned in the
    package's ``.cabal`` file. Using this option has the same affect as
    appending the directory *dir* to the ``extra-lib-dirs`` field in
    each library and executable in the package's ``.cabal`` file. The
    advantage of course is that you do not have to modify the package at
    all. These extra directories will be used while building the package
    and for libraries it is also saved in the package registration
    information and used when compiling modules that use the library.

1138 1139
.. option:: --dependency[=pkgname=ipid]

1140 1141
    Specify that a particular dependency should used for a particular
    package name. In particular, it declares that any reference to
Ben Gamari's avatar
Ben Gamari committed
1142 1143
    *pkgname* in a :pkg-field:`build-depends` should be resolved to
    *ipid*.
1144 1145 1146

.. option:: --exact-configuration

1147
    This changes Cabal to require every dependency be explicitly
1148
    specified using :option:`--dependency`, rather than use Cabal's (very
1149 1150
    simple) dependency solver. This is useful for programmatic use of
    Cabal's API, where you want to error if you didn't specify enough
1151 1152 1153 1154
    :option:`--dependency` flags.

.. option:: --allow-newer[=pkgs], --allow-older[=pkgs]

1155 1156 1157 1158
    Selectively relax upper or lower bounds in dependencies without
    editing the package description respectively.

    The following description focuses on upper bounds and the
1159 1160 1161
    :option:`--allow-newer` flag, but applies analogously to
    :option:`--allow-older` and lower bounds. :option:`--allow-newer`
    and :option:`--allow-older` can be used at the same time.
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194

    If you want to install a package A that depends on B >= 1.0 && <
    2.0, but you have the version 2.0 of B installed, you can compile A
    against B 2.0 by using ``cabal install --allow-newer=B A``. This
    works for the whole package index: if A also depends on C that in
    turn depends on B < 2.0, C's dependency on B will be also relaxed.

    Example:

    ::

        $ cd foo
        $ cabal configure
        Resolving dependencies...
        cabal: Could not resolve dependencies:
        [...]
        $ cabal configure --allow-newer
        Resolving dependencies...
        Configuring foo...

    Additional examples:

    ::

        # Relax upper bounds in all dependencies.
        $ cabal install --allow-newer foo

        # Relax upper bounds only in dependencies on bar, baz and quux.
        $ cabal install --allow-newer=bar,baz,quux foo

        # Relax the upper bound on bar and force bar==2.1.
        $ cabal install --allow-newer=bar --constraint="bar==2.1" foo

1195
    It's also possible to limit the scope of :option:`--allow-newer` to single
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
    packages with the ``--allow-newer=scope:dep`` syntax. This means
    that the dependency on ``dep`` will be relaxed only for the package
    ``scope``.

    Example:

    ::

        # Relax upper bound in foo's dependency on base; also relax upper bound in
        # every package's dependency on lens.
        $ cabal install --allow-newer=foo:base,lens

        # Relax upper bounds in foo's dependency on base and bar's dependency
        # on time; also relax the upper bound in the dependency on lens specified by
        # any package.
        $ cabal install --allow-newer=foo:base,lens --allow-newer=bar:time

1213
    Finally, one can enable :option:`--allow-newer` permanently by setting
1214 1215 1216 1217
    ``allow-newer: True`` in the ``~/.cabal/config`` file. Enabling
    'allow-newer' selectively is also supported in the config file
    (``allow-newer: foo, bar, baz:base``).

1218 1219
.. option:: --constraint=constraint