Skip to content
Snippets Groups Projects
installing.lit 71.6 KiB
Newer Older
% 	Building and installing the Glasgow Functional Programming Tools Suite
%
%				Version 2.02
%				Feb 1997
			

\begin{onlystandalone}
\documentstyle[11pt,literate]{article}
\begin{document}
\title{Building and installing the Glasgow Functional Programming Tools Suite\\
Version~2.02}
\author{The GHC Team\\
Department of Computing Science\\
University of Glasgow\\
Glasgow, Scotland\\
G12 8QQ\\
\\
Email: glasgow-haskell-\{users,bugs\}\@dcs.gla.ac.uk}
\maketitle
\begin{rawlatex}
\tableofcontents
\end{rawlatex}
\clearpage
\end{onlystandalone}

This guide is intended for people who want to install or modify
programs from the Glasgow @fptools@ suite (as distinct from those
who merely want to {\em run} them).

The whole install-and-make system has been completely re-done
between GHC 2.01 and 2.02, so it will be worth your while to re-read this guide
even if you have done so before.

\section{Getting the Glasgow @fptools@ suite}

Building the Glasgow tools {\em can} be complicated, mostly because
there are so many permutations of what/why/how, e.g., ``Build Happy
with HBC, everything else with GHC, leave out profiling, and test it
all on the `real' NoFib programs.''  Yeeps!

Happily, such complications don't apply to most people.  A few common
``strategies'' serve most purposes.  Pick one and proceed
as suggested:

\begin{description}
\item[Binary distribution.]  If your only purpose is to install
some of the @fptools@ suite then the easiest thing to do is to
get a binary distribution.  In the binary distribution everything is
pre-compiled for your particular machine architecture and operating
system, so all you should have to do is install the binaries and libraries
in suitable places.  {\em Need pointer to info about doing binary installation.}

A binary distribution may not work for you for two reasons.  
First, we may not have built the suite for the particular
architecture/OS platform you want.  That may be due to lack of time and
energy (in which case you can get a source distribution and build from it;
see below).  Alternatively, it may be because we havn't yet ported the
suite to your architecture, in which case you are considerably worse off.

The second reason a binary distribution may not be what you want is
if you want to read or modify the souce code.

\item[Source distribution.]
You have a supported
platform, but (a)~you like the warm fuzzy feeling of compiling things
yourself; (b)~you want to build something ``extra''---e.g., a set of
libraries with strictness-analysis turned off; or (c)~you want to hack
on GHC yourself.

A source distribution contains complete sources for the @fptools@ suite.
Not only that, but the more awkward machine-independent steps are done
for you.  For example, if you don't have @flex@ you'll it convenient that
the source distribution contains the result of running @flex@ on the
lexical analyser specification.  If you don't want to alter the lexical
analyser then this saves you having to find and install @flex@.
You will still need a working version of GHC on your machine in order to 
compile (most of) the sources, however.


\item[Build GHC from intermediate C \tr{.hc} files:] 
You need a working GHC to use a source distribution. What if you don't have a working GHC?
Then you have no choice but to ``bootstrap'' up from the
intermediate C (\tr{.hc}) files that we provide.
Building GHC on an unsupported platform falls into this category.
Please see \sectionref{booting-from-C}.

NB: For GHC~2.01, bootstrapping from \tr{.hc} files means you will get
an all-2.01 system---possibly unduly slow.  Building with GHC~0.29
will get you a faster compiler...

Once you have built GHC, you can build the other Glasgow tools with
it.

In theory, you can build GHC with another Haskell compiler (e.g.,
HBC).  We havn't tried to do this for ages and it almost certainly
doesn't work any more.

\item[The CVS repository.]
We make source distributions at the same time as binary distributions;
i.e. infrequently.  They should, however, be pretty thoroughly tested.
If you want more up-to-the minute (but less tested) source code then you 
need to get access to our CVS repository.

All the @fptools@ source code is held in a CVS repository.
CVS is a pretty good source-code control system, and best of all it works over the network.

The repository holds source code only.  It holds no mechanically generated
files at all.  So if you check out a source tree from CVS you will need
to install every utility so that you can build all the derived files
from scratch.

Giving you access to the repository entails some systems administration
at our end; and we are a bit nervous about being submerged in bug reports
about our current working copy (which is, by definition, in flux).  So
we are a bit cautious about offering CVS access.  Feel free to ask though!
\end{description} 

If you are going to do any building from sources (either from a source
distribution or the CVS repository) then you need to read all of this manual in detail.


%************************************************************************
%*									*
\section{Things to check before you start typing}
%*									*
%************************************************************************

Here's a list of things to check before you get started.
\begin{enumerate}
\item
\index{disk space needed}
Disk space needed: About 30MB (five hamburgers' worth) of disk space
for the most basic binary distribution of GHC; more for some
platforms, e.g., Alphas.  An extra ``bundle'' (e.g., concurrent
Haskell libraries) might take you to 8--10 hamburgers.

You'll need over 100MB (say, 20 hamburgers' worth) if you need to
build the basic stuff from scratch.

I don't yet know the disk requirements for the non-GHC tools.

All of the above are {\em estimates} of disk-space needs.

\item
Use an appropriate machine, compilers, and things.

SPARC boxes and DEC Alphas running OSF/1 are fully supported.
Linux, MIPS, and HP boxes are in pretty good shape.
\Sectionref{port-info} gives the full run-down on ports or lack
thereof.

\item
Be sure that the ``pre-supposed'' utilities are installed.
Section~\ref{sect_std-utils} elaborates.

\item
If you have any problem when building or installing the Glasgow tools,
please check the ``known pitfalls'' (\sectionref{build-pitfalls}).  If
you feel there is still some shortcoming in our procedure or
instructions, please report it.

For GHC, please see the bug-reporting section of the User's guide
(separate document), to maximise the usefulness of your report.

If in doubt, please send a message to
\tr{glasgow-haskell-bugs@dcs.gla.ac.uk}.
\end{enumerate}


%************************************************************************
%*									*
\section[port-info]{What machines the Glasgow tools, version~2.01, run on}
\index{ports, GHC}
\index{GHC ports}
\index{supported platforms}
\index{platforms, supported}
%*									*
%************************************************************************

The main question is whether or not the Haskell compiler (GHC) runs on
your platform.

A ``platform'' is a
architecture/manufacturer/operating-system combination,
such as @sparc-sun-solaris2.5.1@.  Other common ones are
@alpha-dec-osf2@, @hppa1.1-hp-hpux9@, @i386-unknown-linux@,
@i386-unknown-solaris2@, @i386-unknown-freebsd@, @i386-unknown-cygwin32@,
@m68k-sun-sunos4@, @mips-sgi-irix5@, @sparc-sun-sunos4@, @sparc-sun-solaris2@.

Bear in mind that certain ``bundles'', e.g. parallel Haskell, may not
work on all machines for which basic Haskell compiling is supported.

Some libraries may only work on a limited number of platforms; for
example, a sockets library is of no use unless the operating system
supports the underlying BSDisms.

%************************************************************************
%*									*
\subsection{What platforms the Haskell compiler (GHC) runs on}
%*									*
%************************************************************************
\index{fully-supported platforms}
\index{native-code generator}
\index{registerised ports}
\index{unregisterised ports}

The GHC hierarchy of Porting Goodness: (a)~Best is a native-code
generator; (b)~next best is a ``registerised''
port; (c)~the bare minimum is an ``unregisterised'' port.
``Unregisterised'' is so terrible that we won't say more about it.

We use Sun4s running SunOS~4.1.3 and Solaris 2.5, and DEC~Alphas
running OSF/1~V2.0, so those are the ``fully-supported'' platforms,
unsurprisingly.  Both have native-code generators, for quicker
compilations.  The native-code generator for iX86 platforms (e.g.,
Linux ELF) is {\em nearly} working; but is not turned on by default.

Here's everything that's known about GHC ports, as of 2.02. We
identify platforms by their ``canonical GNU-style'' names.

Note that some ports are fussy about which GCC version you use; or
require GAS; or ...

\begin{description}
%-------------------------------------------------------------------
\item[\tr{alpha-dec-osf1}:]
\index{alpha-dec-osf1: fully supported}
(We have OSF/1 V2.0.) Fully supported, including native-code generator.
We recommend GCC 2.6.x or later.

%-------------------------------------------------------------------
\item[\tr{sparc-sun-sunos4}:]
\index{sparc-sun-sunos4: fully supported}
Fully supported, including native-code generator.

%-------------------------------------------------------------------
\item[\tr{sparc-sun-solaris2}:]
\index{sparc-sun-solaris2: fully supported}
Fully supported, including native-code generator.  A couple of quirks,
though: (a)~the profiling libraries are bizarrely huge; (b)~the
default \tr{xargs} program is atrociously bad for building GHC
libraries (see \sectionref{Pre-supposed} for details).

%-------------------------------------------------------------------
\item[HP-PA box running HP/UX 9.x:]
\index{hppa1.1-hp-hpux: registerised port}
Works registerised.  No native-code generator.
For GCC, you're best off with one of the Utah releases of
GCC~2.6.3 (`u3' or later), from \tr{jaguar.cs.utah.edu}.
We think a straight GCC 2.7.x works, too.

Concurrent/Parallel Haskell probably don't work (yet).
\index{hppa1.1-hp-hpux: concurrent---no}
\index{hppa1.1-hp-hpux: parallel---no}

%-------------------------------------------------------------------
\item[\tr{i386-*-linux} (PCs running Linux---ELF format):]
\index{i386-*-linux: registerised port}
GHC~2.01 works registerised.
You {\em must} have GCC 2.7.x or later.
The iX86 native-code generator is {\em nearly} there, but it
isn't turned on by default.

Profiling works, and Concurrent Haskell works.
\index{i386-*-linux: profiling---yes}
\index{i386-*-linux: concurrent---yes}
Parallel Haskell probably works.
\index{i386-*-linux: parallel---maybe}

On old Linux a.out systems: should be the same.
\index{i386-*-linuxaout: registerised port}

%-------------------------------------------------------------------
\item[\tr{i386-*-freebsd} (PCs running FreeBSD 2.2 or higher, and
NetBSD/OpenBSD using FreeBSD emulation):] \index{i386-*-freebsd:
registerised port} GHC~2.01 works registerised. Supports same set of
bundles as the above.

\index{i386-*-freebsd: profiling---yes}
\index{i386-*-freebsd: concurrent---yes}
\index{i386-*-freebsd: parallel---maybe}

%-------------------------------------------------------------------
\item[\tr{i386-unknown-cygwin32}:]
\index{i386-unknown-cygwin32: fully supported}
Fully supported under Win95/NT, including a native
code generator. Requires the @cygwin32@ compatibility library and
a healthy collection of GNU tools (i.e., gcc, GNU ld, bash etc.)
Profiling works, so does Concurrent Haskell. 
\index{i386-*-cygwin32: profiling---yes}
\index{i386-*-cygwin32: concurrent---yes}

% ToDo: more documentation on this is reqd here.

%-------------------------------------------------------------------
\item[\tr{mips-sgi-irix5}:]
\index{mips-sgi-irix5: registerised port}
GHC~2.01 works registerised (no native-code generator).
I suspect any GCC~2.6.x (or later) is OK.  The GCC that I used
was built with \tr{--with-gnu-as}; turns out that is important!

Concurrent/Parallel Haskell probably don't work (yet).
Profiling might work, but it is untested.
\index{mips-sgi-irix5: concurrent---no}
\index{mips-sgi-irix5: parallel---no}
\index{mips-sgi-irix5: profiling---maybe}

%-------------------------------------------------------------------
\item[\tr{m68k-apple-macos7} (Mac, using MPW):]
\index{m68k-apple-macos7: historically ported}
Once upon a time, David Wright in Tasmania has actually
gotten GHC to run on a Macintosh.  Ditto James Thomson here at Glasgow.
You may be able to get Thomson's from here.  (Not sure that it will
excite you to death, but...)

No particularly recent GHC is known to work on a Mac.

%-------------------------------------------------------------------
\item[\tr{m68k-next-nextstep3}:]
\index{m68k-next-nextstep3: historically ported}
Carsten Schultz succeeded with a ``registerised'' port of GHC~0.19.
There's probably a little bit-rot since then, but otherwise it should
still be fine.  Had a report that things were basically OK at 0.22.

Concurrent/Parallel Haskell probably won't work (yet).
\index{m68k-next-nextstep3: concurrent---no}
\index{m68k-next-nextstep3: parallel---no}

%-------------------------------------------------------------------
\item[\tr{m68k-sun-sunos4} (Sun3):]
\index{m68k-sun-sunos4: registerised port}
GHC~2.01 hasn't been tried on a Sun3.  GHC~0.26 worked registerised.
No native-code generator.

Concurrent/Parallel Haskell probably don't work (yet).
\index{m68k-sun-sunos4: concurrent---no}
\index{m68k-sun-sunos4: parallel---no}
\end{description}

%************************************************************************
%*									*
\subsection{What machines the other tools run on}
%*									*
%************************************************************************

Unless you hear otherwise, the other tools work if GHC works.

Haggis requires Concurrent Haskell to work.
\index{Haggis, Concurrent Haskell}


%************************************************************************
%*									*
\section[installing-bin-distrib]{Installing from binary distributions}
\index{binary installations}
\index{installation, of binaries}
%*									*
%************************************************************************

Installing from binary distributions is easiest, and recommended!
(Why binaries?  Because GHC is a Haskell compiler written in Haskell,
so you've got to ``bootstrap'' it, somehow.  We provide
machine-generated C-files-from-Haskell for this purpose, but it's
really quite a pain to use them.  If you must build GHC from its
sources, using a binary-distributed GHC to do so is a sensible way to
proceed. For the other @fptools@ programs, many are written in Haskell,
so binary distributions allow you to install them without having a Haskell compiler.)


\subsection{Bundle structure}

Binary distributions come in ``bundles,''\index{bundles of binary stuff}
one bundle per file called \tr{<bundle>-<platform>.tar.gz}.
(See Section~\ref{port-info} for what a platform is.)
Suppose that you untar a binary-distribution bundle, thus:
\begin{verbatim}
  % cd /your/scratch/space
  % gunzip < ghc-2.02-sun-sparc-solaris2.tar.gz | tar xvf -
\end{verbatim}
Then you should find a single directory, @fptools@, with the following
structure:
\begin{description}
\item[@Makefile.in@] the raw material from which the @Makefile@ will be made (\sectionref{sect_install}).
\item[@configure@] the configuration script (\sectionref{sect_install}).
\item[@README@] Contains this file summary.
\item[@INSTALL@] Contains this description of how to install the bundle.
\item[@ANNOUNCE-<bundle>@] The announcement message for the bundle.
\item[@NEWS-<bundle>@] release notes for the bundle -- a longer version of @ANNOUNCE@.
\item[@bin/<platform>/@] contains platform-specific executable files to be invoked
directly by the user.  These are the files that must end up in your path.
\item[@lib/<platform>@] contains platform-specific support files for the installation.
Typically there is a subdirectory for each @fptools@ project, whose name is
the name of the project with its version number.
For example, for GHC 2.02 there would be a sub-directory @ghc-2.02/@.

These sub-directories have the following general structure:
\begin{description}
\item[@libHS.a@ etc:] supporting library archives.
\item[@ghc-iface.prl@ etc:] support scripts.
\item[@import/@] Interface files (@.hi@) for the prelude.
\item[@include/@] A few C @#include@ files.
\end{description}

\item[@share/@] contains platform-independent support files for the installation.
Again, there is a sub-directory for each @fptools@ project.

\item[@info/@] contains Emacs info documentation files (one sub-directory per project).
\item[@html/@] contains HTML documentation files (one sub-directory per project).
\item[@man/@] contains Unix manual pages.
\end{description}
This structure is designed so that you can unpack multiple bundles (including
ones from different releases or platforms) into a single @fptools@ directory:
\begin{verbatim}
  % cd /your/scratch/space
  % gunzip < ghc-2.02-sun-sparc-solaris2.tar.gz | tar xvf -
  % gunzip < happy-1.09-sun-sparc-sunos4.tar.gz | tar xvf -
\end{verbatim}
When you do multiple unpacks like this, the top level @Makefile@, @README@,
and @INSTALL@ get overwritten each time.  That's fine -- they should be the same.
Likewise, the @ANNOUNCE-<bundle>@ and @NEWS-<bundle>@ files will be duplicated
across multiple platforms, so they will be harmlessly overwritten when you do 
multiple unpacks.
Finally, the @share/@ stuff will get harmlessly overwritten when you do multiple
unpacks for one bundle on different platforms.

\subsection[sect_install]{Installing}

OK, so let's assume that you have unpacked your chosen bundles into
a scratch directory @fptools@. What next? Well, you will at least need
to run the @configure@ script by changing your directory to @fptools@.
That should convert @Makefile.in@ to @Makefile@.

You can now either start using the tools {\em in-situ} without going
through any installation process, just type @make in-place@ to set the
tools up for this (you have to be in the @fptools@ directory for
this). You'll also want to add the path which @make@ will now echo to
your @PATH@ environment variable. This option is useful if you simply want
to try out the package and/or you don't have the necessary priviledges (or
inclination) to properly install the tools locally. Note that if you
do decide to install the package `properly' at a later date, you have
to go through the installation steps that follows.

To install an @fptools@ package, you'll have to do the following:

\begin{enumerate}
\item Edit the @Makefile@ and check the settings of the following variables:
\begin{description}
\item[@platform@] the platform you are going to install for.
\item[@bindir@] the directory in which to install user-invokable binaries.
\item[@libdir@] the directory in which to install platform-dependent support files.
\item[@datadir@] the directory in which to install platform-independent support files. 
\item[@infodir@] the directory in which to install Emacs info files.
\item[@htmldir@] the directory in which to install HTML documentation.
\item[@dvidir@] the directory in which to install DVI documentation.
\end{description}
The values for these variables can be set through invocation of the
@configure@ script that comes with the distribution, but doing an optical
diff to see if the values match your expectations is always a Good Idea. 

{\em Instead of running @configure@, it is perfectly OK to copy
@Makefile.in@ to @Makefile@ and set all these variables directly
yourself.  But do it right!}

\item Run @make install@.  This {\em  should} work with ordinary Unix
@make@ -- no need for fancy stuff like GNU @make@. 

\item \tr{rehash} (t?csh users), so your shell will see the new stuff
in your bin directory.

\item
Once done, test your ``installation'' as suggested in
\sectionref{GHC_test}.  Be sure to use a \tr{-v} option, so you
can see exactly what pathnames it's using.

If things don't work as expected, check the list of know pitfalls
\sectionref{build-pitfalls}. 
\end{enumerate}

When installing the user-invokable binaries, this installation
procedure will install, say, @GHC@ version 2.02 as @ghc-2.02@.  It
will also make a link (in the binary installation directory) from
@ghc@ to @ghc-2.02@.  If you install multiple versions of GHC then the
last one ``wins'', and ``@ghc@'' will invoke the last one installed.
You can change this manually if you want.  But regardless, @ghc-2.02@
should always invoke @GHC@ version 2.02.

\subsection{What bundles there are}

There are plenty of ``non-basic'' GHC bundles.  The files for them are
called \tr{ghc-2.01-<bundle>-<platform>.tar.gz}, where the
\tr{<platform>} is as above, and \tr{<bundle>} is one of these:
\begin{description}
\item[\tr{prof}:]  Profiling with cost-centres.  You probably want this.

\item[\tr{conc}:] Concurrent Haskell features.  You may want this.

\item[\tr{par}:] Parallel Haskell features (sits on top of PVM).
You'll want this if you're into that kind of thing.

\item[\tr{gran}:] The ``GranSim'' parallel-Haskell simulator
(hmm... mainly for implementors).

\item[\tr{ticky}:] ``Ticky-ticky'' profiling; very detailed
information about ``what happened when I ran this program''---really
for implementors.

\item[\tr{prof-conc}:] Cost-centre profiling for Concurrent Haskell.

\item[\tr{prof-ticky}:]  Ticky-ticky profiling for Concurrent Haskell.
\end{description}

One likely scenario is that you will grab {\em three} binary
bundles---basic, profiling, and concurrent. 



%************************************************************************
%*									*
\subsection[GHC_test]{Test that GHC seems to be working}
\index{testing a new GHC}
%*									*
%************************************************************************

The way to do this is, of course, to compile and run {\em this} program
(in a file \tr{Main.hs}):
\begin{verbatim}
main = putStr "Hello, world!\n"
\end{verbatim}

First, give yourself a convenient way to execute the driver script
\tr{ghc/driver/ghc}, perhaps something like...
\begin{verbatim}
% ln -s /local/src/ghc-2.01/ghc/driver/ghc ~/bin/alpha/ghc
% rehash
\end{verbatim}

Compile the program, using the \tr{-v} (verbose) flag to verify that
libraries, etc., are being found properly:
\begin{verbatim}
% ghc -v -o hello Main.hs
\end{verbatim}

Now run it:
\begin{verbatim}
% ./hello
Hello, world!
\end{verbatim}

Some simple-but-profitable tests are to compile and run the
notorious \tr{nfib} program, using different numeric types.  Start
with \tr{nfib :: Int -> Int}, and then try \tr{Integer}, \tr{Float},
\tr{Double}, \tr{Rational} and maybe \tr{Complex Float}.  Code
for this is distributed in \tr{ghc/misc/examples/nfib/}.

For more information on how to ``drive'' GHC,
either do \tr{ghc -help} or consult the User's Guide (distributed in
\tr{ghc/docs/users_guide}).


%************************************************************************
%*									*
\section[Pre-supposed]{Installing pre-supposed utilities}
\index{pre-supposed utilities}
\index{utilities, pre-supposed}
%*									*
%************************************************************************

\label{sect_std-utils}

Here are the gory details about some utility programs you may need;
\tr{perl} and \tr{gcc} are the only important ones. (PVM is important
if you're going for Parallel Haskell.) The \tr{configure} script will
tell you if you are missing something.

\begin{description}
\item[Perl:]
\index{pre-supposed: Perl}
\index{Perl, pre-supposed}
{\em You have to have Perl to proceed!} Perl is a language quite good
for doing shell-scripty tasks that involve lots of text processing.
It is pretty easy to install.

Perl~5 is the current version; GHC should be Perl~4 friendly though.
For Win32 platforms, Perl~5 is recommended, we even strongly suggest
you pick up a port of Perl~5 for \tr{cygwin32}, as the common
Hip/ActiveWare port of Perl is not Cool Enough for our purposes.

Perl should be put somewhere so that it can be invoked by the \tr{#!}
script-invoking mechanism. (I believe \tr{/usr/bin/perl} is preferred;
we use \tr{/usr/local/bin/perl} at Glasgow.)  The full pathname should
be less than 32 characters long.

\item[GNU C (\tr{gcc}):]
\index{pre-supposed: GCC (GNU C compiler)}
\index{GCC (GNU C compiler), pre-supposed}
The current version is 2.7.2.  It has a bug that it ticked if you
compile the @gmp@ library without the @-O@ flag.  So the Makefile in
there has the @-O@ flag switched on!  Otherwise, 2.7.2 has no problems that we know of.

If your GCC dies with ``internal error'' on some GHC source file,
please let us know, so we can report it and get things improved.
(Exception: on \tr{iX86} boxes---you may need to fiddle with GHC's
\tr{-monly-N-regs} option; ask if confused...)

\item[PVM version 3:]
\index{pre-supposed: PVM3 (Parallel Virtual Machine)}
\index{PVM3 (Parallel Virtual Machine), pre-supposed}
PVM is the Parallel Virtual Machine on which Parallel Haskell programs
run.  (You only need this if you plan to run Parallel Haskell.  
Concurent Haskell, which runs concurrent threads on a uniprocessor)
doesn't need it.)
Underneath PVM, you can have (for example) a network of
workstations (slow) or a multiprocessor box (faster).

The current version of PVM is 3.3.11; we use 3.3.7.  It is readily available on
the net; I think I got it from \tr{research.att.com}, in \tr{netlib}.

A PVM installation is slightly quirky, but easy to do.  Just follow
the \tr{Readme} instructions.

\item[\tr{xargs} on Solaris2:]
\index{xargs, presupposed (Solaris only)}
\index{Solaris: alternative xargs}
The GHC libraries are put together with something like:
\begin{verbatim}
find bunch-of-dirs -name '*.o' -print | xargs ar q ...
\end{verbatim}
Unfortunately the Solaris \tr{xargs} (the shell-script equivalent
of \tr{map}) only ``bites off'' the \tr{.o} files a few at a
time---with near-infinite rebuilding of the symbol table in
the \tr{.a} file.

The best solution is to install a sane \tr{xargs} from the GNU
findutils distribution.  You can unpack, build, and install the GNU
version in the time the Solaris \tr{xargs} mangles just one GHC
library.

\item[\tr{bash} (Parallel Haskell only):]
\index{bash, presupposed (Parallel Haskell only)}
Sadly, the \tr{gr2ps} script, used to convert ``parallelism profiles''
to PostScript, is written in Bash (GNU's Bourne Again shell).
This bug will be fixed (someday).

\item[Makeindex:]
\index{pre-supposed: makeindex}
\index{makeindex, pre-supposed}
You won't need this unless you are re-making our documents.  Makeindex
normally comes with a \TeX{} distribution, but if not, we can provide
the latest and greatest.

\item[Tgrind:]
\index{pre-supposed: tgrind}
\index{tgrind, pre-supposed}
This is required only if you remake lots of our documents {\em and}
you use the \tr{-t tgrind} option with \tr{lit2latex} (also literate
programming), to do ``fancy'' typesetting of your code.  {\em
Unlikely.}

\item[Flex:]
\index{pre-supposed: flex}
\index{flex, pre-supposed}
This is a quite-a-bit-better-than-Lex lexer.  Used in the
literate-programming stuff.  You won't need it unless you're hacking
on some of our more obscure stuff.

\item[Yacc:]
\index{pre-supposed: non-worthless Yacc}
\index{Yacc, pre-supposed}
If you mess with the Haskell parser, you'll need a Yacc that can cope.
The unbundled \tr{/usr/lang/yacc} is OK; the GNU \tr{bison} is OK;
Berkeley yacc, \tr{byacc}, is not OK.

\item[@sed@]
\index{pre-supposed: sed}
\index{sed, pre-supposed}
You need a working @sed@ if you are going to build from sources.
The build-configuration stuff needs it.
GNU sed version 2.0.4 is no good! It has a bug in it that is tickled by the
build-configuration.  2.0.5 is ok. Others are probably ok too
(assuming we don't create too elaborate configure scripts..)
\end{description}

Two @fptools@ projects are worth a quick note at this point, because
they are useful for all the others:
\begin{itemize}
\item @glafp-utils@ contains several utilities which aren't
particularly Glasgow-ish, but Occasionally Indispensable.


\item @literate@ contains the Glasgow-built tools for generating
documentation.  (The unoriginal idea is to be able to generate @latex@, @info@,
and program code from a single source file.) To get anywhere you'll
need at least @lit2pgm@, either from the @literate@ project, or
because it's already installed on your system. 
\end{itemize}




%************************************************************************
%*									*
\section{Building from source}
%*									*
%************************************************************************

You've been rash enough to want to build some of
the Glasgow Functional Programming tools (GHC, Happy,
nofib, etc) from source.  You've slurped the source,
from the CVS repository or from a source distribution, and
now you're sitting looking at a huge mound of bits, wondering
what to do next.

Gingerly, you type @make all@.  Wrong already!

This rest of this guide is intended for duffers like me, who aren't really
interested in Makefiles and systems configurations, but who need
a mental model of the interlocking pieces so that they can 
make them work, extend them consistently when adding new
software, and lay hands on them gently when they don't work.

\subsection{Your source tree}

The source code is held in your {\em source tree}.
The root directory of your source tree {\em must}
contain the following directories and files:
\begin{itemize}
\item @Makefile@: the root Makefile.
\item @mk/@: the directory that contains the
main Makefile code, shared by all the
@fptools@ software.
\item @configure.in@: a file that tells the GNU configuration 
tools what @fptools@ needs to know about the host platform and
operating system. 
\end{itemize}
All the other directories are individual {\em projects} of the
@fptools@ system --- for example, the Glasgow Haskell Compiler (@ghc@),
the Happy parser generator (@happy@), the @nofib@ benchmark suite, 
and so on.
You can have zero or more of these.  Needless to say, some of them
are needed to build others.  For example, you need @happy@ to build
@ghc@.  You can either grab @happy@ too, or else you can use
a version of @happy@ that's already installed on your system, or 
grab a binary distribution of @happy@ and install it.

The important thing to remember is that even if you want only
one project (@happy@, say), you must have a source tree
whose root directory contains @Makefile@, 
@mk/@, @configure.in@, and the project(s) you 
want (@happy/@ in this case).  You cannot get by with 
just the @happy/@ directory.

\subsection{Build trees}

While you can build a system in the source tree, we don't recommend it.
We often want to build multiple versions of our software
for different architectures, or with different options (e.g. profiling).
It's very desirable to share a single copy of the source code among
all these builds.

So for every source tree we have zero or more {\em build trees}.
Each build tree is initially an exact copy of the source tree,
except that each file is a symbolic link to the source file, 
rather than being a copy of the source file.  There are ``standard''
Unix utilities that make such copies, so standard that they go by
different names: @lndir@, @mkshadowdir@ are two (If you don't have
either, the source distribution includes sources for the \tr{X11}
\tr{lndir} --- check out \tr{fptools/glafp-utils/lndir} ).

The build
tree does not need to be anywhere near the source tree in the
file system.
Indeed, one advantage of separating the build tree from the source
is that the build tree can be placed in a non-backed-up partition,
saving your systems support people from backing up untold megabytes 
of easily-regenerated, and rapidly-changing, gubbins.  The golden rule is 
that (with a single exception -- Section~\ref{sect_build-config})
{\em absolutely
everything in the build tree is either a symbolic link to the source
tree, or else is mechanically generated}.  It should be perfectly 
OK for your build tree to vanish overnight; an hour or two compiling 
and you're on the road again.

You need to be a bit careful, though, that any new files you create
(if you do any development work) are in the source tree, not a build tree!

Remember, that the source files in the build tree are {\em symbolic
links} to the files in the source tree.  (The build tree soon
accumulates lots of built files like @Foo.o@, as well.)  You can {\em
delete} a source file from the build tree without affecting the source
tree (though it's an odd thing to do).  On the other hand, if you {\em
edit} a source file from the build tree, you'll edit the source-tree
file directly.  (You can set up Emacs so that if you edit a source
file from the build tree, Emacs will silently create an edited copy of
the source file in the build tree, leaving the source file unchanged;
but the danger is that you think you've edited the source file whereas
actually all you've done is edit the build-tree copy.  More commonly
you do want to edit the source file.)

Like the source tree, the top level of your build tree must (a linked copy of)
the root directory of the @fptools@ suite.
Inside Makefiles, the root of your build tree is called @$(FPTOOLS_TOP)@.
In the rest of this document path names are relative to @$(FPTOOLS_TOP)@ 
unless otherwise stated.  For example, the file @ghc/mk/target.mk@ is
actually @$(FPTOOLS_TOP)/ghc/mk/target.mk@.


\subsection{Getting the build you want}
\label{sect_build-config}

When you build @fptools@ you will be compiling code 
on a particular {\em host platform},
to run on a particular {\em target platform} (usually the same
as the host platform)\index{platform}.   The difficulty is 
that there are minor differences between different platforms;
minor, but enough that the code needs to be a bit different
for each.  There are some big differences too: for
a different architecture we need to build GHC with a different
native-code generator.

There are also knobs you can turn to control how the @fptools@
software is built.  For example, you might want to build GHC
optimised (so that it runs fast) or unoptimised (so that you can
compile it fast after you've modified it.
Or, you might want to compile it with debugging on (so that
extra consistency-checking code gets included) or off.  And so on.

All of this stuff is called the {\em configuration} of your build.
You set the configuration using an exciting three-step process.
\begin{description}
\item[Step 1: get ready for configuration.]
Change directory to @$(FPTOOLS)@ and issue the following two commands (with no arguments):
\begin{enumerate}
\item @autoconf@. This GNU program
converts @$(FPTOOLS)/configure.in@ to a shell script 
called @$(FPTOOLS)/configure@.

\item @autoheader@.  This second GNU program converts
@$(FPTOOLS)/configure.in@ to @$(FPTOOLS)/mk/config.h.in@.
\end{enumerate}
Both these steps are completely platform-independent; they just mean
that the human-written file (@configure.in@) can be short, although
the resulting shell script, @configure@, and @mk/config.h.in@, are long.
In case you don't have @autoconf@ and @autoheader@ we distribute
the results, @configure@, and @mk/config.h.in@, with the source distribution.
They aren't kept in the repository, though.
\item[Step 2: system configuration.]
Runs the newly-created @configure@ script, thus:
\begin{verbatim}
  ./configure
\end{verbatim}
@configure@'s mission
is to scurry round your computer working out what architecture it has,
what operating system, whether it has the @vfork@ system call,
where @yacc@ is kept, whether @gcc@ is available, where various
obscure @#include@ files are, whether it's a leap year, and
what the systems manager had for lunch.
It communicates these snippets of information in two ways:
\begin{itemize}
\item It translates @mk/config.mk.in@ to @mk/config.mk@,
substituting for things between ``{\tt @@@@}'' brackets.  So,
``{\tt @@HaveGcc@@}'' will be replaced by ``@YES@'' or ``@NO@''
depending on what @configure@ finds.
@mk/config.mk@ is included by every Makefile (directly or indirectly),
so the configuration information is thereby communicated to
all Makefiles.

\item It translates @mk/config.h.in@ to @mk/config.h@.
The latter is @#include@d by various C programs, which
can thereby make use of configuration information.
\end{itemize}


\item[Step 3: build configuration.] Next, you say how this build
of @fptools@ is to differ from the standard defaults by creating a new 
file @mk/build.mk@
{\em in the build tree}.  This file is the one and only
file you edit in the build tree, precisely because it says how
this build differs from the source.  (Just in case your build tree
does die, you might want to keep a private directory of @build.mk@ files,
and use a symbolic link in each build tree to point to the appropriate one.)
So @mk/build.mk@ never
exists in the source tree --- you create one in each build tree
from the template.  We'll discuss what to put in it shortly.
\end{description}
And that's it for configuration. Simple, eh?

What do you put in your build-specific configuration
file @mk/build.mk@?  {\em For almost all purposes all you will do is
put make variable definitions that override those in @mk/config.mk.in@}.
The whole point of @mk/config.mk.in@ --- and its derived 
counterpart @mk/config.mk@ --- is to define the build configuration. It is heavily
commented, as you will see if you look at it.
So generally, what you do is edit @mk/config.mk.in@ (read-only), and add definitions
in @mk/build.mk@ that override any of the @config.mk@ definitions that you
want to change.  (The override occurs because the main boilerplate file,
@mk/boilerplate.mk@, includes @build.mk@ after @config.mk@.)

For example, @config.mk.in@ contains the definition:
\begin{verbatim}
  ProjectsToBuild = glafp-utils literate ghc hslibs
\end{verbatim}
The accompanying comment explains that this is the list of enabled
projects; that is, if (after configuring) you type @gmake all@
in @FPTOOLS_TOP@ three specified projects will be made.
If you want to add @happy@, you can add this line to @build.mk@:
\begin{verbatim}
  ProjectsToBuild += happy
\end{verbatim}
or, if you prefer,
\begin{verbatim}
  ProjectsToBuild = glafp-utils literate ghc hslibs happy
\end{verbatim}
(GNU @make@ allows existing definitions to have new text appended using
the ``@+=@'' operator, which is quite a convenient feature.)

When reading @config.mk.in@, remember that anything between ``{\tt @@...@@}'' signs
is going to be substituted by @configure@ later.  You {\em can} override
the resulting definition if you want, 
but you need to be a bit surer what you are doing.
For example, there's a line that says:
\begin{verbatim}
  YACC = @Yacc@
\end{verbatim}
This defines the Make variables @YACC@ to the pathname for a Yacc that
@configure@ finds somewhere.  If you have your own pet Yacc you want
to use instead, that's fine. Just add this line to @mk/build.mk@:
\begin{verbatim}
  YACC = myyacc
\end{verbatim}
You do not {\em have} to have a @mk/build.mk@ file at all; if you don't,
you'll get all the default settings from @mk/config.mk.in@.


\subsection{The story so far}

Let's summarise the steps you need to carry to get yourself
a fully-configured build tree from scratch.

\begin{enumerate}
\item Get your source tree from somewhere (CVS repository or
source distribution).  Say you call the root directory
@myfptools@ (it does not have to be called @fptools@).

\item Use @lndir@ or @mkshadowdir@ to create a build tree.
\begin{verbatim}
    cd myfptools
    mkshadowdir . /scratch/joe-bloggs/myfptools-sun4
\end{verbatim}
You probably want to give the build tree a name that
suggests its main defining characteristic (in your mind at least),
in case you later add others.

\item Change directory to the build tree.  Everything is going
to happen there now.
\begin{verbatim}
    cd /scratch/joe-bloggs/myfptools-sun4
\end{verbatim}
\item Prepare for system configuration:
\begin{verbatim}
    autoconf
    autoheader
\end{verbatim}
(You can skip this step if you are starting from a source distribution,
and you already have @configure@ and @mk/config.h.in@.)

\item Do system configuration:
\begin{verbatim}
\item Create the file @mk/build.mk@, 
adding definitions for your desired configuration options.
\begin{verbatim}
    emacs mk/build.mk
\end{verbatim}
\end{enumerate}
You can make subsequent changes to @mk/build.mk@ as often 
as you like.  You do not have to run any further configuration 
programs to make these changes take effect.
In theory you should, however, say @gmake clean@, @gmake all@,
because configuration option changes could affect anything --- but in practice you are likely to know what's affected.

\subsection{Making things}

At this point you have made yourself a fully-configured build tree,
so you are ready to start building real things.

The first thing you need to know is that 
{\em you must use GNU @make@, usually called @gmake@, not standard Unix @make@}.
If you use standard Unix @make@ you will get all sorts of error messages
(but no damage) because the @fptools@ @Makefiles@ use GNU @make@'s facilities
extensively.

\subsection[sect_standard-targets]{Standard targets}

In any directory you should be able to make the following:
\begin{description}
\item[@boot@:] does the one-off preparation required to get ready