EHCInstall

Eifl

How to install&use EHC and the tools it requires (on a Windows system)

This is a step-by-step guide to get a working EHC system on your Windows computer. You will get the source and all necessary tools, to be able to experment with and extend EHC yourself. For other operating systems (Linux, MacOS? ) you can just skip step 1 and 2.

You will need tools from six different sources, so have some patience to install them all. The good news is that you may find the tools useful in different situations as well.

  1. Cygwin: a command line shell
  2. Tortoise: SVN version management client
  3. GHC: Haskell compiler
  4. UUlib: Additional Haskell libraries from Utrecht University
  5. UU-AGC: Attribute Grammar Compiler
  6. EHC: Extensible Haskell Compiler

1. Cygwin: a command line shell

EHC makes use of Unix-style development tools, like make and configure. For being able to use such command line tools without having to go so far as to install Linux, you can use Cygwin: a command line shell which comes with many of the needed development tools.

To install Cygwin, go to the Cygwin website and download the small (250k) installation program. During installation it asks for:

  • A root directory. As this directory might need to be mentioned in various places, a short path without spaces is recommended, for example d:\cygwin.
  • A local package directory. This directory is used to store temporary files during download and installation of Cygwin. Any path will do, for example d:\downloads\cygwin.
  • Internet connection type, and mirrorsite to download from. Default choices will do.
  • Packages to select: the default selections are all we need. You can always add more packages later by starting the installation program again.
After installation you will have a desktop icon and/or an item in the start menu.

to test whether it works:

  • Start Cygwin and try some Unix commands, like ls and date (but DOS commands also work, e.g. dir).
  • The root of the file system is the directory that you mentioned during installation. So when you type ls / you will see the files that are physically located in d:\cygwin\. But you can also access files outside the Cygwin system, using Windows pathnames: try ls c:.
  • Some programs that are not designed specifically for Windows might, however, not like colons in their pathnames. If you still need to address files outside the Cygwin directory, to can address e.g. the C-disk by ls /cygdrive/c.
  • To have an even more convenient access to your files, issue the command mount c: /c, and you will be able to address all files on the C-disk as if they were in directory /c. This command needs to be given only once.

1a. Patch Cygwin "make" bug

There is a bug in the Cygwin "make" utility, which exists in version 3.81 and maybe also in version 4. You can download file "make.exe" version 3.80 and copy it to c:\cygwin\bin.

to test whether it works:
Type at a Cygwin prompt:

     
make --version
it should reply: "GNU Make 3.80".

2. Tortoise: SVN version management client

The tools in step 4 to 6 are maintained in a collaborative version management system called Subversion, or SVN. You need a Subversion client to download files from a repository. Tortoise offers a graphical user interface to SVN. It integrates in the explorer, so you will hardly notice it exists as a seprate program: you will just notice enhanced explorer behaviour.

Download Tortoise SVN here and install it.

to test whether it works:
Open the file explorer, and rightclick any directory. A context menu Tortoise SVN should be present.

3. GHC: Haskell compiler

The Glasgow Haskell Compiler (GHC) is an industrial-strength Haskell compiler, including many libraries. To install it:

  • Download version 6.8 from the Haskell website and install it.
    A binary for your operating system is probably available. For Windows, choose the standalone version.
    It is wise to install the compiler in a directory without spaces in its name, for example d:\ghc.
  • Make sure the subdirectory bin of the installation directory is in your PATH. You can do this in Windows by selecting Start > Control Panel > System > Advanced > Environment Variables. Or (which is easier) in Cygwin by editing the last line of file .bashrc in your Cygwin home directory (the directory that is reported by the pwd command in a fresh Cygwin window).

to test whether it works:

  • Type ghc --help at the Cygwin prompt. It should reply with a couple screensful usage information. If it doesn't work, the PATH is probably not right.
  • Create a file Test.hs containing a simple Haskell program:
         
    square x = x*x
    main = putStrLn (show (square 5))
    
    Compile it with ghc Test.hs and run it by starting main.exe.
  • If you include a module header in your program, like
         
    module Test where
    square x = x*x
    main = putStrLn (show (square 5))
    
    you should compile it by ghc --make Test.hs

4. UUlib: Additional Haskell libraries from Utrecht University

Haskell comes with a large number of libraries, but of course we like our own better. Download and install them as follows:

  • Create a directory uulib in a convenient place.
  • Rightclick it in the browser and choose SVN Checkout... from the context menu
  • Type the following URL: https://svn.cs.uu.nl:12443/repos/uust-repo/uulib/trunk
  • To install the libraries (have them recognized hy GHC), start Cygwin and go to the directory you just created. Then type the following commands:
         
        autoconf
        ./configure
        ghc --make Setup.hs -o setup -package Cabal
        ./setup configure
        ./setup build
        ./setup install
    

5. UU-AGC: Attribute Grammar Compiler

The Attribute Grammar Compiler is a preprocessor to Haskell that generates recursive tree walks. Input to this preprocessor is a custom description of an attribute grammar.

Download and install it as follows:

  • Download and unpack the distribution
  • To install the compiler, start Cygwin and go to the directory you just created. Then type the following commands:
         
        autoconf
        ./configure
        make build
        make install
    

6. EHC: Extensible Haskell Compiler

Now you are ready to get our Extensible Haskell Compiler, and soon you'll be extending it yourself.

Download and install it as follows:

  • Create a directory ehc in a convenient place.
  • Rightclick it in the browser and choose SVN Checkout... from the context menu
  • Type the following URL: https://svn.cs.uu.nl:12443/repos/EHC/trunk/EHC
    Expect 30 Megabytes to be downloaded.
  • To install the system, start Cygwin and go to the directory you just created. Then type the following commands:
         
        ./configure --with-ghc=d:/ghc/ghc-6.8/bin/ghc.exe --with-gcc=d:/cygwin/bin/gcc
        ./configure --with-ghc=c:/ghc/ghc-6.8.2/bin/ghc.exe  --with-gcc=/bin/gcc --with-cpp=/bin/cpp --with-ehc-unixtool-prefix="c:/cygwin" --with-uuagc-ehc-ast-options="" --with-uuagc-ehc-sem-options=""  --with-gcc-ehc-options=""
        make 8/ehc
    
    (The paths may look strange having colons and forward slashes, but this needs really be like this. Of course, you can adapt the paths if you installed the tools elsewhere).
    Then wait a long time (7 minutes), as not only the compiler has to be build, but also the supporting development tools shuffle and ruler.
Note that there are various versions of the compiler, which correspond to various stages of extension. In the example above, we build version 8 of the compiler, which is a good start because it is the simplest version that has code generation.

to test whether it works:
Type the following commands:

     
    cd testgrinc
    ../bin/8/ehc.exe -cexe sum.hs
    sum.exe
This will compile an example program sum (a Haskell program that calculates the sum of the numbers 1 to 10). Because of the -cexe flag, EHC will generate a C file, and compile it with the C compiler gcc that comes with Cygwin. Finally, sum.exe is the compiled program which shows the answer 55 when run.
Alternatively, you can use -cbexe to generate bytecode embedded in an interpreter.