This answer serves to complement the other answers
(that are already enlightening).
First of all, know
that there are significant differences
between minor versions of GHC.
For example, the change
from GHC 7.8 to GHC 7.10
(cf. burning bridges proposal).
So, it might be better
to name your GHC binaries
also including minor version numbers, like:
ghc7.8
and ghc7.10
.
Supposing you have several GHCs installed with the following names:
/usr/bin/ghc
/usr/bin/ghc-pkg
/usr/bin/haddock
...
/usr/bin/ghc-7.8
/usr/bin/ghc-pkg-7.8
/usr/bin/haddock-ghc-7.8
...
/usr/bin/ghc-7.6
/usr/bin/ghc-pkg-7.6
/usr/bin/haddock-ghc-7.6
...
(and so on)
For GHC 7.8,
you can create a file called ~/.cabal-ghc-7.8/config
with the following contents
(that point to the locations described above):
remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive
remote-repo-cache: /home/<USER>/.cabal-ghc-7.8/packages
world-file: /home/<USER>/.cabal-ghc-7.8/world
compiler: ghc
extra-prog-path: /home/<USER>/.cabal-ghc-7.8/bin
build-summary: /home/<USER>/.cabal-ghc-7.8/logs/build.log
remote-build-reporting: anonymous
jobs: $ncpus
install-dirs user
prefix: /home/<USER>/.cabal-ghc-7.8
program-locations
ghc-location: /usr/bin/ghc-7.8
ghc-pkg-location: /usr/bin/ghc-pkg-7.8
haddock-location: /usr/bin/haddock-ghc-7.8
hpc-location: /usr/bin/hpc-ghc-7.8
hsc2hs-location: /usr/bin/hsc2hs-ghc-7.8
You can create an executable
possibly called cabal-ghc-7.8
in your PATH
(it uses the --config-file
option described in n.m.'s answer):
#!/bin/bash
exec cabal --config-file=$HOME/.cabal-ghc-7.8/config "$@"
Now, in your cabalized source dir,
you can simply run cabal-ghc-7.8 build
to build your source files using GHC 7.8.
(or cabal-ghc-7.8 test
or anything else)
You can repeat the process for all the GHCs you have installed.
Of course, you should not worry about the standard named GHC.
By default, Cabal searches for a GHC named ghc
.
This answer assumes a UNIX/Linux system (like the use of bash
), but can be adapted to other systems with small changes.