After you've unpacked a Cabal package, you can build it
by moving into the root directory of the package and using the
Setup.hs
or Setup.lhs
script there:
runhaskell Setup.hs
[command
] [option
...]
where runhaskell
might be
runhugs, runghc or
runnhc. The command
argument selects a particular step in the build/install process.
You can also get a summary of the command syntax with
runhaskell Setup.hs
--help
Example 7. Building and installing a system package
runhaskell Setup.hs configure --ghc runhaskell Setup.hs build runhaskell Setup.hs install
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.
Example 8. Building and installing a user package
runhaskell Setup.hs configure --ghc --user --prefix=$HOME runhaskell Setup.hs build runhaskell Setup.hs install
The package may use packages from the user's package database
as well as the global one (--user
), is installed
under the user's home directory (--prefix
),
and is registered in the user's package database
(--user
).
Example 9. Creating a binary package
When creating binary packages (e.g. for RedHat or Debian) one needs to create a tarball that can be sent to another system for unpacking in the root directory:
runhaskell Setup.hs configure --ghc --prefix=/usr runhaskell Setup.hs build runhaskell Setup.hs copy --destdir=/tmp/mypkg (cd /tmp/mypkg; tar cf - .) | gzip -9 >mypkg.tar.gz
If the package contains a library, you need two additional steps:
runhaskell Setup.hs register --gen-script runhaskell Setup.hs unregister --gen-script
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:
--help
, -h
or
-?
List the available options for the command.
--verbose
=n
or
-v
n
Set the verbosity level (0-3). The normal level is 1;
a missing n
defaults to 2.
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.
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 Section 3.3, “System-dependent parameters”
or Section 3.4, “More complex packages”), it is passed the
--with-hc-pkg
,
--prefix
, --bindir
,
--libdir
, --datadir
and
--libexecdir
options.
In addition the value of the --with-compiler
option is passed in a --with-hc
option and
all options specified with --configure-option
=
are passed on.
The following options govern the programs used to process the source files of a package:
--ghc
or -g
, --nhc
, --jhc
, --hugs
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.
--with-compiler
=path
or -w
path
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.
This flag also sets the default value of the
--with-hc-pkg
option to the package tool
for this compiler.
Check the output of setup configure -v
to ensure that it finds the right package tool (or use
--with-hc-pkg
explicitly).
--with-hc-pkg
=path
Specify the path to the package tool, e.g.
ghc-pkg.
The package tool must be compatible with the compiler
specified by --with-compiler
.
If this option is omitted, the default value is determined
from the compiler selected.
--with-prog
=path
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
.
--prog
-options
=options
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 embeded 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, use
--
instead.
prog
-option
--prog
-option
=option
Specify a single additional option to the program
prog
.
For passing an option that contain embeded spaces, such as a file
name with embeded spaces, using this rather than
--
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 prog
-options--foo-options="--bar=C:\Program File\Bar"
.
All of the options passed with either
--
or
prog
-options--
are passed
in the order they were specified on the configure command line.
prog
-option
The following options govern the location of installed files from a package:
--prefix
=dir
The root of the installation, for example
/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
--bindir
=dir
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
$compiler
--libdir
=dir
Object-code libraries are installed here.
In the simple build system, dir
may contain the following path variables:
$prefix
$bindir
$pkgid
$pkg
$version
$compiler
--libexecdir
=dir
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
--datadir
=dir
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
In addition the simple build system supports the following installation path options:
--libsubdir
=dir
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 package
identifier and compiler,
e.g. mypkg-0.2/ghc-6.4
, so libraries
would be installed in
/usr/local/lib/mypkg-0.2/ghc-6.4
.
dir
may contain the following path
variables:
$pkgid
$pkg
$version
$compiler
--datasubdir
=dir
A subdirectory of datadir
in which data files are actually installed.
dir
may contain the following path
variables:
$pkgid
$pkg
$version
$compiler
--docdir
=dir
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
--htmldir
=dir
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
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
Section 4.1.2.3, “Prefix-independence”).
$prefix
The path variable that stands for the root of the installation.
For an installation to be relocatable, all other
instllation paths must be relative to the
$prefix
variable.
$bindir
The path variable that expands to the path given by
the --bindir
configure option (or the
default).
$libdir
As above but for --libdir
$libsubdir
As above but for --libsubdir
$datadir
As above but for --datadir
$datasubdir
As above but for --datasubdir
$docdir
As above but for --docdir
$pkgid
The name and version of the package, eg
mypkg-0.2
$pkg
The name of the package, eg
mypkg
$version
The version of the package, eg
0.2
$compiler
The compiler being used to build the package, eg
ghc-6.6.1
For the simple build system, the following defaults apply:
Option | Windows Default | Unix Default |
---|---|---|
--prefix | C:\Program Files\Haskell | /usr/local |
--bindir | $prefix\bin | $prefix/bin |
--libdir | $prefix | $prefix/lib |
--libsubdir (Hugs) | hugs\packages\$pkg | hugs/packages/$pkg |
--libsubdir (others) | $pkgid\$compiler | $pkgid/$compiler |
--libexecdir | $prefix\$pkgid | $prefix/libexec |
--datadir (executable) | $prefix | $prefix/share |
--datadir (library) | C:\Program Files\Haskell | $prefix/share |
--datasubdir | $pkgid | $pkgid |
--docdir | $prefix\doc\$pkgid | $datadir/doc/$pkgid |
--htmldir | $docdir\html | $docdir/html |
On Windows, and when using Hugs on any system, 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, all
of bindir
,
libdir
,
datadir
and
libexecdir
begin 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 (see Section 3.2, “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.
Flag assignments (see Section 3.1.5.5, “Resolution of Conditions and Flags”) can be controlled with the following command line options.
-f
flagname
or
-f
-
flagname
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
--flags
=flagspecs
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
.
--user
Allow dependencies to be satisfied by the user 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.
--global
(default) Dependencies must be satisfied by the global package database.
--enable-optimization
or -O
(default) Build with optimization flags (if available). This is appropriate for production use, taking more time to build faster libraries and programs.
--disable-optimization
Build without optimization. This is suited for development: building will be quicker, but the resulting library or programs will be slower.
--enable-library-profiling
or
-p
Request that an additional version of the library with profiling features enabled be built and installed (only for implementations that support profiling).
--disable-library-profiling
(default) Do not generate an additional profiling version of the library.
--enable-executable-profiling
Any executables generated should have profiling enabled (only for implementations that support profiling). For this to work, all libraries used by these executables must also have been built with profiling support.
--disable-executable-profiling
(default) Do not enable profiling in generated executables.
--enable-library-vanilla
(default) Build ordinary libraries (as opposed to profiling
libraries). This is independent of the
--enable-library-profiling
option. If you
enable both, you get both.
--disable-library-vanilla
(default) Do not build ordinary libraries. This is useful
in conjunction with --enable-library-profiling
to build only profiling libraries, rather than profiling and
ordinary libraries.
--enable-library-for-ghci
(default) Build libraries suitable for use with GHCi.
--disable-library-for-ghci
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.
--enable-split-objs
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.
--disable-split-objs
(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.
--enable-shared
Build shared library. This implies a seperate compiler run to generate position independent code as required on most platforms.
--disable-shared
(default) Do not build shared library.
--configure-option
=str
An extra option to an external
configure
script,
if one is used (see Section 3.3, “System-dependent parameters”).
There can be several of these options.
In the simple build infrastructure, an additional option is recognized:
--scratchdir
=dir
Specify the directory into which the Hugs output will be
placed (default: dist/scratch
).
Perform any preprocessing or compilation needed to make this package ready for installation.
This command takes the following options:
--prog
-options
=options
, --prog
-option
=option
These are mostly the same as the options configure step (see Section 4.1.1, “Programs used for building”). Unlike the options specified at the configure step, any program options specified at the build step are not persistent but are used for that invocation only. They options specified at the build step are in addition not in replacement of any options specified at the configure step.
Generate a Makefile
that may be used
to compile the Haskell modules to object code.
This command is currently only supported when building libraries,
and only if the compiler is GHC.
The makefile command replaces part of the work done by
setup build
. The sequence of commands would
typically be:
runhaskell Setup.hs makefile make runhaskell Setup.hs build
where setup makefile
does the preprocessing,
make
compiles the Haskell modules, and
setup build
performs any final steps, such as
building the library archives.
The Makefile does not use GHC's --make
flag to compile the modules, instead it compiles modules one at
a time, using dependency information generated by GHC's
-M
flag. There are two reasons you might
therefore want to use setup makefile
:
You want to build in parallel using make -j
.
Currently, setup build
on its own does not support
building in parallel.
You want to build an individual module, pass extra
flags to a compilation, or do other non-standard things that
setup build
does not support.
This command takes the following options:
--file
=filename
or
-f
filename
Specify the output file (default Makefile
).
Build the documentation for the package using haddock. By
default, only the documentation for the exposed modules is generated
(see --executables
).
This command takes the following options:
--hoogle
Generate a file
dist/doc/html/
,
which can be converted by
Hoogle
into a database for searching. This is
equivalent to running haddock with the pkgid
.txt--hoogle
flag.
--html-location
=url
Specify a template for the location of HTML documentation for prerequisite packages. The substitutions listed in Section 4.1.2.2, “Paths in the simple build system” are applied to the template to obtain a location for each package, which will be used by hyperlinks in the generated documentation. For example, the following command generates links pointing at HackageDB pages:
setup haddock --html-location='http://hackage.haskell.org/packages/archive/$pkg/latest/doc/html'
Here the argument is quoted to prevent substitution by the shell.
If this option is omitted, the location for each package is obtained using the package tool (e.g. ghc-pkg).
--executables
Also run haddock for the modules of all the executable programs. By default haddock is run only on the exported modules.
--css
=path
The argument path
denotes a CSS
file, which is passed to haddock and used to set the style of
the generated documentation. This is only needed to override the
default style that haddock uses.
--hyperlink-source
Generate haddock documentation integrated with HsColour. First, HsColour is run to generate colourised code. Then haddock is run to generate HTML documentation. Each entity shown in the documentation is linked to its definition in the colourised code.
--hscolour-css
=path
The argument path
denotes a CSS
file, which is passed to HsColour as in
runhaskell Setup.hs hscolour --css=path
Produce colourised code in HTML format using HsColour.
Colourised code for exported modules is put in
dist/doc/html/
.pkgid
/src
This command takes the following options:
--executables
Also run HsColour on the sources of all executable
programs. Colourised code is put in
dist/doc/html/
.pkgid
/executable
/src
--css
=path
Copy the CSS file from path
to
dist/doc/html/
for exported modules, or to
pkgid
/src/hscolour.cssdist/doc/html/
for executable programs. The CSS file defines the actual colours
used to colourise code. Note that the
pkgid
/executable
/src/hscolour.csshscolour.css
file is required for the code
to be actually colourised.
Copy the files into the install locations and (for library packages) register the package with the compiler, i.e. make the modules it contains available to programs.
The install locations are determined by options to setup configure (see Section 4.1.2, “Installation paths”).
This command takes the following options:
--global
Register this package in the system-wide database.
(This is the default, unless the --user
option was supplied to the configure
command.)
--user
Register this package in the user's local package database.
(This is the default if the --user
option was supplied to the configure
command.)
Copy the files without registering them. This command is mainly of use to those creating binary packages.
This command takes the following option:
--destdir
=path
Specify the directory under which to place installed files. If this is not given, then the root directory is assumed.
Register this package with the compiler, i.e. make the
modules it contains available to programs. This only makes sense
for library packages. Note that the install
command incorporates this action. The main use of this
separate command is in the post-installation step for a binary
package.
This command takes the following options:
--global
Register this package in the system-wide database. (This is the default.)
--user
Register this package in the user's local package database.
--gen-script
Instead of registering the package, generate a script
containing commands to perform the registration. On Unix,
this file is called register.sh
, on
Windows, register.bat
. This script
might be included in a binary bundle, to be run after the
bundle is unpacked on the target system.
--gen-pkg-config
=[path
]Instead of registering the package, generate a package registration file. This only applies to compilers that support package registration files which at the moment is only GHC. The file should be used with the compiler's mechanism for registering packages.
This option is mainly intended for packaging systems. If
possible use the --gen-script
option instead
since it is more portable across Haskell implementations.
The path
is optional and can be
used to specify a particular output file to generate. Otherwise,
by default the file is the package name and version with a
.conf
extension.
--inplace
Registers the package for use directly from the build tree, without needing to install it. This can be useful for testing: there's no need to install the package after modifying it, just recompile and test.
This flag does not create a build-tree-local package database. It still registers the package in one of the user or global databases.
However, there are some caveats. It only works with GHC (currently). It only works if your package doesn't depend on having any supplemental files installed - plain Haskell libraries should be fine.
Deregister this package with the compiler.
This command takes the following options:
--global
Deregister this package in the system-wide database. (This is the default.)
--user
Deregister this package in the user's local package database.
--gen-script
Instead of deregistering the package, generate a script
containing commands to perform the deregistration. On Unix,
this file is called unregister.sh
, on
Windows, unregister.bat
. This script
might be included in a binary bundle, to be run on the
target system.
Remove any local files created during the
configure
, build
,
haddock
, register
or
unregister
steps, and also any files and
directories listed in the extra-tmp-files
field.
This command takes the following options:
--save-configure
or -s
Keeps the configuration information so it is not necessary to run the configure step again before building.
Run the test suite specified by the
runTests
field of
Distribution.Simple.UserHooks
. See Distribution.Simple
for information about creating hooks and using
defaultMainWithHooks
.
Create a system- and compiler-independent source distribution
in a file
in the package
-version
.tar.gzdist
subdirectory, for distribution
to package builders. When unpacked, the commands listed in this
section will be available.
The files placed in this distribution are the package
description file, the setup script, the sources of the modules
named in the package description file, and files named in the
license-file
, main-is
,
c-sources
, data-files
and
extra-source-files
fields.
This command takes the following option:
--snapshot
Append today's date
(in YYYYMMDD
form) to the version
number for the generated source package. The original
package is unaffected.