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 5. 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 6. 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 7. 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:
List the available options for the command.
Set the verbosity level (0-5). The normal level is 1; a missing n defaults to 3.
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, except in the case of the configure command.
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 2.3 or Section 2.4), it is passed the --with-hc, --with-hc-pkg, --prefix, --bindir, --libdir, --datadir and --libexecdir options, plus any unrecognized options.
The following options govern the programs used to process the source files of a package:
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.
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.
Specify the path to the package tool, e.g. ghc-pkg.
Specify the path to haddock.
Specify the path to happy.
Specify the path to alex.
Specify the path to hsc2hs.
Specify the path to c2hs.
Specify the path to haddock.
Specify the path to cpphs.
The following options govern the location of installed files from a package:
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.
Executables that the user might invoke are installed here.
Object-code libraries are installed here.
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.
Not all build systems make use of libsubdir, in particular the Distribution.Make system does not.
Architecture-independent data files are installed here.
A subdirectory of datadir in which data files are actually installed. This option is similar to --libsubdir in that not all build systems make use of it.
Executables that are not expected to be invoked directly by the user are installed here.
For the simple build system, the following defaults apply:
Option | Windows Default | Unix Default |
---|---|---|
--prefix | C:\Program Files | /usr/local |
--bindir | $prefix\$pkgid | $prefix/bin |
--libdir | $prefix\Haskell | $prefix/lib |
--libsubdir (Hugs) | hugs\packages\$pkg | hugs/packages/$pkg |
--libsubdir (others) | $pkgid\$compiler | $pkgid/$compiler |
--datadir (executable) | $prefix | $prefix/share |
--datadir (library) | C:\Program Files\Common Files | $prefix/share |
--datasubdir | $pkgid | $pkgid |
--libexecdir | $prefix\$pkgid | $prefix/libexec |
The following strings are substituted into directory names:
The value of prefix
The full package identifier, e.g. pkg-0.1
The compiler and version, e.g. ghc-6.4.1
The name of the package only
The version of the package
On Windows (and perhaps other OSs), it is possible to query the pathname of the running binary. 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 2.2), 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 filesystem location bears no relation to the library package.
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.
(default) Dependencies must be satisfied by the global package database.
Request that an additional version of the library with profiling features enabled be built and installed (only for implementations that support profiling).
(default) Do not generate an additional profiling version of the library.
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.
(default) Do not enable profiling in generated executables.
In the simple build infrastructure, an additional option is recognized:
Specify the directory into which the package will be built (default: dist/build).
Perform any preprocessing or compilation needed to make this package ready for installation.
Build the interface documentation for a library using haddock.
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 3.1.2).
This command takes the following options:
Register this package in the system-wide database. (This is the default, unless the --user option was supplied to the configure command.)
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:
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:
Register this package in the system-wide database. (This is the default.)
Register this package in the user's local package database.
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.
Deregister this package with the compiler.
This command takes the following options:
Deregister this package in the system-wide database. (This is the default.)
Deregister this package in the user's local package database.
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.
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 package-version.tar.gz in the dist 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:
Append today's date (in YYYYMMDD form) to the version number for the generated source package. The original package is unaffected.