[project @ 1997-06-20 09:19:19 by sof]
[ghc-hetmet.git] / docs / installing.lit
1 %       Building and installing the Glasgow Functional Programming Tools Suite
2 %
3 %                               Version 2.04
4 %                               June 1997
5                         
6
7 \begin{onlystandalone}
8 \documentstyle[11pt,literate]{article}
9 \begin{document}
10 \title{Building and installing the Glasgow Functional Programming Tools Suite\\
11 Version~2.04}
12 \author{The GHC Team\\
13 Department of Computing Science\\
14 University of Glasgow\\
15 Glasgow, Scotland\\
16 G12 8QQ\\
17 \\
18 Email: glasgow-haskell-\{users,bugs\}\@dcs.gla.ac.uk}
19 \maketitle
20 \begin{rawlatex}
21 \tableofcontents
22 \end{rawlatex}
23 \clearpage
24 \end{onlystandalone}
25
26 This guide is intended for people who want to install or modify
27 programs from the Glasgow @fptools@ suite (as distinct from those
28 who merely want to {\em run} them).
29
30 The whole install-and-make system was completely re-done between GHC
31 2.01 and 2.02, so it will be worth your while to re-read this guide
32 even if you have read earlier versions.
33
34 \section{Getting the Glasgow @fptools@ suite}
35
36 Building the Glasgow tools {\em can} be complicated, mostly because
37 there are so many permutations of what/why/how, e.g., ``Build Happy
38 with HBC, everything else with GHC, leave out profiling, and test it
39 all on the `real' NoFib programs.''  Yeeps!
40
41 Happily, such complications don't apply to most people.  A few common
42 ``strategies'' serve most purposes.  Pick one and proceed
43 as suggested:
44
45 \begin{description}
46 \item[Binary distribution.]  If your only purpose is to install
47 some of the @fptools@ suite then the easiest thing to do is to
48 get a binary distribution. In the binary distribution everything is
49 pre-compiled for your particular machine architecture and operating
50 system, so all you should have to do is install the binaries and libraries
51 in suitable places.  {\em Need pointer to info about doing binary installation.}
52
53 A binary distribution may not work for you for two reasons.  First, we
54 may not have built the suite for the particular architecture/OS
55 platform you want. That may be due to lack of time and energy (in
56 which case you can get a source distribution and build from it; see
57 below).  Alternatively, it may be because we haven't yet ported the
58 suite to your architecture, in which case you are considerably worse
59 off.
60
61 The second reason a binary distribution may not be what you want is
62 if you want to read or modify the souce code.
63
64 \item[Source distribution.]
65 You have a supported platform, but (a)~you like the warm fuzzy feeling
66 of compiling things yourself; (b)~you want to build something
67 ``extra''---e.g., a set of libraries with strictness-analysis turned
68 off; or (c)~you want to hack on GHC yourself.
69
70 A source distribution contains complete sources for the @fptools@ suite.
71 Not only that, but the more awkward machine-independent steps are done
72 for you.  For example, if you don't have @flex@ you'll find it
73 convenient that the source distribution contains the result of running
74 @flex@ on the lexical analyser specification.  If you don't want to
75 alter the lexical analyser then this saves you having to find and
76 install @flex@. You will still need a working version of GHC on your
77 machine in order to compile (most of) the sources, however.
78
79 We make source distributions more frequently than binary
80 distributions; a release that comes with pre-compiled binaries
81 is considered a major release, i.e., a release that we have some
82 confidence will work well by having tested it (more) thoroughly.
83
84 Source-only distributions are either bugfix releases or snapshots of
85 current state of development. The release has undergone some testing.
86
87 GHC~2.04 is a source-only release, and it can be compiled up using
88 either GHC~2.02 (or the bugfix release, GHC~2.03) or the Good Old
89 Compiler, GHC~0.29. Compiling with 0.29 is recommended if you're
90 a performance junkie, as 0.29 (still) generates zippier code, but
91 GHC~2.04 is catching up.
92
93 \item[Build GHC from intermediate C \tr{.hc} files:] 
94 You need a working GHC to use a source distribution. What if you don't
95 have a working GHC? Then you have no choice but to ``bootstrap'' up
96 from the intermediate C (\tr{.hc}) files that we provide.
97 Building GHC on an unsupported platform falls into this category.
98 Please see \sectionref{booting-from-C}.
99
100 Once you have built GHC, you can build the other Glasgow tools with
101 it.
102
103 In theory, you can (could?) build GHC with another Haskell compiler
104 (e.g., HBC). We haven't tried to do this for ages and it almost
105 certainly doesn't work any more (for tedious reasons).
106
107 \item[The CVS repository.]
108
109 We make source distributions at the same time as binary distributions;
110 i.e. infrequently.  They should, however, be pretty thoroughly tested.
111 If you want more up-to-the minute (but less tested) source code then you 
112 need to get access to our CVS repository.
113
114 All the @fptools@ source code is held in a CVS repository. CVS is a
115 pretty good source-code control system, and best of all it works over
116 the network.
117
118 The repository holds source code only. It holds no mechanically
119 generated files at all.  So if you check out a source tree from CVS
120 you will need to install every utility so that you can build all the
121 derived files from scratch.
122
123 Giving you access to the repository entails some systems administration
124 at our end; and we are a bit nervous about being submerged in bug reports
125 about our current working copy (which is, by definition, in flux).  So
126 we are a bit cautious about offering CVS access.  Feel free to ask though!
127 \end{description} 
128
129 If you are going to do any building from sources (either from a source
130 distribution or the CVS repository) then you need to read all of this
131 manual in detail.
132
133 %************************************************************************
134 %*                                                                      *
135 \section{Things to check before you start typing}
136 %*                                                                      *
137 %************************************************************************
138
139 Here's a list of things to check before you get started.
140 \begin{enumerate}
141 \item
142 \index{disk space needed}
143 Disk space needed: About 30MB (five hamburgers' worth) of disk space
144 for the most basic binary distribution of GHC; more for some
145 platforms, e.g., Alphas.  An extra ``bundle'' (e.g., concurrent
146 Haskell libraries) might take you to 8--10 hamburgers.
147
148 You'll need over 100MB (say, 20 hamburgers' worth) if you need to
149 build the basic stuff from scratch.
150
151
152 All of the above are {\em estimates} of disk-space needs.(I don't yet
153 know the disk requirements for the non-GHC tools).
154
155 \item
156 Use an appropriate machine, compilers, and things.
157
158 SPARC boxes and DEC Alphas running OSF/1 are fully supported.
159 Linux, MIPS, AIX, Win32 and HP boxes are in pretty good shape.
160 \Sectionref{port-info} gives the full run-down on ports or lack
161 thereof.
162
163 \item
164 Be sure that the ``pre-supposed'' utilities are installed.
165 Section~\ref{sect_std-utils} elaborates.
166
167 \item
168 If you have any problem when building or installing the Glasgow tools,
169 please check the ``known pitfalls'' (\sectionref{build-pitfalls}).  If
170 you feel there is still some shortcoming in our procedure or
171 instructions, please report it.
172
173 For GHC, please see the bug-reporting section of the User's guide
174 (separate document), to maximise the usefulness of your report.
175
176 If in doubt, please send a message to \tr{glasgow-haskell-bugs@dcs.gla.ac.uk}.
177 \end{enumerate}
178
179
180 %************************************************************************
181 %*                                                                      *
182 \section[port-info]{What machines the Glasgow tools, version~2.04, run on}
183 \index{ports, GHC}
184 \index{GHC ports}
185 \index{supported platforms}
186 \index{platforms, supported}
187 %*                                                                      *
188 %************************************************************************
189
190 The main question is whether or not the Haskell compiler (GHC) runs on
191 your platform.
192
193 A ``platform'' is a
194 architecture/manufacturer/operating-system combination,
195 such as @sparc-sun-solaris2.5.1@.  Other common ones are
196 @alpha-dec-osf2@, @hppa1.1-hp-hpux9@, @i386-unknown-linux@,
197 @i386-unknown-solaris2@, @i386-unknown-freebsd@, @i386-unknown-cygwin32@,
198 @m68k-sun-sunos4@, @mips-sgi-irix5@, @sparc-sun-sunos4@,
199 @sparc-sun-solaris2@, @powerpc-ibm-aix@.
200
201 Bear in mind that certain ``bundles'', e.g. parallel Haskell, may not
202 work on all machines for which basic Haskell compiling is supported.
203
204 Some libraries may only work on a limited number of platforms; for
205 example, a sockets library is of no use unless the operating system
206 supports the underlying BSDisms.
207
208 %************************************************************************
209 %*                                                                      *
210 \subsection{What platforms the Haskell compiler (GHC) runs on}
211 %*                                                                      *
212 %************************************************************************
213 \index{fully-supported platforms}
214 \index{native-code generator}
215 \index{registerised ports}
216 \index{unregisterised ports}
217
218 The GHC hierarchy of Porting Goodness: (a)~Best is a native-code
219 generator; (b)~next best is a ``registerised''
220 port; (c)~the bare minimum is an ``unregisterised'' port.
221 (``Unregisterised'' is so terrible that we won't say more about it).
222
223 We use Sun4s running SunOS~4.1.3 and Solaris 2.5, and DEC~Alphas
224 running OSF/1~V2.0, so those are the ``fully-supported'' platforms,
225 unsurprisingly.  Both have native-code generators, for quicker
226 compilations.  The native-code generator for iX86 platforms (e.g.,
227 Linux ELF) is {\em nearly} working; but is not turned on by default.
228
229 Here's everything that's known about GHC ports, as of 2.04. We
230 identify platforms by their ``canonical'' CPU/Manufacturer/OS triple.
231
232 Note that some ports are fussy about which GCC version you use; or
233 require GAS; or ...
234
235 \begin{description}
236 %-------------------------------------------------------------------
237 \item[\tr{alpha-dec-osf1}:]
238 \index{alpha-dec-osf1: fully supported}
239 (We have OSF/1 V2.0.) Fully supported, including native-code generator.
240 We recommend GCC 2.6.x or later.
241
242 %-------------------------------------------------------------------
243 \item[\tr{sparc-sun-sunos4}:]
244 \index{sparc-sun-sunos4: fully supported}
245 Fully supported, including native-code generator.
246
247 %-------------------------------------------------------------------
248 \item[\tr{sparc-sun-solaris2}:]
249 \index{sparc-sun-solaris2: fully supported}
250 Fully supported, including native-code generator.  A couple of quirks,
251 though: (a)~the profiling libraries are bizarrely huge; (b)~the
252 default \tr{xargs} program is atrociously bad for building GHC
253 libraries (see \sectionref{Pre-supposed} for details).
254
255 %-------------------------------------------------------------------
256 \item[HP-PA box running HP/UX 9.x:]
257 \index{hppa1.1-hp-hpux: registerised port}
258 Works registerised.  No native-code generator.
259 For GCC, you're best off with one of the Utah releases of
260 GCC~2.6.3 (`u3' or later), from \tr{jaguar.cs.utah.edu}.
261 We think a straight GCC 2.7.x works, too.
262
263 Concurrent/Parallel Haskell probably don't work (yet).
264 \index{hppa1.1-hp-hpux: concurrent---no}
265 \index{hppa1.1-hp-hpux: parallel---no}
266
267 %-------------------------------------------------------------------
268 \item[\tr{i386-*-linux} (PCs running Linux---ELF format):]
269 \index{i386-*-linux: registerised port}
270 GHC~2.04 works registerised.
271 You {\em must} have GCC 2.7.x or later.
272 The iX86 native-code generator is {\em nearly} there, but it
273 isn't turned on by default.
274
275 Profiling works, and Concurrent Haskell works.
276 \index{i386-*-linux: profiling---yes}
277 \index{i386-*-linux: concurrent---yes}
278 Parallel Haskell probably works.
279 \index{i386-*-linux: parallel---maybe}
280
281 On old Linux a.out systems: should be the same.
282 \index{i386-*-linuxaout: registerised port}
283
284 %-------------------------------------------------------------------
285 \item[\tr{i386-*-freebsd} (PCs running FreeBSD 2.2 or higher, and
286 NetBSD/OpenBSD using FreeBSD emulation):] \index{i386-*-freebsd:
287 registerised port} GHC~2.04 works registerised. Supports same set of
288 bundles as the above.
289
290 \index{i386-*-freebsd: profiling---yes}
291 \index{i386-*-freebsd: concurrent---yes}
292 \index{i386-*-freebsd: parallel---maybe}
293
294 %-------------------------------------------------------------------
295 \item[\tr{i386-unknown-cygwin32}:]
296 \index{i386-unknown-cygwin32: fully supported}
297 Fully supported under Win95/NT, including a native
298 code generator. Requires the @cygwin32@ compatibility library and
299 a healthy collection of GNU tools (i.e., gcc, GNU ld, bash etc.)
300 Profiling works, so does Concurrent Haskell. 
301 \index{i386-*-cygwin32: profiling---yes}
302 \index{i386-*-cygwin32: concurrent---yes}
303
304 % ToDo: more documentation on this is reqd here.
305
306 %-------------------------------------------------------------------
307 \item[\tr{mips-sgi-irix5}:]
308 \index{mips-sgi-irix5: registerised port}
309 GHC~2.04 works registerised (no native-code generator).
310 I suspect any GCC~2.6.x (or later) is OK.  The GCC that I used
311 was built with \tr{--with-gnu-as}; turns out that is important!
312
313 Concurrent/Parallel Haskell probably don't work (yet).
314 Profiling might work, but it is untested.
315 \index{mips-sgi-irix5: concurrent---no}
316 \index{mips-sgi-irix5: parallel---no}
317 \index{mips-sgi-irix5: profiling---maybe}
318
319 %-------------------------------------------------------------------
320 \item[\tr{mips-sgi-irix6}:]
321 \index{mips-sgi-irix6: registerised port}
322 Thanks to the fine efforts of Tomasz Cholewo
323 \tr{<tjchol01@mecca.spd.louisville.edu>}, GHC~2.04 works registerised
324 (no native code generator) under IRIX 6.2 and 6.3. Depends on having
325 specially tweaked version of gcc-2.7.2 around, which can be downloaded
326 from
327
328 \begin{verbatim}
329   http://mecca.spd.louisville.edu/~tjchol01/software/
330 \end{verbatim}
331
332 Profiling works, Concurrent/Parallel Haskell might work (AFAIK, untested).
333 \index{mips-sgi-irix6: concurrent---maybe}
334 \index{mips-sgi-irix6: parallel---maybe}
335 \index{mips-sgi-irix6: profiling---yes}
336
337 %-------------------------------------------------------------------
338 \item[\tr{powerpc-ibm-aix}:]
339 \index{powerpc-ibm-aix: registerised port}
340 GHC~2.04 works registerised (no native-code generator..yet).
341 I suspect 2.7.x is what you need together with this.
342
343 Concurrent/Parallel Haskell probably don't work (yet).
344 Profiling might work, but it is untested.
345 \index{mips-sgi-irix5: concurrent---no}
346 \index{mips-sgi-irix5: parallel---no}
347 \index{mips-sgi-irix5: profiling---maybe}
348
349 %-------------------------------------------------------------------
350 \item[\tr{m68k-apple-macos7} (Mac, using MPW):]
351 \index{m68k-apple-macos7: historically ported}
352 Once upon a time, David Wright in Tasmania has actually
353 gotten GHC to run on a Macintosh.  Ditto James Thomson here at Glasgow.
354 You may be able to get Thomson's from here.  (Not sure that it will
355 excite you to death, but...)
356
357 No particularly recent GHC is known to work on a Mac.
358
359 %-------------------------------------------------------------------
360 \item[\tr{m68k-next-nextstep3}:]
361 \index{m68k-next-nextstep3: historically ported}
362 Carsten Schultz succeeded with a ``registerised'' port of GHC~0.29.
363 There's probably a little bit-rot since then, but otherwise it should
364 still be fine.
365
366 Concurrent/Parallel Haskell probably won't work (yet).
367 \index{m68k-next-nextstep3: concurrent---no}
368 \index{m68k-next-nextstep3: parallel---no}
369
370 %-------------------------------------------------------------------
371 \item[\tr{m68k-sun-sunos4} (Sun3):]
372 \index{m68k-sun-sunos4: registerised port}
373 GHC~2.04 hasn't been tried on a Sun3.  GHC~0.26 worked registerised.
374 No native-code generator.
375
376 Concurrent/Parallel Haskell probably don't work (yet).
377 \index{m68k-sun-sunos4: concurrent---no}
378 \index{m68k-sun-sunos4: parallel---no}
379 \end{description}
380
381 %************************************************************************
382 %*                                                                      *
383 \subsection{What machines the other tools run on}
384 %*                                                                      *
385 %************************************************************************
386
387 Unless you hear otherwise, the other tools work if GHC works.
388
389 Haggis requires Concurrent Haskell to work.
390 \index{Haggis, Concurrent Haskell}
391
392
393 %************************************************************************
394 %*                                                                      *
395 \section[installing-bin-distrib]{Installing from binary distributions}
396 \index{binary installations}
397 \index{installation, of binaries}
398 %*                                                                      *
399 %************************************************************************
400
401 Installing from binary distributions is easiest, and recommended!
402 (Why binaries?  Because GHC is a Haskell compiler written in Haskell,
403 so you've got to ``bootstrap'' it, somehow.  We provide
404 machine-generated C-files-from-Haskell for this purpose, but it's
405 really quite a pain to use them.  If you must build GHC from its
406 sources, using a binary-distributed GHC to do so is a sensible way to
407 proceed. For the other @fptools@ programs, many are written in Haskell,
408 so binary distributions allow you to install them without having a Haskell compiler.)
409
410
411 \subsection{Bundle structure}
412
413 Binary distributions come in ``bundles,''\index{bundles of binary stuff}
414 one bundle per file called \tr{<bundle>-<platform>.tar.gz}.
415 (See Section~\ref{port-info} for what a platform is.)
416 Suppose that you untar a binary-distribution bundle, thus:
417 \begin{verbatim}
418   % cd /your/scratch/space
419   % gunzip < ghc-2.02-sun-sparc-solaris2.tar.gz | tar xvf -
420 \end{verbatim}
421 Then you should find a single directory, @fptools@, with the following
422 structure:
423 \begin{description}
424 \item[@Makefile.in@] the raw material from which the @Makefile@ will be made (\sectionref{sect_install}).
425 \item[@configure@] the configuration script (\sectionref{sect_install}).
426 \item[@README@] Contains this file summary.
427 \item[@INSTALL@] Contains this description of how to install the bundle.
428 \item[@ANNOUNCE-<bundle>@] The announcement message for the bundle.
429 \item[@NEWS-<bundle>@] release notes for the bundle -- a longer version of @ANNOUNCE@.
430 \item[@bin/<platform>/@] contains platform-specific executable files to be invoked
431 directly by the user.  These are the files that must end up in your path.
432 \item[@lib/<platform>@] contains platform-specific support files for the installation.
433 Typically there is a subdirectory for each @fptools@ project, whose name is
434 the name of the project with its version number.
435 For example, for GHC 2.02 there would be a sub-directory @ghc-2.02/@.
436
437 These sub-directories have the following general structure:
438 \begin{description}
439 \item[@libHS.a@ etc:] supporting library archives.
440 \item[@ghc-iface.prl@ etc:] support scripts.
441 \item[@import/@] Interface files (@.hi@) for the prelude.
442 \item[@include/@] A few C @#include@ files.
443 \end{description}
444
445 \item[@share/@] contains platform-independent support files for the installation.
446 Again, there is a sub-directory for each @fptools@ project.
447
448 \item[@info/@] contains Emacs info documentation files (one sub-directory per project).
449 \item[@html/@] contains HTML documentation files (one sub-directory per project).
450 \item[@man/@] contains Unix manual pages.
451 \end{description}
452 This structure is designed so that you can unpack multiple bundles (including
453 ones from different releases or platforms) into a single @fptools@ directory:
454 \begin{verbatim}
455   % cd /your/scratch/space
456   % gunzip < ghc-2.02-sun-sparc-solaris2.tar.gz | tar xvf -
457   % gunzip < happy-1.09-sun-sparc-sunos4.tar.gz | tar xvf -
458 \end{verbatim}
459 When you do multiple unpacks like this, the top level @Makefile@, @README@,
460 and @INSTALL@ get overwritten each time.  That's fine -- they should be the same.
461 Likewise, the @ANNOUNCE-<bundle>@ and @NEWS-<bundle>@ files will be duplicated
462 across multiple platforms, so they will be harmlessly overwritten when you do 
463 multiple unpacks.
464 Finally, the @share/@ stuff will get harmlessly overwritten when you do multiple
465 unpacks for one bundle on different platforms.
466
467 \subsection[sect_install]{Installing}
468
469 OK, so let's assume that you have unpacked your chosen bundles into
470 a scratch directory @fptools@. What next? Well, you will at least need
471 to run the @configure@ script by changing your directory to @fptools@.
472 That should convert @Makefile.in@ to @Makefile@.
473
474 You can now either start using the tools {\em in-situ} without going
475 through any installation process, just type @make in-place@ to set the
476 tools up for this (you have to be in the @fptools@ directory for
477 this). You'll also want to add the path which @make@ will now echo to
478 your @PATH@ environment variable. This option is useful if you simply want
479 to try out the package and/or you don't have the necessary priviledges (or
480 inclination) to properly install the tools locally. Note that if you
481 do decide to install the package `properly' at a later date, you have
482 to go through the installation steps that follows.
483
484 To install an @fptools@ package, you'll have to do the following:
485
486 \begin{enumerate}
487 \item Edit the @Makefile@ and check the settings of the following variables:
488 \begin{description}
489 \item[@platform@] the platform you are going to install for.
490 \item[@bindir@] the directory in which to install user-invokable binaries.
491 \item[@libdir@] the directory in which to install platform-dependent support files.
492 \item[@datadir@] the directory in which to install platform-independent support files. 
493 \item[@infodir@] the directory in which to install Emacs info files.
494 \item[@htmldir@] the directory in which to install HTML documentation.
495 \item[@dvidir@] the directory in which to install DVI documentation.
496 \end{description}
497 The values for these variables can be set through invocation of the
498 @configure@ script that comes with the distribution, but doing an optical
499 diff to see if the values match your expectations is always a Good Idea. 
500
501 {\em Instead of running @configure@, it is perfectly OK to copy
502 @Makefile.in@ to @Makefile@ and set all these variables directly
503 yourself.  But do it right!}
504
505 \item Run @make install@.  This {\em  should} work with ordinary Unix
506 @make@ -- no need for fancy stuff like GNU @make@. 
507
508 \item \tr{rehash} (t?csh users), so your shell will see the new stuff
509 in your bin directory.
510
511 \item
512 Once done, test your ``installation'' as suggested in
513 \sectionref{GHC_test}.  Be sure to use a \tr{-v} option, so you
514 can see exactly what pathnames it's using.
515
516 If things don't work as expected, check the list of know pitfalls
517 \sectionref{build-pitfalls}. 
518 \end{enumerate}
519
520 When installing the user-invokable binaries, this installation
521 procedure will install, say, @GHC@ version 2.02 as @ghc-2.02@.  It
522 will also make a link (in the binary installation directory) from
523 @ghc@ to @ghc-2.02@.  If you install multiple versions of GHC then the
524 last one ``wins'', and ``@ghc@'' will invoke the last one installed.
525 You can change this manually if you want.  But regardless, @ghc-2.02@
526 should always invoke @GHC@ version 2.02.
527
528 \subsection{What bundles there are}
529
530 There are plenty of ``non-basic'' GHC bundles.  The files for them are
531 called \tr{ghc-2.04-<bundle>-<platform>.tar.gz}, where the
532 \tr{<platform>} is as above, and \tr{<bundle>} is one of these:
533 \begin{description}
534 \item[\tr{prof}:]  Profiling with cost-centres.  You probably want this.
535
536 \item[\tr{conc}:] Concurrent Haskell features.  You may want this.
537
538 \item[\tr{par}:] Parallel Haskell features (sits on top of PVM).
539 You'll want this if you're into that kind of thing.
540
541 \item[\tr{gran}:] The ``GranSim'' parallel-Haskell simulator
542 (hmm... mainly for implementors).
543
544 \item[\tr{ticky}:] ``Ticky-ticky'' profiling; very detailed
545 information about ``what happened when I ran this program''---really
546 for implementors.
547
548 \item[\tr{prof-conc}:] Cost-centre profiling for Concurrent Haskell.
549
550 \item[\tr{prof-ticky}:]  Ticky-ticky profiling for Concurrent Haskell.
551 \end{description}
552
553 One likely scenario is that you will grab {\em three} binary
554 bundles---basic, profiling, and concurrent. 
555
556
557
558 %************************************************************************
559 %*                                                                      *
560 \subsection[GHC_test]{Test that GHC seems to be working}
561 \index{testing a new GHC}
562 %*                                                                      *
563 %************************************************************************
564
565 The way to do this is, of course, to compile and run {\em this} program
566 (in a file \tr{Main.hs}):
567 \begin{verbatim}
568 main = putStr "Hello, world!\n"
569 \end{verbatim}
570
571 First, give yourself a convenient way to execute the driver script
572 \tr{ghc/driver/ghc}, perhaps something like...
573 \begin{verbatim}
574 % ln -s /local/src/ghc-2.04/ghc/driver/ghc ~/bin/alpha/ghc
575 % rehash
576 \end{verbatim}
577
578 Compile the program, using the \tr{-v} (verbose) flag to verify that
579 libraries, etc., are being found properly:
580 \begin{verbatim}
581 % ghc -v -o hello Main.hs
582 \end{verbatim}
583
584 Now run it:
585 \begin{verbatim}
586 % ./hello
587 Hello, world!
588 \end{verbatim}
589
590 Some simple-but-profitable tests are to compile and run the
591 notorious \tr{nfib} program, using different numeric types.  Start
592 with \tr{nfib :: Int -> Int}, and then try \tr{Integer}, \tr{Float},
593 \tr{Double}, \tr{Rational} and maybe \tr{Complex Float}.  Code
594 for this is distributed in \tr{ghc/misc/examples/nfib/}.
595
596 For more information on how to ``drive'' GHC,
597 either do \tr{ghc -help} or consult the User's Guide (distributed in
598 \tr{ghc/docs/users_guide}).
599
600
601 %************************************************************************
602 %*                                                                      *
603 \section[Pre-supposed]{Installing pre-supposed utilities}
604 \index{pre-supposed utilities}
605 \index{utilities, pre-supposed}
606 %*                                                                      *
607 %************************************************************************
608
609 \label{sect_std-utils}
610
611 Here are the gory details about some utility programs you may need;
612 \tr{perl} and \tr{gcc} are the only important ones. (PVM is important
613 if you're going for Parallel Haskell.) The \tr{configure} script will
614 tell you if you are missing something.
615
616 \begin{description}
617 \item[Perl:]
618 \index{pre-supposed: Perl}
619 \index{Perl, pre-supposed}
620 {\em You have to have Perl to proceed!} Perl is a language quite good
621 for doing shell-scripty tasks that involve lots of text processing.
622 It is pretty easy to install.
623
624 Perl~5 is the current version; GHC should be Perl~4 friendly though.
625 For Win32 platforms, Perl~5 is recommended, we even strongly suggest
626 you pick up a port of Perl~5 for \tr{cygwin32}, as the common
627 Hip/ActiveWare port of Perl is not Cool Enough for our purposes.
628
629 Perl should be put somewhere so that it can be invoked by the \tr{#!}
630 script-invoking mechanism. (I believe \tr{/usr/bin/perl} is preferred;
631 we use \tr{/usr/local/bin/perl} at Glasgow.)  The full pathname should
632 be less than 32 characters long.
633
634 \item[GNU C (\tr{gcc}):]
635 \index{pre-supposed: GCC (GNU C compiler)}
636 \index{GCC (GNU C compiler), pre-supposed}
637 The current version is 2.7.2.
638
639 If your GCC dies with ``internal error'' on some GHC source file,
640 please let us know, so we can report it and get things improved.
641 (Exception: on \tr{iX86} boxes---you may need to fiddle with GHC's
642 \tr{-monly-N-regs} option; ask if confused...)
643
644 \item[PVM version 3:]
645 \index{pre-supposed: PVM3 (Parallel Virtual Machine)}
646 \index{PVM3 (Parallel Virtual Machine), pre-supposed}
647 PVM is the Parallel Virtual Machine on which Parallel Haskell programs
648 run.  (You only need this if you plan to run Parallel Haskell.  
649 Concurent Haskell, which runs concurrent threads on a uniprocessor
650 doesn't need it.)
651 Underneath PVM, you can have (for example) a network of
652 workstations (slow) or a multiprocessor box (faster).
653
654 The current version of PVM is 3.3.11; we use 3.3.7.  It is readily
655 available on the net; I think I got it from \tr{research.att.com}, in
656 \tr{netlib}.
657
658 A PVM installation is slightly quirky, but easy to do.  Just follow
659 the \tr{Readme} instructions.
660
661 \item[\tr{xargs} on Solaris2:]
662 \index{xargs, presupposed (Solaris only)}
663 \index{Solaris: alternative xargs}
664 The GHC libraries are put together with something like:
665 \begin{verbatim}
666 find bunch-of-dirs -name '*.o' -print | xargs ar q ...
667 \end{verbatim}
668 Unfortunately the Solaris \tr{xargs} (the shell-script equivalent
669 of \tr{map}) only ``bites off'' the \tr{.o} files a few at a
670 time---with near-infinite rebuilding of the symbol table in
671 the \tr{.a} file.
672
673 The best solution is to install a sane \tr{xargs} from the GNU
674 findutils distribution.  You can unpack, build, and install the GNU
675 version in the time the Solaris \tr{xargs} mangles just one GHC
676 library.
677
678 \item[\tr{bash} (Parallel Haskell only):]
679 \index{bash, presupposed (Parallel Haskell only)}
680 Sadly, the \tr{gr2ps} script, used to convert ``parallelism profiles''
681 to PostScript, is written in Bash (GNU's Bourne Again shell).
682 This bug will be fixed (someday).
683
684 \item[Makeindex:]
685 \index{pre-supposed: makeindex}
686 \index{makeindex, pre-supposed}
687 You won't need this unless you are re-making our documents.  Makeindex
688 normally comes with a \TeX{} distribution, but if not, we can provide
689 the latest and greatest.
690
691 \item[Tgrind:]
692 \index{pre-supposed: tgrind}
693 \index{tgrind, pre-supposed}
694 This is required only if you remake lots of our documents {\em and}
695 you use the \tr{-t tgrind} option with \tr{lit2latex} (also literate
696 programming), to do ``fancy'' typesetting of your code.  {\em
697 Unlikely.}
698
699 \item[Flex:]
700 \index{pre-supposed: flex}
701 \index{flex, pre-supposed}
702 This is a quite-a-bit-better-than-Lex lexer.  Used in the
703 literate-programming stuff.  You won't need it unless you're hacking
704 on some of our more obscure stuff.
705
706 \item[Yacc:]
707 \index{pre-supposed: non-worthless Yacc}
708 \index{Yacc, pre-supposed}
709 If you mess with the Haskell parser, you'll need a Yacc that can cope.
710 The unbundled \tr{/usr/lang/yacc} is OK; the GNU \tr{bison} is OK;
711 Berkeley yacc, \tr{byacc}, is not OK.
712
713 \item[@sed@]
714 \index{pre-supposed: sed}
715 \index{sed, pre-supposed}
716 You need a working @sed@ if you are going to build from sources.
717 The build-configuration stuff needs it.
718 GNU sed version 2.0.4 is no good! It has a bug in it that is tickled
719 by the build-configuration.  2.0.5 is ok. Others are probably ok too
720 (assuming we don't create too elaborate configure scripts..)
721 \end{description}
722
723 Two @fptools@ projects are worth a quick note at this point, because
724 they are useful for all the others:
725 \begin{itemize}
726 \item @glafp-utils@ contains several utilities which aren't
727 particularly Glasgow-ish, but Occasionally Indispensable. Like
728 @lndir@ for creating symbolic link trees.
729
730 \item @literate@ contains the Glasgow-built tools for generating
731 documentation.  (The unoriginal idea is to be able to generate @latex@, @info@,
732 and program code from a single source file.) To get anywhere you'll
733 need at least @lit2pgm@, either from the @literate@ project, or
734 because it's already installed on your system. 
735 \end{itemize}
736
737
738
739 %************************************************************************
740 %*                                                                      *
741 \section{Building from source}
742 %*                                                                      *
743 %************************************************************************
744
745 You've been rash enough to want to build some of
746 the Glasgow Functional Programming tools (GHC, Happy,
747 nofib, etc) from source.  You've slurped the source,
748 from the CVS repository or from a source distribution, and
749 now you're sitting looking at a huge mound of bits, wondering
750 what to do next.
751
752 Gingerly, you type @make all@.  Wrong already!
753
754 This rest of this guide is intended for duffers like me, who aren't really
755 interested in Makefiles and systems configurations, but who need
756 a mental model of the interlocking pieces so that they can 
757 make them work, extend them consistently when adding new
758 software, and lay hands on them gently when they don't work.
759
760 \subsection{Your source tree}
761
762 The source code is held in your {\em source tree}.
763 The root directory of your source tree {\em must}
764 contain the following directories and files:
765 \begin{itemize}
766 \item @Makefile@: the root Makefile.
767 \item @mk/@: the directory that contains the
768 main Makefile code, shared by all the
769 @fptools@ software.
770 \item @configure.in@: a file that tells the GNU configuration 
771 tools what @fptools@ needs to know about the host platform and
772 operating system. 
773 \end{itemize}
774 All the other directories are individual {\em projects} of the
775 @fptools@ system --- for example, the Glasgow Haskell Compiler (@ghc@),
776 the Happy parser generator (@happy@), the @nofib@ benchmark suite, 
777 and so on.
778 You can have zero or more of these.  Needless to say, some of them
779 are needed to build others.  For example, you need @happy@ to build
780 @ghc@.  You can either grab @happy@ too, or else you can use
781 a version of @happy@ that's already installed on your system, or 
782 grab a binary distribution of @happy@ and install it.
783
784 The important thing to remember is that even if you want only
785 one project (@happy@, say), you must have a source tree
786 whose root directory contains @Makefile@, 
787 @mk/@, @configure.in@, and the project(s) you 
788 want (@happy/@ in this case).  You cannot get by with 
789 just the @happy/@ directory.
790
791 \subsection{Build trees}
792
793 While you can build a system in the source tree, we don't recommend it.
794 We often want to build multiple versions of our software
795 for different architectures, or with different options (e.g. profiling).
796 It's very desirable to share a single copy of the source code among
797 all these builds.
798
799 So for every source tree we have zero or more {\em build trees}.  Each
800 build tree is initially an exact copy of the source tree, except that
801 each file is a symbolic link to the source file, rather than being a
802 copy of the source file.  There are ``standard'' Unix utilities that
803 make such copies, so standard that they go by different names:
804 @lndir@, @mkshadowdir@ are two (If you don't have either, the source
805 distribution includes sources for the \tr{X11} \tr{lndir} --- check
806 out \tr{fptools/glafp-utils/lndir} ).
807
808 The build tree does not need to be anywhere near the source tree in
809 the file system.  Indeed, one advantage of separating the build tree
810 from the source is that the build tree can be placed in a
811 non-backed-up partition, saving your systems support people from
812 backing up untold megabytes of easily-regenerated, and
813 rapidly-changing, gubbins.  The golden rule is that (with a single
814 exception -- Section~\ref{sect_build-config}) {\em absolutely
815 everything in the build tree is either a symbolic link to the source
816 tree, or else is mechanically generated}.  It should be perfectly OK
817 for your build tree to vanish overnight; an hour or two compiling and
818 you're on the road again.
819
820 You need to be a bit careful, though, that any new files you create
821 (if you do any development work) are in the source tree, not a build tree!
822
823 Remember, that the source files in the build tree are {\em symbolic
824 links} to the files in the source tree.  (The build tree soon
825 accumulates lots of built files like @Foo.o@, as well.)  You can {\em
826 delete} a source file from the build tree without affecting the source
827 tree (though it's an odd thing to do).  On the other hand, if you {\em
828 edit} a source file from the build tree, you'll edit the source-tree
829 file directly.  (You can set up Emacs so that if you edit a source
830 file from the build tree, Emacs will silently create an edited copy of
831 the source file in the build tree, leaving the source file unchanged;
832 but the danger is that you think you've edited the source file whereas
833 actually all you've done is edit the build-tree copy.  More commonly
834 you do want to edit the source file.)
835
836 Like the source tree, the top level of your build tree must (a linked
837 copy of) the root directory of the @fptools@ suite.  Inside Makefiles,
838 the root of your build tree is called @$(FPTOOLS_TOP)@.  In the rest
839 of this document path names are relative to @$(FPTOOLS_TOP)@ unless
840 otherwise stated.  For example, the file @ghc/mk/target.mk@ is
841 actually @$(FPTOOLS_TOP)/ghc/mk/target.mk@.
842
843
844 \subsection{Getting the build you want}
845 \label{sect_build-config}
846
847 When you build @fptools@ you will be compiling code on a particular
848 {\em host platform}, to run on a particular {\em target platform}
849 (usually the same as the host platform)\index{platform}.  The
850 difficulty is that there are minor differences between different
851 platforms; minor, but enough that the code needs to be a bit different
852 for each.  There are some big differences too: for a different
853 architecture we need to build GHC with a different native-code
854 generator.
855
856 There are also knobs you can turn to control how the @fptools@
857 software is built.  For example, you might want to build GHC optimised
858 (so that it runs fast) or unoptimised (so that you can compile it fast
859 after you've modified it.  Or, you might want to compile it with
860 debugging on (so that extra consistency-checking code gets included)
861 or off.  And so on.
862
863 All of this stuff is called the {\em configuration} of your build.
864 You set the configuration using an exciting three-step process.
865 \begin{description}
866 \item[Step 1: get ready for configuration.]
867 Change directory to @$(FPTOOLS)@ and issue the following two commands (with no arguments):
868 \begin{enumerate}
869 \item @autoconf@. This GNU program
870 converts @$(FPTOOLS)/configure.in@ to a shell script 
871 called @$(FPTOOLS)/configure@.
872
873 \item @autoheader@.  This second GNU program converts
874 @$(FPTOOLS)/configure.in@ to @$(FPTOOLS)/mk/config.h.in@.
875 \end{enumerate}
876 Both these steps are completely platform-independent; they just mean
877 that the human-written file (@configure.in@) can be short, although
878 the resulting shell script, @configure@, and @mk/config.h.in@, are long.
879
880 In case you don't have @autoconf@ and @autoheader@ we distribute
881 the results, @configure@, and @mk/config.h.in@, with the source distribution.
882 They aren't kept in the repository, though.
883
884 \item[Step 2: system configuration.]
885 Runs the newly-created @configure@ script, thus:
886 \begin{verbatim}
887   ./configure
888 \end{verbatim}
889 @configure@'s mission
890 is to scurry round your computer working out what architecture it has,
891 what operating system, whether it has the @vfork@ system call,
892 where @yacc@ is kept, whether @gcc@ is available, where various
893 obscure @#include@ files are, whether it's a leap year, and
894 what the systems manager had for lunch.
895 It communicates these snippets of information in two ways:
896 \begin{itemize}
897 \item It translates @mk/config.mk.in@ to @mk/config.mk@,
898 substituting for things between ``{\tt @@@@}'' brackets.  So,
899 ``{\tt @@HaveGcc@@}'' will be replaced by ``@YES@'' or ``@NO@''
900 depending on what @configure@ finds.
901 @mk/config.mk@ is included by every Makefile (directly or indirectly),
902 so the configuration information is thereby communicated to
903 all Makefiles.
904
905 \item It translates @mk/config.h.in@ to @mk/config.h@.
906 The latter is @#include@d by various C programs, which
907 can thereby make use of configuration information.
908 \end{itemize}
909
910
911 \item[Step 3: build configuration.] Next, you say how this build
912 of @fptools@ is to differ from the standard defaults by creating a new 
913 file @mk/build.mk@
914 {\em in the build tree}.  This file is the one and only
915 file you edit in the build tree, precisely because it says how
916 this build differs from the source.  (Just in case your build tree
917 does die, you might want to keep a private directory of @build.mk@ files,
918 and use a symbolic link in each build tree to point to the appropriate one.)
919 So @mk/build.mk@ never
920 exists in the source tree --- you create one in each build tree
921 from the template.  We'll discuss what to put in it shortly.
922 \end{description}
923 And that's it for configuration. Simple, eh?
924
925 What do you put in your build-specific configuration
926 file @mk/build.mk@?  {\em For almost all purposes all you will do is
927 put make variable definitions that override those in @mk/config.mk.in@}.
928 The whole point of @mk/config.mk.in@ --- and its derived 
929 counterpart @mk/config.mk@ --- is to define the build configuration. It is heavily
930 commented, as you will see if you look at it.
931 So generally, what you do is edit @mk/config.mk.in@ (read-only), and add definitions
932 in @mk/build.mk@ that override any of the @config.mk@ definitions that you
933 want to change.  (The override occurs because the main boilerplate file,
934 @mk/boilerplate.mk@, includes @build.mk@ after @config.mk@.)
935
936 For example, @config.mk.in@ contains the definition:
937 \begin{verbatim}
938   ProjectsToBuild = glafp-utils literate ghc hslibs
939 \end{verbatim}
940 The accompanying comment explains that this is the list of enabled
941 projects; that is, if (after configuring) you type @gmake all@
942 in @FPTOOLS_TOP@ three specified projects will be made.
943 If you want to add @happy@, you can add this line to @build.mk@:
944 \begin{verbatim}
945   ProjectsToBuild += happy
946 \end{verbatim}
947 or, if you prefer,
948 \begin{verbatim}
949   ProjectsToBuild = glafp-utils literate ghc hslibs happy
950 \end{verbatim}
951 (GNU @make@ allows existing definitions to have new text appended using
952 the ``@+=@'' operator, which is quite a convenient feature.)
953
954 When reading @config.mk.in@, remember that anything between ``{\tt @@...@@}'' signs
955 is going to be substituted by @configure@ later.  You {\em can} override
956 the resulting definition if you want, 
957 but you need to be a bit surer what you are doing.
958 For example, there's a line that says:
959 \begin{verbatim}
960   YACC = @Yacc@
961 \end{verbatim}
962 This defines the Make variables @YACC@ to the pathname for a Yacc that
963 @configure@ finds somewhere.  If you have your own pet Yacc you want
964 to use instead, that's fine. Just add this line to @mk/build.mk@:
965 \begin{verbatim}
966   YACC = myyacc
967 \end{verbatim}
968 You do not {\em have} to have a @mk/build.mk@ file at all; if you don't,
969 you'll get all the default settings from @mk/config.mk.in@.
970
971
972 \subsection{The story so far}
973
974 Let's summarise the steps you need to carry to get yourself
975 a fully-configured build tree from scratch.
976
977 \begin{enumerate}
978 \item Get your source tree from somewhere (CVS repository or
979 source distribution).  Say you call the root directory
980 @myfptools@ (it does not have to be called @fptools@).
981
982 \item Use @lndir@ or @mkshadowdir@ to create a build tree.
983 \begin{verbatim}
984     cd myfptools
985     mkshadowdir . /scratch/joe-bloggs/myfptools-sun4
986 \end{verbatim}
987 You probably want to give the build tree a name that
988 suggests its main defining characteristic (in your mind at least),
989 in case you later add others.
990
991 \item Change directory to the build tree.  Everything is going
992 to happen there now.
993 \begin{verbatim}
994     cd /scratch/joe-bloggs/myfptools-sun4
995 \end{verbatim}
996 \item Prepare for system configuration:
997 \begin{verbatim}
998     autoconf
999     autoheader
1000 \end{verbatim}
1001 (You can skip this step if you are starting from a source distribution,
1002 and you already have @configure@ and @mk/config.h.in@.)
1003
1004 \item Do system configuration:
1005 \begin{verbatim}
1006     ./configure
1007 \end{verbatim}
1008
1009 \item Create the file @mk/build.mk@, 
1010 adding definitions for your desired configuration options.
1011 \begin{verbatim}
1012     emacs mk/build.mk
1013 \end{verbatim}
1014 \end{enumerate}
1015 You can make subsequent changes to @mk/build.mk@ as often 
1016 as you like.  You do not have to run any further configuration 
1017 programs to make these changes take effect.
1018 In theory you should, however, say @gmake clean@, @gmake all@,
1019 because configuration option changes could affect anything --- but in practice you are likely to know what's affected.
1020
1021 \subsection{Making things}
1022
1023 At this point you have made yourself a fully-configured build tree,
1024 so you are ready to start building real things.
1025
1026 The first thing you need to know is that 
1027 {\em you must use GNU @make@, usually called @gmake@, not standard Unix @make@}.
1028 If you use standard Unix @make@ you will get all sorts of error messages
1029 (but no damage) because the @fptools@ @Makefiles@ use GNU @make@'s facilities
1030 extensively.
1031
1032 \subsection[sect_standard-targets]{Standard targets}
1033
1034 In any directory you should be able to make the following:
1035 \begin{description}
1036 \item[@boot@:] does the one-off preparation required to get ready
1037 for the real work.  Notably, it does @gmake depend@ in all directories
1038 that contain programs.  But @boot@ does more.  For example, you can't
1039 do @gmake depend@ in a directory of C program until you have converted
1040 the literate @.lh@ header files into standard @.h@ header files.
1041 Similarly, you convert a literate file to illiterate form until you
1042 have built the @literate@ tools.  @boot@ takes care of these
1043 inter-directory dependencies.
1044
1045 You should say @gmake boot@ right after configuring your build tree,
1046 but note that this is a one-off, i.e., there's no need to re-do
1047 @gmake boot@ if you should re-configure your build tree at a later
1048 stage (no harm caused if you do though).
1049
1050 \item[@all@:] makes all the final target(s) for this Makefile.
1051 Depending on which directory you are in a ``final target''
1052 may be an executable program, a library archive, a shell script,
1053 or a Postscript file.
1054 Typing @gmake@ alone is generally the same as typing @gmake all@.
1055
1056 \item[@install@:] installs the things built by @all@.  Where does it
1057 install them?  That is specified by @mk/config.mk.in@; you can 
1058 override it in @mk/build.mk@.
1059
1060 \item[@uninstall@:] reverses the effect of @install@.
1061
1062 \item[@clean@:] remove all easily-rebuilt files.
1063
1064 \item[@veryclean@:] remove all files that can be rebuilt at all.
1065 There's a danger here that you may remove a file that needs a more
1066 obscure 
1067 utility to rebuild it (especially if you started from a source
1068 distribution).
1069
1070 \item[@check@:] run the test suite.
1071 \end{description}
1072 All of these standard targets
1073 automatically recurse into sub-directories.
1074 Certain other standard targets do not:
1075 \begin{description}
1076 \item[@configure@:] is only available in the root directory @$(FPTOOLS)@;
1077 it has been discussed in Section~\ref{sect_build-config}.
1078
1079 \item[@depend@:] make a @.depend@ file in each directory that needs
1080 it. This @.depend@ file contains mechanically-generated dependency
1081 information; for example, suppose a directory contains a Haskell 
1082 source module @Foo.lhs@ which imports another module @Baz@.
1083 Then the generated @.depend@ file will contain the dependency:
1084 \begin{verbatim}
1085   Foo.o : Baz.hi
1086 \end{verbatim}
1087 which says that the object file @Foo.o@ depends on the interface
1088 file @Baz.hi@ generated by compiling module @Baz@.
1089 The @.depend@ file is automatically included by every Makefile.
1090
1091 \item[@binary-dist@:] make a binary distribution.
1092
1093 \item[@dist@:] make a source distribution.
1094 \end{description}
1095
1096 \subsection{Other targets}
1097
1098 Most @Makefiles@ have targets other than these.  You can find
1099 this out by looking in the @Makefile@ itself.
1100
1101
1102
1103
1104 %************************************************************************
1105 %*                                                                      *
1106 \section{The @Makefile@ architecture}
1107 %*                                                                      *
1108 %************************************************************************
1109
1110
1111 @make@ is great if everything works --- you type @gmake install@ and, lo,
1112 the right things get compiled and installed in the right places.
1113 Our goal is to make this happen often, but somehow it often doesn't;
1114 instead
1115 some wierd error message eventually emerges from the bowels of a directory
1116 you didn't know existed.
1117
1118 The purpose of this section is to give you a road-map to help you figure
1119 out what is going right and what is going wrong.
1120
1121 \subsection{A small project}
1122
1123 To get started, let us look at the @Makefile@ for an imaginary small
1124 @fptools@ project, @small@.  Each project in @fptools@ has its own
1125 directory in @FPTOOLS_TOP@, so the @small@ project will have its own
1126 directory @FPOOLS_TOP/small/@.  Inside the @small/@ directory there
1127 will be a @Makefile@, looking something like this:
1128 \begin{verbatim}
1129   #     Makefile for fptools project "small"
1130
1131   TOP = ..
1132   include $(TOP)/mk/boilerplate.mk
1133
1134   SRCS = $(wildcard *.lhs) $(wildcard *.c)
1135   HS_PROG = small
1136
1137   include $(TOP)/target.mk
1138 \end{verbatim}
1139 This @Makefile@ has three sections:
1140 \begin{enumerate}
1141 \item The first section includes\footnote{One of the
1142 most important features of GNU @make@ that we use is the ability
1143 for a @Makefile@ to include another named file, very like @cpp@'s @#include@ directive.}
1144 a file of ``boilerplate'' code from the
1145 level above (which in this case will be @FPTOOLS_TOP/mk/boilerplate.mk@).
1146 As its name suggests, @boilerplate.mk@ consists of a large quantity of standard
1147 @Makefile@ code.  We discuss this boilerplate in more detail in Section~\ref{sect_boiler}.
1148
1149 Before the @include@ statement, you must define the @make@ variable
1150 @TOP@ to be the directory containing the @mk@ directory in which
1151 the @boilerplate.mk@ file is.
1152 It is {\em not} OK to simply say
1153 \begin{verbatim}
1154   include ../mk/boilerplate.mk  # NO NO NO
1155 \end{verbatim}
1156 Why?  Because the @boilerplate.mk@ file needs to know where it is,
1157 so that it can, in turn, @include@ other files.
1158 (Unfortunately, when an @include@d file does an
1159 @include@, the filename is treated
1160 relative to the directory in which @gmake@ is being run, not
1161 the directory in which the @included@ sits.) 
1162 In general,
1163 {\em every file @foo.mk@ 
1164 assumes that @$(TOP)/mk/foo.mk@ refers to itself.}  
1165 It is up to the @Makefile@ doing the @include@ to ensure this
1166 is the case.
1167
1168 Files intended for inclusion in other @Makefile@s are written to have
1169 the following property:
1170 {\em after @foo.mk@ is @include@d, it leaves @TOP@ containing the same
1171 value as it had just before the @include@ statement}.
1172 In our example, this invariant guarantees that the @include@
1173 for @target.mk@ will look in the same directory as that for
1174 @boilerplate.mk@.
1175
1176 \item The second section 
1177 defines the following standard @make@ variables: @SRCS@ (the source files from
1178 which is to be built), and @HS_PROG@ (the
1179 executable binary to be built).  
1180 We will discuss in more detail what the ``standard variables'' are,
1181 and how they affect what happens, in Section~\ref{sect_targets}.
1182
1183 The definition for @SRCS@ uses the useful GNU @make@
1184 construct @$(wildcard@~$pat$@)@, which expands to a list of all the
1185 files matching the pattern $pat$ in the current directory.
1186 In this example, @SRCS@ is set to the list of all the @.lhs@ and @.c@ files
1187 in the directory.  (Let's suppose there is one of each, @Foo.lhs@
1188 and @Baz.c@.)
1189
1190 \item The last section includes a second file of standard code,
1191 called @target.mk@.  It contains the rules that tell @gmake@
1192 how to make the standard targets
1193 (Section~\ref{sect_standard-targets}).
1194 Why, you ask, can't this standard code
1195 be part of @boilerplate.mk@?  Good question.
1196 We discuss the reason later, in Section~\ref{sect_boiler-arch}.
1197
1198 You do not {\em have} to @include@ the @target.mk@ file.  Instead,
1199 you can write rules of your own for all the standard targets.
1200 Usually, though, you will find quite a big payoff from using
1201 the canned rules in
1202 @target.mk@; the price tag is that you have to understand
1203 what canned rules get enabled, and what they do (Section~\ref{sect_targets}).
1204 \end{enumerate}
1205
1206 In our example @Makefile@, most of the work is done 
1207 by the two @include@d files.  When you say @gmake all@,
1208 the following things happen:
1209 \begin{itemize}
1210 \item @gmake@ figures out that the object files are @Foo.o@ and @Baz.o@.
1211 \item It uses a boilerplate pattern rule to compile 
1212 @Foo.lhs@ to @Foo.o@ using
1213 a Haskell compiler.  (Which one?  That is set in the build configuration.)
1214 \item It uses another standard pattern rule to compile @Baz.c@ to @Baz.o@,
1215 using a C compiler.  (Ditto.)
1216 \item It links the resulting @.o@ files together to make @small@,
1217 using the Haskell compiler to do the link step.  (Why not use @ld@?  Because
1218 the Haskell compiler knows what standard librarise to link in.  How did @gmake@
1219 know to use the Haskell compiler to do the link, rather than the C compiler?
1220 Because we set the variable @HS_PROG@ rather than @C_PROG@.)
1221 \end{itemize}
1222 All @Makefile@s should follow the above three-section format.
1223
1224 \subsection{A larger project}
1225
1226 Larger projects are usually structured into a nummber of sub-directories,
1227 each of which has its own @Makefile@.  (In very large projects, this
1228 sub-structure might be iterated recursively, though that is rare.)
1229 To give you the idea, here's part of the directory structure for
1230 the (rather large) @ghc@ project:
1231 \begin{verbatim}
1232   $(FPTOOLS_TOP)/ghc/
1233     Makefile
1234
1235     mk/
1236       boilerplate.mk
1237       rules.mk
1238
1239     docs/
1240       Makefile
1241       ...source files for documentation...
1242
1243     driver/
1244       Makefile
1245       ...source files for driver...
1246
1247     compiler/
1248       Makefile
1249       parser/...source files for parser...
1250       renamer/...source files for renamer...
1251       ...etc...
1252 \end{verbatim}
1253 The sub-directories @docs@, @driver@, @compiler@, and so on, each contains
1254 a sub-component of @ghc@, and each has its own @Makefile@.
1255 There must also be a @Makefile@ in @$(FPTOOLS_TOP)/ghc@.
1256 It does most of its work by recursively invoking @gmake@
1257 on the @Makefile@s in the sub-directories.
1258 We say that @ghc/Makefile@ is a {\em non-leaf @Makefile@},
1259 because it does little except organise its children, while the @Makefile@s
1260 in the sub-directories are all {\em leaf @Makefile@s}.  (In principle
1261 the sub-directories might themselves contain a non-leaf @Makefile@ and
1262 several sub-sub-directories, but that does not happen in @ghc@.)
1263
1264 The @Makefile@ in @ghc/compiler@ is considered a leaf @Makefile@ even
1265 though the @ghc/compiler@ has sub-directories, because these sub-directories
1266 do not themselves have @Makefile@ in them.  They are just used to structure
1267 the collection of modules that make up @ghc@, but all are managed by the
1268 single @Makefile@ in @ghc/compiler@.
1269
1270 You will notice that @ghc/@ also contains a directory @ghc/mk/@.
1271 It contains @ghc@-specific @Makefile@ boilerplate code.
1272 More precisely:
1273 \begin{itemize}
1274 \item @ghc/mk/boilerplate.mk@ is included at the top of @ghc/Makefile@,
1275 and of all the leaf @Makefile@s in the sub-directories.
1276 It in turn @include@s the main boilerplate file @mk/boilerplate.mk@.
1277
1278 \item @ghc/mk/target.mk@ is @include@d at the bottom of @ghc/Makefile@,
1279 and of all the leaf @Makefiles@ in the sub-directories.
1280 It in turn @include@s the file @mk/target.mk@.
1281 \end{itemize}
1282 So these two files are the place to look for @ghc@-wide customisation
1283 of the standard boilerplate.
1284
1285
1286
1287 \subsection{Boilerplate architecture}
1288 \label{sect_boiler-arch}
1289
1290 Every @Makefile@ includes a @boilerplate.mk@ file at the top,
1291 and @target.mk@ file at the bottom.  In this section we discuss
1292 what is in these files, and why there have to be two of them.
1293 In general:
1294 \begin{itemize}
1295 \item @boilerplate.mk@ consists of:
1296 \begin{itemize}
1297 \item {\em Definitions of millions of @make@ variables} that collectively
1298 specify the build configuration.  Examples: @HC_OPTS@, the options to
1299 feed to the Haskell compiler; @NoFibSubDirs@, the sub-directories to
1300 enable within the @nofib@ project; @GhcWithHc@, the name of the
1301 Haskell compiler to use when compiling @GHC@ in the @ghc@ project.
1302 \item {\em Standard pattern rules} that tell @gmake@ how to construct
1303 one file from another.  
1304 \end{itemize}
1305 @boilerplate.mk@ needs to be @include@d at the {\em top} of each 
1306 @Makefile@, so that the 
1307 user can replace the boilerplate definitions or pattern rules by simply 
1308 giving a new definition or pattern rule in the @Makefile@.  @gmake@ simply
1309 takes the last definition as the definitive one.
1310
1311 Instead of {\em replacing} boilerplate definitions, it is also quite
1312 common to {\em augment} them. For example, a @Makefile@ might say:
1313 \begin{verbatim}
1314   SRC_HC_OPTS += -O
1315 \end{verbatim}
1316 thereby adding ``@-O@'' to the end of @SRC_HC_OPTS@. 
1317
1318 \item @target.mk@ contains @make@ rules for the standard targets described
1319 in Section~\ref{sect_standard-targets}.
1320 These rules are selectively included, depending on the setting of
1321 certain @make@ variables.  These variables are usually set in the middle
1322 section of the @Makefile@ between the two @include@s.
1323
1324 @target.mk@ must be included at the end (rather than being part of @boilerplate.mk@)
1325 for several tiresome reasons:
1326 \begin{itemize}
1327 \item @gmake@ commits target and dependency lists earlier than it should.
1328 For example, @target.mk@ has a rule that looks like this:
1329 \begin{verbatim}
1330   $(HS_PROG) : $(OBJS)
1331         $(HC) $(LD_OPTS) $< -o $@
1332 \end{verbatim}
1333 If this rule was in @boilerplate.mk@ then @$(HS_PROG)@ and @$(OBJS)@
1334 would not have their final values at the moment @gmake@ encountered the
1335 rule.  Alas, @gmake@ takes a snapshot of their current values, and 
1336 wires that snapshot into the rule.
1337 (In contrast, the commands executed when the rule ``fires'' are
1338 only substituted at the moment of firing.)
1339 So, the rule must follow the definitions given in the @Makefile@ itself.
1340
1341 \item Unlike pattern rules, ordinary rules cannot be overriden or
1342 replaced by subsequent rules for the same target (at least not without an
1343 error message).  Including ordinary rules in @boilerplate.mk@ would
1344 prevent the user from writing rules for specific targets in specific cases.
1345
1346 \item There are a couple of other reasons I've forgotten, but it doesn't
1347 matter too much.
1348 \end{itemize}
1349 \end{itemize}
1350
1351 \subsection{The main @mk/boilerplate.mk@ file}
1352 \label{sect_boiler}
1353
1354 If you look at @$(FPTOOLS_TOP)/mk/boilerplate.mk@ you will find that
1355 it consists of the following sections, each held in a separate file:
1356 \begin{description}
1357 \item[@config.mk@] is the build configuration file we discussed at length
1358 in Section~\ref{sect_build-config}.
1359
1360 \item[@paths.mk@] defines @make@ variables for pathnames and file
1361 lists.  In particular, it gives definitions for:
1362 \begin{description}
1363 \item[@SRCS@:] all source files in the current directory.
1364 \item[@HS_SRCS@:] all Haskell source files in the current directory.
1365 It is derived from @$(SRCS)@, so if you override @SRCS@ with a new value
1366 @HS_SRCS@ will follow suit.
1367 \item[@C_SRCS@:] similarly for C source files.
1368 \item[@HS_OBJS@:] the @.o@ files derived from @$(HS_SRCS)@.
1369 \item[@C_OBJS@:] similarly for @$(C_SRCS)@.
1370 \item[@OBJS@:] the concatenation of @$(HS_OBJS)@ and @$(C_OBJS)@.
1371 \end{description}
1372 Any or all of these definitions can easily be overriden by giving new
1373 definitions in your @Makefile@.  For example, 
1374 if there are things in the current directory that look like source files
1375 but aren't, then you'll need to set @SRCS@ manually in your @Makefile@.
1376 The other definitions will then work from this new definition.
1377
1378 What, exactly, does @paths.mk@ consider a ``source file'' to be.
1379 It's based the file's suffix (e.g. @.hs@, @.lhs@, @.c@, @.lc@, etc), 
1380 but this is the kind of detail that changes
1381 more rapidly, so rather than enumerate the source suffices here the best thing
1382 to do is to look in @paths.mk@.
1383
1384 \item[@opts.mk@] defines @make@ variables for option strings to
1385 pass to each program. For example, it defines @HC_OPTS@, the
1386 option strings to pass to the Haskell compiler.  See  \sectionref{sect_suffix}.
1387
1388 \item[@suffix.mk@] defines standard pattern rules -- see \sectionref{sect_suffix}
1389 \end{description}
1390 Any of the variables and pattern rules defined by the boilerplate file
1391 can easily be overridden in any particular @Makefile@, because
1392 the boilerplace @include@ comes first.  Definitions after this
1393 @include@ directive simply override the default ones in @boilerplate.mk@.
1394
1395 \subsection[sect_suffix]{Pattern rules and options}
1396
1397 The file @suffix.mk@ defines standard {\em pattern rules} that say how to build one kind
1398 of file from another, for example, how to build a @.o@ file from a @.c@ file.
1399 (GNU @make@'s {\em pattern rules} are more powerful and easier to use than
1400 Unix @make@'s {\em suffix rules}.)
1401
1402 Almost all the rules look something like this:
1403 \begin{verbatim}
1404 %.o : %.c
1405         @$(RM) $@
1406         $(CC) $(CC_OPTS) -c $< -o $@
1407 \end{verbatim}
1408 Here's how to understand the rule.  It says that $something@.o@$ (say @Foo.o@)
1409 can be built from $something@.c@$ (@Foo.c@), by invoking the C compiler
1410 (path name held in @$(CC)@), passing to it the options @$(CC_OPTS)@ and the rule's 
1411 dependent
1412 file of the rule @$<@ (@Foo.c@ in this case), and putting the result in
1413 the rule's target @$@@@ (@Foo.o@ in this case).
1414
1415 Every program is held in a @make@ variable defined in @mk/config.mk@ --- look in @mk/config.mk@ for
1416 the complete list.  One important one is the Haskell compiler, which is called @$(HC)@.
1417
1418 Every programs options are are held in a @make@ variables called @<prog>_OPTS@.
1419 the @<prog>_OPTS@ variables are defined in @mk/opts.mk@.  Almost all of them are defined
1420 like this:
1421 \begin{verbatim}
1422   CC_OPTS = $(SRC_CC_OPTS) $(WAY$(_way)_CC_OPTS) $($*_CC_OPTS) $(EXTRA_CC_OPTS)
1423 \end{verbatim}
1424 The four variables from which @CC_OPTS@ is built have the following meaning:
1425 \begin{description}
1426 \item[@SRC_CC_OPTS@:] options passed to all C compilations.
1427 \item[@WAY_<way>_CC_OPTS@:] options passed to C compilations for way @<way>@. For example,
1428 @WAY_mp_CC_OPTS@ gives options to pass to the C compiler when compiling way @mp@.
1429 The variable @WAY_CC_OPTS@ holds options to pass to the C compiler when compiling the standard way.
1430 (Section~\ref{sect_ways} dicusses multi-way compilation.)
1431 \item[@<module>_CC_OPTS@:] options to pass to the C compiler that are specific to module @<module>@.
1432 For example, @SMap_CC_OPTS@ gives the specific options to pass to the C compiler when compiling
1433 @SMap.c@.
1434 \item[@EXTRA_CC_OPTS@:] extra options to pass to all C compilations.  This is intended for command
1435 line use, thus;
1436 \begin{verbatim}
1437   gmake libHS.a EXTRA_CC_OPTS="-v"
1438 \end{verbatim}
1439 \end{description}
1440
1441
1442 \subsection{The main @mk/target.mk@ file}
1443 \label{sect_targets}
1444
1445 @target.mk@ contains canned rules for all the standard targets described in
1446 Section~\ref{sect_standard-targets}.  It is complicated by the fact
1447 that you don't want all of these rules to be active in every @Makefile@.
1448 Rather than have a plethora of tiny files which you can include selectively,
1449 there is a single file, @target.mk@, which selectively includes rules 
1450 based on whether you have defined certain variables in your @Makefile@.
1451 This section explains what rules you get, what variables control them, and 
1452 what the rules do.  Hopefully, you will also get enough of an idea of what is supposed
1453 to happen that you can read and understand any wierd special cases yourself.
1454
1455 \begin{description}
1456 \item{@HS_PROG@.}  If @HS_PROG@ is defined, you get rules with the
1457 following targets:
1458 \begin{description}
1459 \item[@HS_PROG@] itself.  This rule links @$(OBJS)@ with the Haskell
1460 runtime system to get an executable called @$(HS_PROG)@.
1461 \item[@install@] installs @$(HS_PROG)@ in @$(bindir)@ with the execute bit set.
1462 \end{description}
1463
1464 \item[@C_PROG@] is similar to @HS_PROG@, except that the link step
1465 links @$(C_OBJS)@ with the C runtime system.
1466
1467 \item[@LIBRARY@] is similar to @HS_PROG@, except
1468 that it links @$(LIB_OBJS)@ to make the library archive @$(LIBRARY)@,
1469 and @install@ installs it in @$(libdir)@, with the execute bit not set.
1470
1471 \item[@LIB_DATA@] ...
1472 \item[@LIB_EXEC@] ...
1473
1474 \item[@HS_SRCS@, @C_SRCS@.] If @HS_SRCS@ is defined and non-empty, a rule for
1475 the target @depend@ is included, which generates dependency information for
1476 Haskell programs.  Similarly for @C_SRCS@.
1477 \end{description}
1478
1479 All of these rules are ``double-colon'' rules, thus
1480 \begin{verbatim}
1481   install :: $(HS_PROG)
1482         ...how to install it...
1483 \end{verbatim}
1484 GNU @make@ treats double-colon rules as separate entities.  If there
1485 are several double-colon rules for the same target it takes each in turn
1486 and fires it if its dependencies say to do so.  This means that you can,
1487 for example, define both @HS_PROG@ and @LIBRARY@, which will generate two
1488 rules for @install@.  When you type @gmake install@ both rules will be fired,
1489 and both the program and the library will be installed, just as you wanted.
1490
1491 \subsection{Recursion}
1492 \label{sect_subdirs}
1493
1494 In leaf @Makefiles@ the variable @SUBDIRS@ is undefined.  In non-leaf
1495 @Makefiles@, @SUBDIRS@ is set to the list of sub-directories that contain subordinate
1496 @Makefile@s.  {\em It is up to you to set @SUBDIRS@ in the @Makefile@.}
1497 There is no automation here --- @SUBDIRS@ is too important automate.
1498
1499 When @SUBDIRS@ is defined, @target.mk@ includes a rather neat rule for
1500 the standard targets (Section~\ref{sect_standard-targets}) that 
1501 simply invokes @make@ recursively in each of the sub-directories.
1502
1503 {\em These recursive invocations are guaranteed to occur in the order in 
1504 which the list of directories is specified in @SUBDIRS@.}  This guarantee can
1505 be important.  For example, when you say @gmake boot@ it can be important
1506 that the recursive invocation of @make boot@ is done in one sub-directory (the include
1507 files, say) before another (the source files).
1508 Generally, put the most independent sub-directory first, and the most dependent
1509 last.
1510
1511 \subsection{Way management}
1512 \label{sect_ways}
1513
1514 We sometimes want to build essentially the same system in several different
1515 ``ways''.  For example, we want to build @ghc@'s @Prelude@ libraries with
1516 and without profiling, with and without concurrency, and so on, so that
1517 there is an appropriately-built library archive to link with when the user compiles
1518 his program.
1519 It would be possible to have a completely separate build tree for each such ``way'',
1520 but it would be horribly bureaucratic, especially since often only parts of the
1521 build tree need to be constructed in multiple ways.
1522
1523 Instead, the @template.mk@ contains some clever magic to allow you to build
1524 several versions of a system; and to control locally how many versions are built
1525 and how they differ.  This section explains the magic.
1526
1527 The files for a particular way are distinguished by munging the suffix.
1528 The ``normal way'' is always built, and its files have the standard suffices
1529 @.o@, @.hi@, and so on.  In addition, you can build one or more extra ways,
1530 each distinguished by a {\em way tag}.  The object files and interface files
1531 for one of these extra ways are distinguished by their suffix.  For example,
1532 way @mp@ has files @.mp_o@ and @.mp_hi@.  Library archives have their way
1533 tag the other side of the dot, for boring reasons; thus, @libHS_mp.a@.
1534
1535 A @make@ variable called @way@ holds the current way tag.  {\em @way@ is only ever
1536 set on the command line of a recursive invocation of @gmake@.}  It is
1537 never set inside a @Makefile@.  So it is a global constant for any one invocation
1538 of @gmake@.  Two other @make@ variables, @way_@ and @_way@ are immediately derived
1539 from @$(way)@ and never altered.  If @way@ is not set, then neither are @way_@
1540 and @_way@, and the invocation of @make@ will build the ``normal way''.
1541 If @way@ is set, then the other two variables are set in sympathy. 
1542 For example, if @$(way)@ is ``@mp@'', then @way_@ is set to ``@mp_@''
1543 and @_way@ is set to ``@_mp@''.   These three variables are then used
1544 when constructing file names.
1545
1546 So how does @make@ ever get recursively invoked with @way@ set?  There
1547 are two ways in which this happens:
1548 \begin{itemize}
1549 \item For some (but not all) of the standard targets, when in a leaf sub-directory,
1550 @make@ is recursively invoked for each way tag in @$(WAYS)@.  You set @WAYS@ to
1551 the list of way tags you want these targets built for.  The mechanism here is
1552 very much like the recursive invocation of @make@ in sub-directories
1553 (Section~\ref{sect_subdirs}).
1554
1555 It is up to you to set @WAYS@ in your @Makefile@; this is how you control
1556 what ways will get built.
1557 \item For a useful collection of targets (such as @libHS_mp.a@, @Foo.mp_o@)
1558 there is a rule which recursively invokes @make@ to make the specified
1559 target, setting the @way@ variable.  So if you say @gmake Foo.mp_o@
1560 you should see a recursive invocation @gmake Foo.mp_o way=mp@,
1561 and {\em in this recursive invocation the pattern rule for compiling a Haskell
1562 file into a @.o@ file will match}.  The key pattern rules (in @suffix.mk@)
1563 look like this:
1564 \begin{verbatim}
1565   %.$(way_)o : %.lhs
1566         $(HC) $(HC_OPTS) $< -o $@
1567 \end{verbatim}
1568 Neat, eh?
1569 \end{itemize}
1570
1571
1572 \subsection{When the canned rule isn't right}
1573
1574 Sometimes the canned rule just doesn't do the right thing.  For example, in 
1575 the @nofib@ suite we want the link step to print out timing information.
1576 The thing to do here is {\em not} to define @HS_PROG@ or @C_PROG@, and instead
1577 define a special purpose rule in your own @Makefile@.
1578 By using different variable names you will avoid the canned rules being included,
1579 and conflicting with yours.
1580
1581
1582 %************************************************************************
1583 %*                                                                      *
1584 \section[booting-from-C]{Booting/porting from C (\tr{.hc}) files}
1585 \index{building GHC from .hc files}
1586 \index{booting GHC from .hc files}
1587 %*                                                                      *
1588 %************************************************************************
1589
1590 This section is for people trying to get GHC going by using the
1591 supplied intermediate C (\tr{.hc}) files.  This would probably be
1592 because no binaries have been provided, or because the machine
1593 is not ``fully supported.''
1594
1595 THIS SECTION HASN'T BEEN UPDATED YET.  Please let us know if you want to use this
1596 route. Unless someone does, this section may never get written, and the
1597 .hc files distribution may not get built!
1598
1599
1600 %************************************************************************
1601 %*                                                                      *
1602 \section[build-pitfalls]{Known pitfalls in building Glasgow Haskell}
1603 \index{problems, building}
1604 \index{pitfalls, in building}
1605 \index{building pitfalls}
1606 %*                                                                      *
1607 %************************************************************************
1608
1609 WARNINGS about pitfalls and known ``problems'':
1610
1611 \begin{enumerate}
1612 %------------------------------------------------------------------------
1613 \item
1614 One difficulty that comes up from time to time is running out of space
1615 in \tr{/tmp}.  (It is impossible for the configuration stuff to
1616 compensate for the vagaries of different sysadmin approaches re temp
1617 space.)
1618
1619 The quickest way around it is \tr{setenv TMPDIR /usr/tmp} or
1620 even \tr{setenv TMPDIR .} (or the equivalent incantation with the
1621 shell of your choice).
1622
1623 The best way around it is to say
1624 \begin{verbatim}
1625   TMPDIR=<dir>
1626 \end{verbatim}
1627 in your @build.mk@ file.
1628 Then GHC and the other @fptools@ programs will use the appropriate directory
1629 in all cases.
1630
1631 %------------------------------------------------------------------------
1632 \item
1633 In compiling some support-code bits, e.g., in \tr{ghc/runtime/gmp} and
1634 even in \tr{ghc/lib}, you may get a few C-compiler warnings.  We think
1635 these are OK.
1636
1637 %------------------------------------------------------------------------
1638 \item
1639 When compiling via C, you'll sometimes get ``warning:
1640 assignment from incompatible pointer type'' out of GCC.  Harmless.
1641
1642 %------------------------------------------------------------------------
1643 \item
1644 Similarly, \tr{ar}chiving warning messages like the following are not
1645 a problem:
1646 \begin{verbatim}
1647 ar: filename GlaIOMonad__1_2s.o truncated to GlaIOMonad_
1648 ar: filename GlaIOMonad__2_2s.o truncated to GlaIOMonad_
1649 ...
1650 \end{verbatim}
1651
1652 %------------------------------------------------------------------------
1653 \item
1654 Also harmless are some specialisation messages that you may see when
1655 compiling GHC; e.g.:
1656 \begin{verbatim}
1657 SPECIALISATION MESSAGES (Desirable):
1658 *** INSTANCES
1659 {-# SPECIALIZE instance Eq [Class] #-}
1660 {-# SPECIALIZE instance Eq (Class, [Class]) #-}
1661 {-# SPECIALIZE instance Outputable [ClassOp] #-}
1662 {-# SPECIALIZE instance Outputable [Id] #-}
1663 \end{verbatim}
1664
1665 %------------------------------------------------------------------------
1666 \item
1667 In compiling the compiler proper (in \tr{compiler/}), you {\em may} get an
1668 ``Out of heap space'' error message.  These
1669 can vary with the vagaries of different systems, it seems.  The
1670 solution is simple: (1)~add a suitable \tr{-H} flag to the @<module>_HC_OPTS@
1671 @make@ variable in the appropriate @Makefile@;
1672 (2)~try again: \tr{gmake}.
1673 (Section~\ref{sect_suffix}.)
1674
1675 Alternatively, just cut to the chase scene:
1676 \begin{verbatim}
1677 % cd ghc/compiler
1678 % make EXTRA_HC_OPTS=-H32m  # or some nice big number
1679 \end{verbatim}
1680
1681 %------------------------------------------------------------------------
1682 \item
1683 Not too long into the build process, you may get a huge complaint
1684 of the form:
1685 \begin{verbatim}
1686 Giant error 'do'ing getopts.pl:  at ./lit2pgm.BOOT line 27.
1687 \end{verbatim}
1688 This indicates that your \tr{perl} was mis-installed; the binary is
1689 unable to find the files for its ``built-in'' library.  Speak to your
1690 perl installer, then re-try.
1691
1692 %------------------------------------------------------------------------
1693 \item
1694 If you try to compile some Haskell, and you get errors from GCC
1695 about lots of things from \tr{/usr/include/math.h}, then your GCC
1696 was mis-installed.  \tr{fixincludes} wasn't run when it should've
1697 been.
1698
1699 As \tr{fixincludes} is now automagically run as part of GCC
1700 installation, this bug also suggests that you have an old GCC.
1701
1702
1703 %------------------------------------------------------------------------
1704 \item
1705 You {\em may} need to re-\tr{ranlib} your libraries (on Sun4s).
1706 \begin{verbatim}
1707 % cd $(libdir)/ghc-2.04/sparc-sun-sunos4
1708 % foreach i ( `find . -name '*.a' -print` ) # or other-shell equiv...
1709 ?    ranlib $i
1710 ?    # or, on some machines: ar s $i
1711 ? end
1712 \end{verbatim}
1713 We'd be interested to know if this is still necessary.
1714
1715 %------------------------------------------------------------------------
1716 \item
1717 If you end up making documents that involve (La)TeX and/or \tr{tib}
1718 (Simon's favourite), the odds are that something about your/our setup
1719 will reach out and bite you.  Yes, please complain; meanwhile,
1720 you can do \tr{make -n whatever.dvi} to see the intended commands,
1721 then try to muddle through, doing them by hand.
1722
1723 %------------------------------------------------------------------------
1724 \item
1725 GHC's sources go through \tr{cpp}
1726 before being compiled, and \tr{cpp} varies a bit from one Unix to another.
1727 One particular gotcha is macro calls like this:
1728 \begin{verbatim}
1729   SLIT("Hello, world")
1730 \end{verbatim}
1731 Some \tr{cpp}s treat the comma inside the string as separating two macro arguments,
1732 so you get
1733 \begin{verbatim}
1734   :731: macro `SLIT' used with too many (2) args
1735 \end{verbatim}
1736 Alas, \tr{cpp} doesn't tell you the offending file!
1737
1738 Workaround: don't put wierd things in string args to \tr{cpp} macros.
1739 \end{enumerate}
1740
1741
1742
1743 % ====================================================================
1744 %Here follow pitfalls that apply to pre-2.02 releases.  They should not
1745 %happen any more If they do crop up with 2.02 or later, please let us
1746 %know.
1747
1748 \begin{enumerate}
1749 %%------------------------------------------------------------------------
1750 %\item
1751 %When configuring the support code (mkworld, glafp-utils, etc.), you
1752 %will see mention of \tr{NO_SPECIFIC_PROJECT} and
1753 %\tr{NO_SPECIFIC_VERSION}.  This is cool.
1754
1755
1756 %------------------------------------------------------------------------
1757 %\item
1758 %Sooner or later in your ``make-worlding'' life you will do and see
1759 %something like:
1760 %\begin{verbatim}
1761 % make Makefile
1762 %        rm -f Makefile.bak; mv Makefile Makefile.bak
1763 %../.././mkworld/jmake -P ghc -S std -I../.././mkworld -DTopDir=../../. -DTopDir=...
1764 %../.././mkworld/jrestoredeps
1765 %==== The new Makefile is for: ====
1766 %make: Fatal error in reader: Makefile, line 850: Unexpected end of line seen
1767 %Current working directory /export/users/fp/grasp/ghc-0.26/ghc/runtimes/standard
1768 %*** Error code 1
1769 %make: Fatal error: Command failed for target `Makefile'
1770 %\end{verbatim}
1771
1772 %Don't panic!  It should restore your previous \tr{Makefile}, and
1773 %leave the junk one in \tr{Makefile.bad}.  Snoop around at your leisure.
1774
1775 % ------------------------------------------------------------------------
1776 %\item
1777 %If you do corrupt a \tr{Makefile} totally, or you need to glue a new
1778 %directory into the directory structure (in \tr{newdir}---which must
1779 %have a \tr{Jmakefile}, even if empty), here's a neat trick:
1780 %\begin{verbatim}
1781 %#
1782 %# move to the directory just above the one where you want a Makefile...
1783 %cd ..
1784 %#
1785 %# make Makefiles, but lie about the directories below...
1786 %make Makefiles SUBDIRS=newdir
1787 %\end{verbatim}
1788
1789 %This will create a \tr{Makefile} {\em ex nihilo} in \tr{newdir}, and
1790 %it will be properly wired into the general make-world structure.
1791
1792 % ------------------------------------------------------------------------
1793 \item
1794 Don't configure/build/install using a variety of machines.  A
1795 mistake we've made is to do \tr{make Makefiles} on a Sun4, then try to
1796 build GHC (\tr{make all}) on a Sun3.
1797
1798 %------------------------------------------------------------------------
1799 %\item
1800 %If you build an ``unregisterised'' build, you will get bazillions of
1801 %warnings about `ANSI C forbids braced-groups within expressions'.
1802 %Especially in \tr{ghc/lib}.  These are OK.
1803
1804 \end{enumerate}
1805
1806
1807 \begin{onlystandalone}
1808 \printindex
1809 \end{document}
1810 \end{onlystandalone}
1811