>
Notes for building under WindowsBuilding the Glasgow Functional Programming Tools Suite | ||
---|---|---|
Prev |
This section summarises how to get the utilities you need on your Win95/98/NT/2000 machine to use CVS and build GHC. Similar notes for installing and running GHC may be found in the user guide. In general, Win95/Win98 behave the same, and WinNT/Win2k behave the same. You should read the GHC installation guide sections on Windows (in the user guide) before continuing to read these notes.
The Windows situation for building GHC is rather confusing. This section tries to clarify, and to establish terminology.
MinGW (Minimalist GNU for Windows) is a collection of header files and import libraries that allow one to use gcc and produce native Win32 programs that do not rely on any third-party DLLs. The current set of tools include GNU Compiler Collection (gcc), GNU Binary Utilities (Binutils), GNU debugger (Gdb), GNU make, and a assorted other utilities.
The GHC that we distribute includes, inside the distribution itself, the MinGW gcc, as, ld, and a bunch of input/output libraries. GHC compiles Haskell to C (or to assembly code), and then invokes these MinGW tools to generate an executable binary. The resulting binaries can run on any Win32 system.
We will call a GHC that targets MinGW in this way GHC-mingw.
The down-side of GHC-mingw is that the MinGW libraries do not support anything like the full Posix interface. So programs compiled with GHC-mingw cannot import the (Haskell) Posix library; they have to do their input output using standard Haskell I/O libraries, or native Win32 bindings.
There is a way to get the full Posix interface, which is to use Cygwin. Cygwin is a complete Unix simulation that runs on Win32. Cygwin comes with a shell, and all the usual Unix commands: mv, rm, ls, plus of course gcc, ld and so on. A C program compiled with the Cygwin gcc certainly can use all of Posix.
So why doesn't GHC use the Cygwin gcc and libraries? Because Cygwin comes with a DLL that must be linked with every runnable Cygwin-compiled program. A program compiled by the Cygwin tools cannot run at all unless Cygwin is installed. If GHC targeted Cygwin, users would have to install Cygwin just to run the Haskell programs that GHC compiled; and the Cygwin DLL would have to be in the DLL load path. Worse, Cygwin is a moving target. The name of the main DLL, cygwin1.dll does not change, but the implementation certainly does. Even the interfaces to functions it exports seem to change occasionally. So programs compiled by GHC might only run with particular versions of Cygwin. All of this seems very undesirable.
Nevertheless, it is certainly possible to build a version of GHC that targets Cygwin; we will call that GHC-cygwin. The up-side of GHC-cygwin is that Haskell programs compiled by GHC-cygwin can import the (Haskell) Posix library.
Notice that "GHC-mingw" means "GHC that targets MinGW". It says nothing about how that GHC was built. It is entirely possible to have a GHC-mingw that was built by compiling GHC's Haskell sources with a GHC-cygwin, or vice versa.
We distribute only a GHC-mingw built by a GHC-mingw; supporting GHC-cygwin too is beyond our resources. The GHC we distribute therefore does not require Cygwin to run, nor do the programs it compiles require Cygwin.
The instructions that follow describe how to build GHC-mingw. It is possible to build GHC-cygwin, but it's not a supported route, and the build system might be flaky.
You don't need Cygwin to use GHC, but you do need it to build GHC.
Install Cygwin from http://www.cygwin.com/. The installation process is straightforward; we install it in c:/cygwin. Both cvs and ssh come with Cygwin, but you'll need them, so make sure you select them when running the Cygwin installer.
Now set the following user environment variables:
Add c:/cygwin/bin and c:/cygwin/usr/bin to your PATH
Set MAKE_MODE to UNIX. If you don't do this you get very weird messages when you type make, such as:
/c: /c: No such file or directory |
Set SHELL to c:/cygwin/bin/sh. When you invoke a shell in Emacs, this SHELL is what you get.
Set HOME to point to your home directory. This is where, for example, bash will look for your .bashrc file. Ditto emacs looking for .emacsrc
There are a few other things to do:
Some script files used in the make system start with "#!/bin/perl", (and similarly for bash). Notice the hardwired path! So you need to ensure that your /bin directory has the following binaries in it:
sh
perl
cat
By default, cygwin provides the command shell ash as sh.exe. It has a couple of 'issues', so in your /bin directory, make sure that bash.exe is also provided as sh.exe (i.e. overwrite the old sh.exe with a copy of bash.exe).
Finally, here are some things to be aware of when using Cygwin:
Cygwin doesn't deal well with filenames that include spaces. "Program Files" and "Local files" are common gotchas.
Cygwin implements a symbolic link as a text file with some magical text in it. So other programs that don't use Cygwin's I/O libraries won't recognise such files as symlinks. In particular, programs compiled by GHC are meant to be runnable without having Cygwin, so they don't use the Cygwin library, so they don't recognise symlinks.
Win32 has a find command which is not the same as Cygwin's find. You will probably discover that the Win32 find appears in your PATH before the Cygwin one, because it's in the system PATH environment variable, whereas you have probably modified the user PATH variable. You can always invoke find with an absolute path, or rename it.
You have to install the following other things to build GHC:
Install an executable GHC, from http://www.haskell.org/ghc. This is what you will use to compile GHC. Add it in your PATH: the installer tells you the path element you need to add upon completion.
Install an executable Happy, from http://www.haskell.org/happy. Happy is a parser generator used to compile the Haskell grammar. Add it in your PATH.
GHC uses the mingw C compiler to generate code, so you have to install that. Just pick up a mingw bundle at http://www.mingw.org/. We install it in c:/mingw.
Finally, check out a copy of GHC sources from the CVS repository, following the instructions above (Section 2.1).
OK! Now go read the documentation above on building from source (Section 7); the bullets below only tell you about Windows-specific wrinkles.
Run autoconf both in fptools and in fptools/ghc. If you omit the latter step you'll get an error when you run ./configure:
...lots of stuff... creating mk/config.h mk/config.h is unchanged configuring in ghc running /bin/sh ./configure --cache-file=.././config.cache --srcdir=. ./configure: ./configure: No such file or directory configure: error: ./configure failed for ghc |
autoconf seems to create the file configure read-only. So if you need to run autoconf again (which I sometimes do for safety's sake), you get
/usr/bin/autoconf: cannot create configure: permission denied |
You either need to add ghc to your PATH before you invoke configure, or use the configure option --with-ghc=c:/ghc/ghc-some-version/bin/ghc.
After autoconf run ./configure in fptools/ thus:
./configure --host=i386-unknown-mingw32 --with-gcc=/mingw/bin/gcc |
If you want to build GHC-cygwin (Section 12.1.2) you'll have to do something more like:
./configure --with-gcc=...the Cygwin gcc... |
Do not attempt to build the documentation. It needs all kinds of wierd Jade stuff that we haven't worked out for Win32.