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