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