Using the Glasgow Haskell Compiler (GHC) on OS X Lion with Xcode 4.3
Here is what you need to do if you want to use the Glasgow Haskell Compiler (GHC) on OS X Lion with a clean installation of Xcode 4.3.
Command line tools
You need to install the command line tools from Apple. You may do that in two ways (the second is faster as it is a much smaller download):
- Install all of Xcode:
- Install Xcode from the Mac App Store.
- Launch Xcode.
- In the Preferences dialog of Xcode, select the "Downloads" pane and install "Command line tools".
- Install the command line tools only:
- At the downloads page of Apple Developer, download the latest "Command line tools".
- Install them.
In both cases, you need to register as an Apple developer. (This is a free registration.)
Install GHC 7.4.1 (or later)
Older versions of GHC —including GHC 7.0.4, which is part of the Haskell Platform 2011.4.0.0 (December 2011)— won't work. They complain about not being able to execute '/Developer/usr/bin/gcc'. (You can fix this by modifying GHC's wrapper script as mentioned in the comments.)
Download and install GHC 7.4.1 (or a later version) — or install the Haskell Platform once a 2012 release has been made.
Install Cabal tools (optional)
To facilitate the easy installation of Haskell packages, you should get the cabal-install tool.
- Download cabal-install-0.14.0.tar.gz
- Unpack the tarball and, inside the created 'cabal-install-0.14.0' directory, run the following: 'sh bootstrap.sh'
Update: As @zmoazeni points out in the comments, Homebrew has now been updated, so that you can install both GHC and cabal-install version 0.14 by executing
brew install ghc --devel
brew install cabal-install
Using GHC's LLVM backend (optional)
If you like to use GHC's LLVM backend —which is more efficient for array-based and other loop-oriented code— you need to seperately install LLVM. (This is despite the Apple tools being based on LLVM as well.)
- Install Homebrew (as per the instructions on that webpage).
- Then, execute the following: 'brew install llvm'
Compiling GHC from the sources in the Git repositories (GHC developers only)
If you plan to work on GHC itself and you need to compile the develeopment version of GHC straight from the Git repositories, you need to install the GNU auto tools as well (which are no longer distributed by Apple).
- Install Homebrew (as per the instructions on that webpage) — if you didn't do that already to install LLVM above.
- Then, execute the following: 'brew install autoconf automake'
The GHC Trac has more information on Building and Porting GHC.