[project @ 2000-01-26 12:27:34 by rrt]
[ghc-hetmet.git] / docs / building.sgml
1 <!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
2
3 <Article>
4
5 <ArtHeader>
6
7 <Title>Building and Installing the Glasgow Functional Programming Tools Suite</Title>
8 <Author><OtherName>The GHC Team</OtherName></Author>
9 <Address><Email>glasgow-haskell-&lcub;users,bugs&rcub;@dcs.gla.ac.uk</Email></Address>
10 <PubDate>January 2000</PubDate>
11
12 <Abstract>
13
14 <Para>
15 This guide is intended for people who want to build or modify
16 programs from the Glasgow <Literal>fptools</Literal> suite (as distinct from those
17 who merely want to <Emphasis>run</Emphasis> them). Installation instructions are now provided in the user guide.
18 </Para>
19
20 <Para>
21 The bulk of this guide applies to building on Unix systems; see <XRef LinkEnd="winbuild"> for Windows notes.
22 </Para>
23
24 </Abstract>
25
26 </ArtHeader>
27
28
29 <Sect1 id="sec-getting">
30 <Title>Getting the Glasgow <Literal>fptools</Literal> suite
31 </Title>
32
33 <Para>
34 Building the Glasgow tools <Emphasis>can</Emphasis> be complicated, mostly because
35 there are so many permutations of what/why/how, e.g., ``Build Happy
36 with HBC, everything else with GHC, leave out profiling, and test it
37 all on the `real' NoFib programs.''  Yeeps!
38 </Para>
39
40 <Para>
41 Happily, such complications don't apply to most people.  A few common
42 ``strategies'' serve most purposes.  Pick one and proceed
43 as suggested:
44 </Para>
45
46 <Para>
47 <VariableList>
48
49 <VarListEntry>
50 <Term><IndexTerm><Primary>Binary distribution</Primary></IndexTerm>Binary distribution.</Term>
51 <ListItem>
52 <Para>
53 If your only purpose is to install some of the <Literal>fptools</Literal> suite then the easiest thing to do is to get a binary distribution. In the
54 binary distribution everything is pre-compiled for your particular
55 machine architecture and operating system, so all you should have to
56 do is install the binaries and libraries in suitable places. The user guide
57 describes how to do this.
58 </Para>
59
60 <Para>
61 A binary distribution may not work for you for two reasons.  First, we
62 may not have built the suite for the particular architecture/OS
63 platform you want. That may be due to lack of time and energy (in
64 which case you can get a source distribution and build from it; see
65 below).  Alternatively, it may be because we haven't yet ported the
66 suite to your architecture, in which case you are considerably worse
67 off.
68 </Para>
69
70 <Para>
71 The second reason a binary distribution may not be what you want is
72 if you want to read or modify the souce code.
73 </Para>
74 </ListItem></VarListEntry>
75 <VarListEntry>
76 <Term><IndexTerm><Primary>Source distribution</Primary></IndexTerm>Source distribution.</Term>
77 <ListItem>
78 <Para>
79 You have a supported
80 platform, but (a)&nbsp;you like the warm fuzzy feeling of compiling things
81 yourself; (b)&nbsp;you want to build something ``extra''&mdash;e.g., a set of
82 libraries with strictness-analysis turned off; or (c)&nbsp;you want to hack
83 on GHC yourself.
84 </Para>
85
86 <Para>
87 A source distribution contains complete sources for one or more
88 projects in the <Literal>fptools</Literal> suite.  Not only that, but the more awkward
89 machine-independent steps are done for you.  For example, if you don't
90 have <Command>flex</Command><IndexTerm><Primary>flex</Primary></IndexTerm> you'll find it convenient that the source
91 distribution contains the result of running <Command>flex</Command> on the lexical
92 analyser specification.  If you don't want to alter the lexical
93 analyser then this saves you having to find and install <Command>flex</Command>. You
94 will still need a working version of GHC on your machine in order to
95 compile (most of) the sources, however.
96 </Para>
97
98 <Para>
99 We make source distributions more frequently than binary
100 distributions; a release that comes with pre-compiled binaries
101 is considered a major release, i.e., a release that we have some
102 confidence will work well by having tested it (more) thoroughly.
103 </Para>
104
105 <Para>
106 Source-only distributions are either bugfix releases or snapshots of
107 current state of development. The release has undergone some testing.
108 Source releases of 4.xx can be compiled up using 2.10 or later.
109 </Para>
110 </ListItem></VarListEntry>
111 <VarListEntry>
112 <Term>Build GHC from intermediate C <Filename>.hc</Filename> files<IndexTerm><Primary>hc files</Primary></IndexTerm>:</Term>
113 <ListItem>
114 <Para>
115 You
116 need a working GHC to use a source distribution. What if you don't
117 have a working GHC? Then you have no choice but to ``bootstrap'' up
118 from the intermediate C (<Filename>.hc</Filename>) files that we provide.  Building GHC
119 on an unsupported platform falls into this category.  Please see
120 <Xref LinkEnd="sec-booting-from-C">.
121 </Para>
122
123 <Para>
124 Once you have built GHC, you can build the other Glasgow tools with
125 it.
126 </Para>
127
128 <Para>
129 In theory, you can (could?) build GHC with another Haskell compiler
130 (e.g., HBC). We haven't tried to do this for ages and it almost
131 certainly doesn't work any more (for tedious reasons).
132 </Para>
133 </ListItem></VarListEntry>
134 <VarListEntry>
135 <Term>The CVS repository.</Term>
136 <ListItem>
137 <Para>
138 We make source distributions slightly more often than binary
139 distributions; but still infrequently.  If you want more up-to-the
140 minute (but less tested) source code then you need to get access to
141 our CVS repository.
142 </Para>
143
144 <Para>
145 All the <Literal>fptools</Literal> source code is held in a CVS repository. CVS is a
146 pretty good source-code control system, and best of all it works over
147 the network.
148 </Para>
149
150 <Para>
151 The repository holds source code only. It holds no mechanically
152 generated files at all.  So if you check out a source tree from CVS
153 you will need to install every utility so that you can build all the
154 derived files from scratch.
155 </Para>
156
157 <Para>
158 More information about our CVS repository is available at <ULink
159 URL="http://www.dcs.gla.ac.uk/fp/software/ghc/cvs-cheat-sheet.html"
160 >The Fptools CVS Cheat Sheet</ULink
161 >.
162 </Para>
163 </ListItem></VarListEntry>
164 </VariableList>
165 </Para>
166
167 <Para>
168 If you are going to do any building from sources (either from a source
169 distribution or the CVS repository) then you need to read all of this
170 manual in detail.
171 </Para>
172
173 </Sect1>
174
175 <Sect1>
176 <Title>Things to check before you start typing</Title>
177
178 <Para>
179 Here's a list of things to check before you get started.
180
181 <OrderedList>
182 <ListItem>
183
184 <Para>
185 <IndexTerm><Primary>Disk space needed</Primary></IndexTerm>Disk space needed: About 30MB (five hamburgers' worth) of disk space
186 for the most basic binary distribution of GHC; more for some
187 platforms, e.g., Alphas.  An extra ``bundle'' (e.g., concurrent
188 Haskell libraries) might take you to 8&ndash;10 hamburgers.
189
190 You'll need over 100MB (say, 20 hamburgers' worth) if you need to
191 build the basic stuff from scratch.
192
193
194 All of the above are <Emphasis>estimates</Emphasis> of disk-space needs. (I don't yet
195 know the disk requirements for the non-GHC tools).
196
197 </Para>
198 </ListItem>
199 <ListItem>
200
201 <Para>
202 Use an appropriate machine, compilers, and things.
203
204 SPARC boxes, DEC Alphas running OSF/1, and PCs running Linux, FreeBSD,
205 or Solaris are all fully supported.  MIPS, AIX, Win32 and HP boxes are
206 in pretty good shape.  <Xref LinkEnd="sec-port-info">
207 gives the full run-down on ports or lack thereof.
208
209 NOTE: as of version 4.00, we lost a few ports.  All of the x86 ports
210 are working, as is the Sparc/Solaris port, but the rest will need a
211 little work.  Please contact us if you can provide hardware cycles
212 and/or porting expertise.
213
214 </Para>
215 </ListItem>
216 <ListItem>
217
218 <Para>
219  Be sure that the ``pre-supposed'' utilities are installed.
220 <Xref LinkEnd="sec-pre-supposed"> elaborates.
221
222 </Para>
223 </ListItem>
224 <ListItem>
225
226 <Para>
227  If you have any problem when building or installing the Glasgow
228 tools, please check the ``known pitfalls'' (<Xref LinkEnd="sec-build-pitfalls">).  Also check the <ULink
229 URL="http://www.dcs.gla.ac.uk/fp/software/ghc/ghc-bugs.html"
230 >known bugs page</ULink>.
231 <IndexTerm><Primary>known bugs</Primary></IndexTerm>
232 <IndexTerm><Primary>bugs, known</Primary></IndexTerm>
233
234 If you feel there is still some shortcoming in our procedure or
235 instructions, please report it.
236
237 For GHC, please see the bug-reporting section of the User's guide
238 (separate document), to maximise the usefulness of your report.
239 <IndexTerm><Primary>bugs, reporting</Primary></IndexTerm>
240
241 If in doubt, please send a message to <Email>glasgow-haskell-bugs@dcs.gla.ac.uk</Email>.
242 <IndexTerm><Primary>bugs, mailing list</Primary></IndexTerm>
243 </Para>
244 </ListItem>
245
246 </OrderedList>
247
248 </Para>
249
250 </Sect1>
251
252 <Sect1 id="sec-port-info">
253 <Title>What machines the Glasgow tools run on
254 </Title>
255
256 <Para>
257 <IndexTerm><Primary>ports, GHC</Primary></IndexTerm>
258 <IndexTerm><Primary>GHC ports</Primary></IndexTerm>
259 <IndexTerm><Primary>supported platforms</Primary></IndexTerm>
260 <IndexTerm><Primary>platforms, supported</Primary></IndexTerm>
261 The main question is whether or not the Haskell compiler (GHC) runs on
262 your platform.
263 </Para>
264
265 <Para>
266 A ``platform'' is a architecture/manufacturer/operating-system
267 combination, such as <Literal>sparc-sun-solaris2</Literal>.  Other common ones are
268 <Literal>alpha-dec-osf2</Literal>, <Literal>hppa1.1-hp-hpux9</Literal>, <Literal>i386-unknown-linux</Literal>,
269 <Literal>i386-unknown-solaris2</Literal>, <Literal>i386-unknown-freebsd</Literal>,
270 <Literal>i386-unknown-cygwin32</Literal>, <Literal>m68k-sun-sunos4</Literal>, <Literal>mips-sgi-irix5</Literal>,
271 <Literal>sparc-sun-sunos4</Literal>, <Literal>sparc-sun-solaris2</Literal>, <Literal>powerpc-ibm-aix</Literal>.
272 </Para>
273
274 <Para>
275 Bear in mind that certain ``bundles'', e.g. parallel Haskell, may not
276 work on all machines for which basic Haskell compiling is supported.
277 </Para>
278
279 <Para>
280 Some libraries may only work on a limited number of platforms; for
281 example, a sockets library is of no use unless the operating system
282 supports the underlying BSDisms.
283 </Para>
284
285 <Sect2>
286 <Title>What platforms the Haskell compiler (GHC) runs on</Title>
287
288 <Para>
289 <IndexTerm><Primary>fully-supported platforms</Primary></IndexTerm>
290 <IndexTerm><Primary>native-code generator</Primary></IndexTerm>
291 <IndexTerm><Primary>registerised ports</Primary></IndexTerm>
292 <IndexTerm><Primary>unregisterised ports</Primary></IndexTerm>
293 The GHC hierarchy of Porting Goodness: (a)&nbsp;Best is a native-code
294 generator; (b)&nbsp;next best is a ``registerised''
295 port; (c)&nbsp;the bare minimum is an ``unregisterised'' port.
296 (``Unregisterised'' is so terrible that we won't say more about it).
297 </Para>
298
299 <Para>
300 We use Sparcs running Solaris 2.5, x86 boxes running FreeBSD and
301 Linux, and DEC&nbsp;Alphas running OSF/1&nbsp;V2.0, so those are the
302 ``fully-supported'' platforms, unsurprisingly.  All have native-code
303 generators, for quicker compilations.  The native-code generator for
304 iX86 platforms (e.g., Linux ELF) is <Emphasis>nearly</Emphasis> working; but is not
305 turned on by default.
306 </Para>
307
308 <Para>
309 Here's everything that's known about GHC ports.  We identify platforms
310 by their ``canonical'' CPU/Manufacturer/OS triple.
311 </Para>
312
313 <Para>
314 Note that some ports are fussy about which GCC version you use; or
315 require GAS; or&hellip;
316 </Para>
317
318 <Para>
319 <VariableList>
320
321 <VarListEntry>
322 <Term>alpha-dec-osf1:</Term>
323 <ListItem>
324 <Para>
325 <IndexTerm><Primary>alpha-dec-osf1: fully supported</Primary></IndexTerm>
326 </Para>
327
328 <Para>
329 (We have OSF/1 V3.0.) Fully supported, including native-code
330 generator.  We recommend GCC 2.6.x or later.
331 </Para>
332 </ListItem></VarListEntry>
333 <VarListEntry>
334 <Term>sparc-sun-sunos4:</Term>
335 <ListItem>
336 <Para>
337 <IndexTerm><Primary>sparc-sun-sunos4: fully supported</Primary></IndexTerm>
338 </Para>
339
340 <Para>
341 Fully supported, including native-code generator.
342 </Para>
343 </ListItem></VarListEntry>
344 <VarListEntry>
345 <Term>sparc-sun-solaris2:</Term>
346 <ListItem>
347 <Para>
348 <IndexTerm><Primary>sparc-sun-solaris2: fully supported</Primary></IndexTerm>
349 </Para>
350
351 <Para>
352 Fully supported, including native-code generator.  A couple of quirks,
353 though: (a)&nbsp;the profiling libraries are bizarrely huge when compiled
354 with object splitting; (b)&nbsp;the default <Command>xargs</Command><IndexTerm><Primary>xargs</Primary></IndexTerm> program is
355 atrociously bad for building GHC libraries (see <Xref LinkEnd="sec-pre-supposed"> for
356 details).
357 </Para>
358 </ListItem></VarListEntry>
359 <VarListEntry>
360 <Term>HP-PA box running HP</Term>
361 <ListItem>
362 <Para>
363 UX 9.x:
364 <IndexTerm><Primary>hppa1.1-hp-hpux: registerised port</Primary></IndexTerm>
365 </Para>
366
367 <Para>
368 Works registerised.  No native-code generator.  For GCC, you're best
369 off with one of the Utah releases of GCC&nbsp;2.6.3 (`u3' or later), from
370 <Literal>jaguar.cs.utah.edu</Literal>.  We think a straight GCC 2.7.x works,
371 too.
372 </Para>
373
374 <Para>
375 Concurrent/Parallel Haskell probably don't work (yet).
376 <IndexTerm><Primary>hppa1.1-hp-hpux: concurrent&mdash;no</Primary></IndexTerm>
377 <IndexTerm><Primary>hppa1.1-hp-hpux: parallel&mdash;no</Primary></IndexTerm>
378 </Para>
379 </ListItem></VarListEntry>
380 <VarListEntry>
381 <Term>i386-*-linux (PCs running Linux&mdash;ELF format):</Term>
382 <ListItem>
383 <Para>
384 <IndexTerm><Primary>i386-*-linux: registerised port</Primary></IndexTerm>
385 </Para>
386
387 <Para>
388 GHC works registerised.  You <Emphasis>must</Emphasis> have GCC 2.7.x or later.  The
389 iX86 native-code generator is <Emphasis>nearly</Emphasis> there, but it isn't turned
390 on by default.
391 </Para>
392
393 <Para>
394 Profiling works, and Concurrent Haskell works.
395 <IndexTerm><Primary>i386-*-linux: profiling&mdash;yes</Primary></IndexTerm>
396 <IndexTerm><Primary>i386-*-linux: concurrent&mdash;yes</Primary></IndexTerm>
397 Parallel Haskell probably works.
398 <IndexTerm><Primary>i386-*-linux: parallel&mdash;maybe</Primary></IndexTerm>
399 </Para>
400
401 <Para>
402 On old Linux a.out systems: should be the same.
403 <IndexTerm><Primary>i386-*-linuxaout: registerised port</Primary></IndexTerm>
404 </Para>
405 </ListItem></VarListEntry>
406 <VarListEntry>
407 <Term>i386-*-freebsd (PCs running FreeBSD 2.2 or higher, and
408 NetBSD/OpenBSD using FreeBSD emulation):</Term>
409 <ListItem>
410 <Para>
411 <IndexTerm><Primary>i386-*-freebsd:registerised port</Primary></IndexTerm>
412 </Para>
413
414 <Para>
415 GHC works registerised. Supports same set of bundles as the above.
416 <IndexTerm><Primary>i386-*-freebsd: profiling&mdash;yes</Primary></IndexTerm>
417 <IndexTerm><Primary>i386-*-freebsd: concurrent&mdash;yes</Primary></IndexTerm>
418 <IndexTerm><Primary>i386-*-freebsd: parallel&mdash;maybe</Primary></IndexTerm>
419 </Para>
420 </ListItem></VarListEntry>
421 <VarListEntry>
422 <Term>i386-unknown-cygwin32:</Term>
423 <ListItem>
424 <Para>
425 <IndexTerm><Primary>i386-unknown-cygwin32: fully supported</Primary></IndexTerm>
426 Fully supported under Win95/NT, including a native code
427 generator. Requires the <Literal>cygwin32</Literal> compatibility library and a
428 healthy collection of GNU tools (i.e., gcc, GNU ld, bash etc.)
429 Profiling works, so does Concurrent Haskell.  
430 <IndexTerm><Primary>i386-*-cygwin32: profiling&mdash;yes</Primary></IndexTerm> 
431 <IndexTerm><Primary>i386-*-cygwin32: concurrent&mdash;yes</Primary></IndexTerm>
432 </Para>
433 </ListItem></VarListEntry>
434 <VarListEntry>
435 <Term>mips-sgi-irix5:</Term>
436 <ListItem>
437 <Para>
438 <IndexTerm><Primary>mips-sgi-irix5: registerised port</Primary></IndexTerm>
439 GHC works registerised (no native-code generator).  I suspect any
440 GCC&nbsp;2.6.x (or later) is OK.  The GCC that I used was built with
441 <Option>--with-gnu-as</Option>; turns out that is important!
442 </Para>
443
444 <Para>
445 Concurrent/Parallel Haskell probably don't work (yet).
446 Profiling might work, but it is untested.
447 <IndexTerm><Primary>mips-sgi-irix5: concurrent&mdash;no</Primary></IndexTerm>
448 <IndexTerm><Primary>mips-sgi-irix5: parallel&mdash;no</Primary></IndexTerm>
449 <IndexTerm><Primary>mips-sgi-irix5: profiling&mdash;maybe</Primary></IndexTerm>
450 </Para>
451 </ListItem></VarListEntry>
452 <VarListEntry>
453 <Term>mips-sgi-irix6:</Term>
454 <ListItem>
455 <Para>
456 <IndexTerm><Primary>mips-sgi-irix6: registerised port</Primary></IndexTerm>
457 Thanks to the fine efforts of Tomasz Cholewo <ULink
458 URL="mailto:tjchol01@mecca.spd.louisville.edu"
459 >tjchol01@mecca.spd.louisville.edu</ULink
460 >, GHC works registerised (no
461 native code generator) under IRIX 6.2 and 6.3. Depends on having a
462 <ULink
463 URL="http://mecca.spd.louisville.edu/~tjchol01/software/"
464 >specially tweaked version of gcc-2.7.2 around</ULink>.
465 Profiling works, Concurrent/Parallel Haskell might work (AFAIK, untested).
466 <IndexTerm><Primary>mips-sgi-irix6: concurrent&mdash;maybe</Primary></IndexTerm>
467 <IndexTerm><Primary>mips-sgi-irix6: parallel&mdash;maybe</Primary></IndexTerm>
468 <IndexTerm><Primary>mips-sgi-irix6: profiling&mdash;yes</Primary></IndexTerm>
469 </Para>
470 </ListItem></VarListEntry>
471 <VarListEntry>
472 <Term>powerpc-ibm-aix:</Term>
473 <ListItem>
474 <Para>
475 <IndexTerm><Primary>powerpc-ibm-aix: registerised port</Primary></IndexTerm>
476 GHC works registerised (no native-code generator&hellip;yet).
477 I suspect 2.7.x is what you need together with this.
478 </Para>
479
480 <Para>
481 Concurrent/Parallel Haskell probably don't work (yet).
482 Profiling might work, but it is untested.
483 <IndexTerm><Primary>mips-sgi-irix5: concurrent&mdash;no</Primary></IndexTerm>
484 <IndexTerm><Primary>mips-sgi-irix5: parallel&mdash;no</Primary></IndexTerm>
485 <IndexTerm><Primary>mips-sgi-irix5: profiling&mdash;maybe</Primary></IndexTerm>
486 </Para>
487 </ListItem></VarListEntry>
488 <VarListEntry>
489 <Term>m68k-apple-macos7 (Mac, using MPW):</Term>
490 <ListItem>
491 <Para>
492 <IndexTerm><Primary>m68k-apple-macos7: historically ported</Primary></IndexTerm>
493 Once upon a time, David Wright in Tasmania actually
494 got GHC to run on a Macintosh.  Ditto James Thomson here at Glasgow.
495 You may be able to get Thomson's from here.  (Not sure that it will
496 excite you to death, but&hellip;)
497 </Para>
498
499 <Para>
500 No particularly recent GHC is known to work on a Mac.
501 </Para>
502 </ListItem></VarListEntry>
503 <VarListEntry>
504 <Term>m68k-next-nextstep3:</Term>
505 <ListItem>
506 <Para>
507 <IndexTerm><Primary>m68k-next-nextstep3: historically ported</Primary></IndexTerm>
508 Carsten Schultz succeeded with a ``registerised'' port of GHC&nbsp;0.29.
509 There's probably a little bit-rot since then, but otherwise it should
510 still be fine.
511 </Para>
512
513 <Para>
514 Concurrent/Parallel Haskell probably won't work (yet).
515 <IndexTerm><Primary>m68k-next-nextstep3: concurrent&mdash;no</Primary></IndexTerm>
516 <IndexTerm><Primary>m68k-next-nextstep3: parallel&mdash;no</Primary></IndexTerm>
517 </Para>
518 </ListItem></VarListEntry>
519 <VarListEntry>
520 <Term>m68k-sun-sunos4 (Sun3):</Term>
521 <ListItem>
522 <Para>
523 <IndexTerm><Primary>m68k-sun-sunos4: registerised
524 port</Primary></IndexTerm> GHC 2.0x and 3.0x haven't been tried on a Sun3.  GHC&nbsp;0.26
525 worked registerised.  No native-code generator.
526 </Para>
527
528 <Para>
529 Concurrent/Parallel Haskell probably don't work (yet).
530 <IndexTerm><Primary>m68k-sun-sunos4: concurrent&mdash;no</Primary></IndexTerm>
531 <IndexTerm><Primary>m68k-sun-sunos4: parallel&mdash;no</Primary></IndexTerm>
532 </Para>
533 </ListItem></VarListEntry>
534 </VariableList>
535 </Para>
536
537 </Sect2>
538
539 <Sect2>
540 <Title>What machines the other tools run on</Title>
541
542 <Para>
543 Unless you hear otherwise, the other tools work if GHC works.
544 </Para>
545
546 <Para>
547 Haggis requires Concurrent Haskell to work.
548 <IndexTerm><Primary>Haggis, Concurrent Haskell</Primary></IndexTerm>
549 </Para>
550
551 </Sect2>
552
553 </Sect1>
554
555
556 <Sect1 id="sec-pre-supposed">
557 <Title>Installing pre-supposed utilities
558
559 <IndexTerm><Primary>pre-supposed utilities</Primary></IndexTerm>
560 <IndexTerm><Primary>utilities, pre-supposed</Primary></IndexTerm></Title>
561
562 <Para>
563 Here are the gory details about some utility programs you may need;
564 <Command>perl</Command> and <Command>gcc</Command> are the only important ones. (PVM<IndexTerm><Primary>PVM</Primary></IndexTerm> is important
565 if you're going for Parallel Haskell.)  The <Command>configure</Command><IndexTerm><Primary>configure</Primary></IndexTerm>
566 script will tell you if you are missing something.
567 </Para>
568
569 <Para>
570 <VariableList>
571
572 <VarListEntry>
573 <Term>Perl:</Term>
574 <ListItem>
575 <Para>
576 <IndexTerm><Primary>pre-supposed: Perl</Primary></IndexTerm>
577 <IndexTerm><Primary>Perl, pre-supposed</Primary></IndexTerm>
578 <Emphasis>You have to have Perl to proceed!</Emphasis> Perl is a language quite good
579 for doing shell-scripty tasks that involve lots of text processing.
580 It is pretty easy to install.
581 </Para>
582
583 <Para>
584 Perl&nbsp;5 is required.  For Win32 platforms, we strongly suggest you pick
585 up a port of Perl&nbsp;5 for <Literal>cygwin32</Literal>, as the common Hip/ActiveWare port
586 of Perl is Not Cool Enough for our purposes.
587 </Para>
588
589 <Para>
590 Perl should be put somewhere so that it can be invoked by the <Literal>&num;!</Literal>
591 script-invoking mechanism. (I believe <Filename>/usr/bin/perl</Filename> is preferred;
592 we use <Filename>/usr/local/bin/perl</Filename> at Glasgow.)  The full pathname should
593 may need to be less than 32 characters long on some systems.
594 </Para>
595 </ListItem></VarListEntry>
596 <VarListEntry>
597 <Term>GNU C (<Command>gcc</Command>):</Term>
598 <ListItem>
599 <Para>
600 <IndexTerm><Primary>pre-supposed: GCC (GNU C compiler)</Primary></IndexTerm>
601 <IndexTerm><Primary>GCC (GNU C compiler), pre-supposed</Primary></IndexTerm>
602 </Para>
603
604 <Para>
605 Versions 2.7.2.x, 2.8.1 and egcs 1.1.2 are known to work.  Use other
606 versions at your own risk!
607 </Para>
608
609 <Para>
610 If your GCC dies with ``internal error'' on some GHC source file,
611 please let us know, so we can report it and get things improved.
612 (Exception: on iX86 boxes&mdash;you may need to fiddle with GHC's
613 <Option>-monly-N-regs</Option> option; see the User's Guide)
614 </Para>
615 </ListItem></VarListEntry>
616 <VarListEntry>
617 <Term><Command>xargs</Command> on Solaris2:</Term>
618 <ListItem>
619 <Para>
620 <IndexTerm><Primary>xargs, presupposed (Solaris only)</Primary></IndexTerm>
621 <IndexTerm><Primary>Solaris: alternative xargs</Primary></IndexTerm>
622 The GHC libraries are put together with something like:
623
624 <ProgramListing>
625 find bunch-of-dirs -name '*.o' -print | xargs ar q ...
626 </ProgramListing>
627
628 Unfortunately the Solaris <Command>xargs</Command> (the shell-script equivalent
629 of <Function>map</Function>) only ``bites off'' the <Filename>.o</Filename> files a few at a
630 time&mdash;with near-infinite rebuilding of the symbol table in
631 the <Filename>.a</Filename> file.
632 </Para>
633
634 <Para>
635 The best solution is to install a sane <Command>xargs</Command> from the GNU
636 findutils distribution.  You can unpack, build, and install the GNU
637 version in the time the Solaris <Command>xargs</Command> mangles just one GHC
638 library.
639 </Para>
640 </ListItem></VarListEntry>
641 <VarListEntry>
642 <Term>Autoconf:</Term>
643 <ListItem>
644 <Para>
645 <IndexTerm><Primary>pre-supposed: Autoconf</Primary></IndexTerm>
646 <IndexTerm><Primary>Autoconf, pre-supposed</Primary></IndexTerm>
647 </Para>
648
649 <Para>
650 GNU Autoconf is needed if you intend to build from the CVS sources, it
651 is <Emphasis>not</Emphasis> needed if you just intend to build a standard source
652 distribution.
653 </Para>
654
655 <Para>
656 Autoconf builds the <Command>configure</Command> script from <Filename>configure.in</Filename> and
657 <Filename>aclocal.m4</Filename>.  If you modify either of these files, you'll need
658 Autoconf to rebuild <Filename>configure</Filename>.
659 </Para>
660 </ListItem></VarListEntry>
661 <VarListEntry>
662 <Term><Command>sed</Command></Term>
663 <ListItem>
664 <Para>
665 <IndexTerm><Primary>pre-supposed: sed</Primary></IndexTerm>
666 <IndexTerm><Primary>sed, pre-supposed</Primary></IndexTerm>
667 You need a working <Command>sed</Command> if you are going to build from sources.  The
668 build-configuration stuff needs it.  GNU sed version 2.0.4 is no good!
669 It has a bug in it that is tickled by the build-configuration.  2.0.5
670 is OK. Others are probably OK too (assuming we don't create too
671 elaborate configure scripts.)
672 </Para>
673 </ListItem></VarListEntry>
674 </VariableList>
675 </Para>
676
677 <Para>
678 One <Literal>fptools</Literal> project is worth a quick note at this point, because it
679 is useful for all the others: <Literal>glafp-utils</Literal> contains several utilities
680 which aren't particularly Glasgow-ish, but Occasionally Indispensable.
681 Like <Command>lndir</Command> for creating symbolic link trees.
682 </Para>
683
684 <Sect2 id="pre-supposed-gph-tools">
685 <Title>Tools for building parallel GHC (GPH)
686 </Title>
687
688 <Para>
689 <VariableList>
690
691 <VarListEntry>
692 <Term>PVM version 3:</Term>
693 <ListItem>
694 <Para>
695 <IndexTerm><Primary>pre-supposed: PVM3 (Parallel Virtual Machine)</Primary></IndexTerm>
696 <IndexTerm><Primary>PVM3 (Parallel Virtual Machine), pre-supposed</Primary></IndexTerm>
697 </Para>
698
699 <Para>
700 PVM is the Parallel Virtual Machine on which Parallel Haskell programs
701 run.  (You only need this if you plan to run Parallel Haskell.
702 Concurent Haskell, which runs concurrent threads on a uniprocessor
703 doesn't need it.)  Underneath PVM, you can have (for example) a
704 network of workstations (slow) or a multiprocessor box (faster).
705 </Para>
706
707 <Para>
708 The current version of PVM is 3.3.11; we use 3.3.7.  It is readily
709 available on the net; I think I got it from <Literal>research.att.com</Literal>, in
710 <Filename>netlib</Filename>.
711 </Para>
712
713 <Para>
714 A PVM installation is slightly quirky, but easy to do.  Just follow
715 the <Filename>Readme</Filename> instructions.
716 </Para>
717 </ListItem></VarListEntry>
718 <VarListEntry>
719 <Term><Command>bash</Command>:</Term>
720 <ListItem>
721 <Para>
722 <IndexTerm><Primary>bash, presupposed (Parallel Haskell only)</Primary></IndexTerm>
723 Sadly, the <Command>gr2ps</Command> script, used to convert ``parallelism profiles''
724 to PostScript, is written in Bash (GNU's Bourne Again shell).
725 This bug will be fixed (someday).
726 </Para>
727 </ListItem></VarListEntry>
728 </VariableList>
729 </Para>
730
731 </Sect2>
732
733 <Sect2 id="pre-supposed-doc-tools">
734 <Title>Tools for building the Documentation
735 </Title>
736
737 <Para>
738 The following additional tools are required if you want to format the
739 documentation that comes with the <Literal>fptools</Literal> projects:
740 </Para>
741
742 <Para>
743 <VariableList>
744
745 <VarListEntry>
746 <Term>DocBook:</Term>
747 <ListItem>
748 <Para>
749 <IndexTerm><Primary>pre-supposed: DocBook</Primary></IndexTerm>
750 <IndexTerm><Primary>DocBook, pre-supposed</Primary></IndexTerm>
751 All our documentation is written in SGML, using the DocBook DTD and processed using the <ULink URL="http://sourceware.cygnus.com/docbook-tools/">Cygnus DocBook tools</ULink>, which is the most shrink-wrapped SGML suite
752 that we could find.  Unfortunately, it's only packaged as RPMs. You can use it to generate HTML (and
753 hence DVI, PDF and Postscript) and RTF from any
754 LinuxDoc source file (including this manual).
755 </Para>
756 </ListItem></VarListEntry>
757 <VarListEntry>
758 <Term>TeX:</Term>
759 <ListItem>
760 <Para>
761 <IndexTerm><Primary>pre-supposed: TeX</Primary></IndexTerm>
762 <IndexTerm><Primary>TeX, pre-supposed</Primary></IndexTerm>
763 A decent TeX distribution is required if you want to produce printable
764 documentation.  We recomment teTeX, which includes just about
765 everything you need.
766 </Para>
767 </ListItem></VarListEntry>
768 </VariableList>
769 </Para>
770
771 </Sect2>
772
773 <Sect2 id="pre-supposed-other-tools">
774 <Title>Other useful tools
775 </Title>
776
777 <Para>
778 <VariableList>
779
780 <VarListEntry>
781 <Term>Flex:</Term>
782 <ListItem>
783 <Para>
784 <IndexTerm><Primary>pre-supposed: flex</Primary></IndexTerm> 
785 <IndexTerm><Primary>flex, pre-supposed</Primary></IndexTerm>
786 </Para>
787
788 <Para>
789 This is a quite-a-bit-better-than-Lex lexer.  Used to build a couple
790 of utilities in <Literal>glafp-utils</Literal>.  Depending on your operating system,
791 the supplied <Command>lex</Command> may or may not work; you should get the GNU
792 version.
793 </Para>
794 </ListItem></VarListEntry>
795 </VariableList>
796 </Para>
797
798 </Sect2>
799
800 </Sect1>
801
802 <Sect1 id="sec-building-from-source">
803 <Title>Building from source
804
805 <IndexTerm><Primary>Building from source</Primary></IndexTerm>
806 <IndexTerm><Primary>Source, building from</Primary></IndexTerm></Title>
807
808 <Para>
809 You've been rash enough to want to build some of
810 the Glasgow Functional Programming tools (GHC, Happy,
811 nofib, etc.) from source.  You've slurped the source,
812 from the CVS repository or from a source distribution, and
813 now you're sitting looking at a huge mound of bits, wondering
814 what to do next.
815 </Para>
816
817 <Para>
818 Gingerly, you type <Command>make</Command>.  Wrong already!
819 </Para>
820
821 <Para>
822 This rest of this guide is intended for duffers like me, who aren't
823 really interested in Makefiles and systems configurations, but who
824 need a mental model of the interlocking pieces so that they can make
825 them work, extend them consistently when adding new software, and lay
826 hands on them gently when they don't work.
827 </Para>
828
829 <Sect2 id="sec-source-tree">
830 <Title>Your source tree
831 </Title>
832
833 <Para>
834 The source code is held in your <Emphasis>source tree</Emphasis>.
835 The root directory of your source tree <Emphasis>must</Emphasis>
836 contain the following directories and files:
837 </Para>
838
839 <Para>
840
841 <ItemizedList>
842 <ListItem>
843
844 <Para>
845 <Filename>Makefile</Filename>: the root Makefile.
846 </Para>
847 </ListItem>
848 <ListItem>
849
850 <Para>
851 <Filename>mk/</Filename>: the directory that contains the
852 main Makefile code, shared by all the
853 <Literal>fptools</Literal> software.
854 </Para>
855 </ListItem>
856 <ListItem>
857
858 <Para>
859  <Filename>configure.in</Filename>, <Filename>config.sub</Filename>, <Filename>config.guess</Filename>:
860 these files support the configuration process.
861 </Para>
862 </ListItem>
863 <ListItem>
864
865 <Para>
866  <Filename>install-sh</Filename>.
867 </Para>
868 </ListItem>
869
870 </ItemizedList>
871
872 </Para>
873
874 <Para>
875 All the other directories are individual <Emphasis>projects</Emphasis> of the
876 <Literal>fptools</Literal> system&mdash;for example, the Glasgow Haskell Compiler
877 (<Literal>ghc</Literal>), the Happy parser generator (<Literal>happy</Literal>), the <Literal>nofib</Literal> benchmark
878 suite, and so on.  You can have zero or more of these.  Needless to
879 say, some of them are needed to build others.
880 </Para>
881
882 <Para>
883 The important thing to remember is that even if you want only one
884 project (<Literal>happy</Literal>, say), you must have a source tree whose root
885 directory contains <Filename>Makefile</Filename>, <Filename>mk/</Filename>, <Filename>configure.in</Filename>, and the
886 project(s) you want (<Filename>happy/</Filename> in this case).  You cannot get by with
887 just the <Filename>happy/</Filename> directory.
888 </Para>
889
890 </Sect2>
891
892 <Sect2>
893 <Title>Build trees
894 <IndexTerm><Primary>build trees</Primary></IndexTerm>
895 <IndexTerm><Primary>link trees, for building</Primary></IndexTerm></Title>
896
897 <Para>
898 While you can build a system in the source tree, we don't recommend it.
899 We often want to build multiple versions of our software
900 for different architectures, or with different options (e.g. profiling).
901 It's very desirable to share a single copy of the source code among
902 all these builds.
903 </Para>
904
905 <Para>
906 So for every source tree we have zero or more <Emphasis>build trees</Emphasis>.  Each
907 build tree is initially an exact copy of the source tree, except that
908 each file is a symbolic link to the source file, rather than being a
909 copy of the source file.  There are ``standard'' Unix utilities that
910 make such copies, so standard that they go by different names:
911 <Command>lndir</Command><IndexTerm><Primary>lndir</Primary></IndexTerm>, <Command>mkshadowdir</Command><IndexTerm><Primary>mkshadowdir</Primary></IndexTerm> are two (If you
912 don't have either, the source distribution includes sources for the
913 X11 <Command>lndir</Command>&mdash;check out <Filename>fptools/glafp-utils/lndir</Filename>). See <Xref LinkEnd="sec-storysofar"> for a typical invocation.
914 </Para>
915
916 <Para>
917 The build tree does not need to be anywhere near the source tree in
918 the file system.  Indeed, one advantage of separating the build tree
919 from the source is that the build tree can be placed in a
920 non-backed-up partition, saving your systems support people from
921 backing up untold megabytes of easily-regenerated, and
922 rapidly-changing, gubbins.  The golden rule is that (with a single
923 exception&mdash;<XRef LinkEnd="sec-build-config"> <Emphasis>absolutely everything in the build tree is either
924 a symbolic link to the source tree, or else is mechanically
925 generated</Emphasis>.  It should be perfectly OK for your build tree to vanish
926 overnight; an hour or two compiling and you're on the road again.
927 </Para>
928
929 <Para>
930 You need to be a bit careful, though, that any new files you create
931 (if you do any development work) are in the source tree, not a build tree!
932 </Para>
933
934 <Para>
935 Remember, that the source files in the build tree are <Emphasis>symbolic
936 links</Emphasis> to the files in the source tree.  (The build tree soon
937 accumulates lots of built files like <Filename>Foo.o</Filename>, as well.)  You
938 can <Emphasis>delete</Emphasis> a source file from the build tree without affecting
939 the source tree (though it's an odd thing to do).  On the other hand,
940 if you <Emphasis>edit</Emphasis> a source file from the build tree, you'll edit the
941 source-tree file directly.  (You can set up Emacs so that if you edit
942 a source file from the build tree, Emacs will silently create an
943 edited copy of the source file in the build tree, leaving the source
944 file unchanged; but the danger is that you think you've edited the
945 source file whereas actually all you've done is edit the build-tree
946 copy.  More commonly you do want to edit the source file.)
947 </Para>
948
949 <Para>
950 Like the source tree, the top level of your build tree must be (a
951 linked copy of) the root directory of the <Literal>fptools</Literal> suite.  Inside
952 Makefiles, the root of your build tree is called
953 <Constant>&dollar;(FPTOOLS&lowbar;TOP)</Constant><IndexTerm><Primary>FPTOOLS&lowbar;TOP</Primary></IndexTerm>.  In the rest of this document path
954 names are relative to <Constant>&dollar;(FPTOOLS&lowbar;TOP)</Constant> unless otherwise stated.  For
955 example, the file <Filename>ghc/mk/target.mk</Filename> is actually
956 <Filename><Constant>&dollar;(FPTOOLS&lowbar;TOP)</Constant>/ghc/mk/target.mk</Filename>.
957 </Para>
958
959 </Sect2>
960
961 <Sect2 id="sec-build-config">
962 <Title>Getting the build you want
963 </Title>
964
965 <Para>
966 When you build <Literal>fptools</Literal> you will be compiling code on a particular
967 <Emphasis>host platform</Emphasis>, to run on a particular <Emphasis>target platform</Emphasis>
968 (usually the same as the host platform)<IndexTerm><Primary>platform</Primary></IndexTerm>.  The
969 difficulty is that there are minor differences between different
970 platforms; minor, but enough that the code needs to be a bit different
971 for each.  There are some big differences too: for a different
972 architecture we need to build GHC with a different native-code
973 generator.
974 </Para>
975
976 <Para>
977 There are also knobs you can turn to control how the <Literal>fptools</Literal>
978 software is built.  For example, you might want to build GHC optimised
979 (so that it runs fast) or unoptimised (so that you can compile it fast
980 after you've modified it.  Or, you might want to compile it with
981 debugging on (so that extra consistency-checking code gets included)
982 or off.  And so on.
983 </Para>
984
985 <Para>
986 All of this stuff is called the <Emphasis>configuration</Emphasis> of your build.
987 You set the configuration using a three-step process.
988 <VariableList>
989
990 <VarListEntry>
991 <Term>Step 1: get ready for configuration.</Term>
992 <ListItem>
993 <Para>
994 Change directory to
995 <Constant>&dollar;(FPTOOLS&lowbar;TOP)</Constant> and issue the command <Command>autoconf</Command><IndexTerm><Primary>autoconf</Primary></IndexTerm> (with
996 no arguments). This GNU program converts <Filename><Constant>&dollar;(FPTOOLS&lowbar;TOP)</Constant>/configure.in</Filename>
997 to a shell script called <Filename><Constant>&dollar;(FPTOOLS&lowbar;TOP)</Constant>/configure</Filename>.
998 </Para>
999
1000 <Para>
1001 Both these steps are completely platform-independent; they just mean
1002 that the human-written file (<Filename>configure.in</Filename>) can be short, although
1003 the resulting shell script, <Command>configure</Command>, and <Filename>mk/config.h.in</Filename>, are
1004 long.
1005 </Para>
1006
1007 <Para>
1008 In case you don't have <Command>autoconf</Command> we distribute the results,
1009 <Command>configure</Command>, and <Filename>mk/config.h.in</Filename>, with the source distribution.  They
1010 aren't kept in the repository, though.
1011 </Para>
1012 </ListItem></VarListEntry>
1013 <VarListEntry>
1014 <Term>Step 2: system configuration.</Term>
1015 <ListItem>
1016 <Para>
1017 Runs the newly-created <Command>configure</Command> script, thus:
1018
1019 <ProgramListing>
1020 ./configure
1021 </ProgramListing>
1022
1023 <Command>configure</Command>'s mission is to scurry round your computer working out
1024 what architecture it has, what operating system, whether it has the
1025 <Function>vfork</Function> system call, where <Command>yacc</Command> is kept, whether <Command>gcc</Command> is available,
1026 where various obscure <Literal>&num;include</Literal> files are, whether it's a leap year,
1027 and what the systems manager had for lunch.  It communicates these
1028 snippets of information in two ways:
1029 </Para>
1030
1031 <Para>
1032
1033 <ItemizedList>
1034 <ListItem>
1035
1036 <Para>
1037  It translates <Filename>mk/config.mk.in</Filename><IndexTerm><Primary>config.mk.in</Primary></IndexTerm> to
1038 <Filename>mk/config.mk</Filename><IndexTerm><Primary>config.mk</Primary></IndexTerm>, substituting for things between
1039 ``<Literal>@</Literal>'' brackets.  So, ``<Literal>@HaveGcc@</Literal>'' will be replaced by
1040 ``<Literal>YES</Literal>'' or ``<Literal>NO</Literal>'' depending on what <Command>configure</Command> finds.
1041 <Filename>mk/config.mk</Filename> is included by every Makefile (directly or indirectly),
1042 so the configuration information is thereby communicated to all
1043 Makefiles.
1044
1045 </Para>
1046 </ListItem>
1047 <ListItem>
1048
1049 <Para>
1050  It translates <Filename>mk/config.h.in</Filename><IndexTerm><Primary>config.h.in</Primary></IndexTerm> to
1051 <Filename>mk/config.h</Filename><IndexTerm><Primary>config.h</Primary></IndexTerm>.  The latter is <Literal>&num;include</Literal>d by various C
1052 programs, which can thereby make use of configuration information.
1053
1054 </Para>
1055 </ListItem>
1056
1057 </ItemizedList>
1058
1059 </Para>
1060
1061 <Para>
1062 <Command>configure</Command> caches the results of its run in <Filename>config.cache</Filename>.  Quite
1063 often you don't want that; you're running <Command>configure</Command> a second time
1064 because something has changed.  In that case, simply delete
1065 <Filename>config.cache</Filename>.
1066 </Para>
1067 </ListItem></VarListEntry>
1068 <VarListEntry>
1069 <Term>Step 3: build configuration.</Term>
1070 <ListItem>
1071 <Para>
1072 Next, you say how this build of <Literal>fptools</Literal> is to differ from the
1073 standard defaults by creating a new file <Filename>mk/build.mk</Filename><IndexTerm><Primary>build.mk</Primary></IndexTerm>
1074 <Emphasis>in the build tree</Emphasis>.  This file is the one and only file you edit
1075 in the build tree, precisely because it says how this build differs
1076 from the source.  (Just in case your build tree does die, you might
1077 want to keep a private directory of <Filename>build.mk</Filename> files, and use a
1078 symbolic link in each build tree to point to the appropriate one.)  So
1079 <Filename>mk/build.mk</Filename> never exists in the source tree&mdash;you create one in
1080 each build tree from the template.  We'll discuss what to put in it
1081 shortly.  
1082 </Para>
1083 </ListItem></VarListEntry>
1084 </VariableList>
1085 </Para>
1086
1087 <Para>
1088 And that's it for configuration. Simple, eh?
1089 </Para>
1090
1091 <Para>
1092 What do you put in your build-specific configuration file
1093 <Filename>mk/build.mk</Filename>?  <Emphasis>For almost all purposes all you will do is put
1094 make variable definitions that override those in</Emphasis> <Filename>mk/config.mk.in</Filename>.
1095 The whole point of <Filename>mk/config.mk.in</Filename>&mdash;and its derived counterpart
1096 <Filename>mk/config.mk</Filename>&mdash;is to define the build configuration. It is heavily
1097 commented, as you will see if you look at it.  So generally, what you
1098 do is look at <Filename>mk/config.mk.in</Filename>, and add definitions in <Filename>mk/build.mk</Filename>
1099 that override any of the <Filename>config.mk</Filename> definitions that you want to
1100 change.  (The override occurs because the main boilerplate file,
1101 <Filename>mk/boilerplate.mk</Filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm>, includes <Filename>build.mk</Filename> after
1102 <Filename>config.mk</Filename>.)
1103 </Para>
1104
1105 <Para>
1106 For example, <Filename>config.mk.in</Filename> contains the definition:
1107 </Para>
1108
1109 <Para>
1110
1111 <ProgramListing>
1112 ProjectsToBuild = glafp-utils ghc hslibs
1113 </ProgramListing>
1114
1115 </Para>
1116
1117 <Para>
1118 The accompanying comment explains that this is the list of enabled
1119 projects; that is, if (after configuring) you type <Command>gmake all</Command> in
1120 <Constant>FPTOOLS&lowbar;TOP</Constant> three specified projects will be made.  If you want to
1121 add <Command>green-card</Command>, you can add this line to <Filename>build.mk</Filename>:
1122 </Para>
1123
1124 <Para>
1125
1126 <ProgramListing>
1127 ProjectsToBuild += green-card
1128 </ProgramListing>
1129
1130 </Para>
1131
1132 <Para>
1133 or, if you prefer,
1134 </Para>
1135
1136 <Para>
1137
1138 <ProgramListing>
1139 ProjectsToBuild = glafp-utils ghc green-card
1140 </ProgramListing>
1141
1142 </Para>
1143
1144 <Para>
1145 (GNU <Command>make</Command> allows existing definitions to have new text appended
1146 using the ``<Literal>+=</Literal>'' operator, which is quite a convenient feature.)
1147 </Para>
1148
1149 <Para>
1150 When reading <Filename>config.mk.in</Filename>, remember that anything between
1151 ``@...@'' signs is going to be substituted by <Command>configure</Command>
1152 later.  You <Emphasis>can</Emphasis> override the resulting definition if you want,
1153 but you need to be a bit surer what you are doing.  For example,
1154 there's a line that says: 
1155 </Para>
1156
1157 <Para>
1158
1159 <ProgramListing>
1160 YACC = @YaccCmd@
1161 </ProgramListing>
1162
1163 </Para>
1164
1165 <Para>
1166 This defines the Make variables <Constant>YACC</Constant> to the pathname for a <Command>yacc</Command> that
1167 <Command>configure</Command> finds somewhere.  If you have your own pet <Command>yacc</Command> you want
1168 to use instead, that's fine. Just add this line to <Filename>mk/build.mk</Filename>:
1169 </Para>
1170
1171 <Para>
1172
1173 <ProgramListing>
1174 YACC = myyacc
1175 </ProgramListing>
1176
1177 </Para>
1178
1179 <Para>
1180 You do not <Emphasis>have</Emphasis> to have a <Filename>mk/build.mk</Filename> file at all; if you
1181 don't, you'll get all the default settings from <Filename>mk/config.mk.in</Filename>.
1182 </Para>
1183
1184 <Para>
1185 You can also use <Filename>build.mk</Filename> to override anything that <Command>configure</Command> got
1186 wrong.  One place where this happens often is with the definition of
1187 <Constant>FPTOOLS&lowbar;TOP&lowbar;ABS</Constant>: this variable is supposed to be the canonical path
1188 to the top of your source tree, but if your system uses an automounter
1189 then the correct directory is hard to find automatically.  If you find
1190 that <Command>configure</Command> has got it wrong, just put the correct definition in
1191 <Filename>build.mk</Filename>.
1192 </Para>
1193
1194 </Sect2>
1195
1196 <Sect2 id="sec-storysofar">
1197 <Title>The story so far</Title>
1198
1199 <Para>
1200 Let's summarise the steps you need to carry to get yourself
1201 a fully-configured build tree from scratch.
1202 </Para>
1203
1204 <Para>
1205
1206 <OrderedList>
1207 <ListItem>
1208
1209 <Para>
1210  Get your source tree from somewhere (CVS repository or source
1211 distribution).  Say you call the root directory <Filename>myfptools</Filename> (it
1212 does not have to be called <Filename>fptools</Filename>).  Make sure that you have
1213 the essential files (see <XRef LinkEnd="sec-source-tree">).
1214
1215 </Para>
1216 </ListItem>
1217 <ListItem>
1218
1219 <Para>
1220  Use <Command>lndir</Command> or <Command>mkshadowdir</Command> to create a build tree.
1221
1222 <ProgramListing>
1223 cd myfptools
1224 mkshadowdir . /scratch/joe-bloggs/myfptools-sun4
1225 </ProgramListing>
1226
1227 (N.B. <Command>mkshadowdir</Command>'s first argument is taken relative to its second.) You probably want to give the build tree a name that
1228 suggests its main defining characteristic (in your mind at least),
1229 in case you later add others.
1230
1231 </Para>
1232 </ListItem>
1233 <ListItem>
1234
1235 <Para>
1236  Change directory to the build tree.  Everything is going
1237 to happen there now.
1238
1239 <ProgramListing>
1240 cd /scratch/joe-bloggs/myfptools-sun4
1241 </ProgramListing>
1242
1243 </Para>
1244 </ListItem>
1245 <ListItem>
1246
1247 <Para>
1248  Prepare for system configuration:
1249
1250 <ProgramListing>
1251 autoconf
1252 </ProgramListing>
1253
1254 (You can skip this step if you are starting from a source distribution,
1255 and you already have <Filename>configure</Filename> and <Filename>mk/config.h.in</Filename>.)
1256
1257 </Para>
1258 </ListItem>
1259 <ListItem>
1260
1261 <Para>
1262  Do system configuration:
1263
1264 <ProgramListing>
1265 ./configure
1266 </ProgramListing>
1267
1268
1269 </Para>
1270 </ListItem>
1271 <ListItem>
1272
1273 <Para>
1274  Create the file <Filename>mk/build.mk</Filename>, 
1275 adding definitions for your desired configuration options.
1276
1277 <ProgramListing>
1278 emacs mk/build.mk
1279 </ProgramListing>
1280
1281 </Para>
1282 </ListItem>
1283
1284 </OrderedList>
1285
1286 You can make subsequent changes to <Filename>mk/build.mk</Filename> as often 
1287 as you like.  You do not have to run any further configuration 
1288 programs to make these changes take effect.
1289 In theory you should, however, say <Command>gmake clean</Command>, <Command>gmake all</Command>,
1290 because configuration option changes could affect anything&mdash;but in practice you are likely to know what's affected.
1291 </Para>
1292
1293 </Sect2>
1294
1295 <Sect2>
1296 <Title>Making things</Title>
1297
1298 <Para>
1299 At this point you have made yourself a fully-configured build tree,
1300 so you are ready to start building real things.
1301 </Para>
1302
1303 <Para>
1304 The first thing you need to know is that 
1305 <Emphasis>you must use GNU <Command>make</Command>, usually called <Command>gmake</Command>, not standard Unix <Command>make</Command></Emphasis>.
1306 If you use standard Unix <Command>make</Command> you will get all sorts of error messages
1307 (but no damage) because the <Literal>fptools</Literal> <Command>Makefiles</Command> use GNU <Command>make</Command>'s facilities
1308 extensively.
1309 </Para>
1310
1311 </Sect2>
1312
1313 <Sect2 id="sec-standard-targets">
1314 <Title>Standard Targets
1315
1316 <IndexTerm><Primary>targets, standard makefile</Primary></IndexTerm>
1317 <IndexTerm><Primary>makefile targets</Primary></IndexTerm></Title>
1318
1319 <Para>
1320 In any directory you should be able to make the following:
1321 <VariableList>
1322
1323 <VarListEntry>
1324 <Term><Literal>boot</Literal>:</Term>
1325 <ListItem>
1326 <Para>
1327 does the one-off preparation required to get ready for the real work.
1328 Notably, it does <Command>gmake depend</Command> in all directories that contain
1329 programs.  It also builds the necessary tools for compilation to proceed.
1330 </Para>
1331
1332 <Para>
1333 You should say <Command>gmake boot</Command> right after configuring your build tree,
1334 but note that this is a one-off, i.e., there's no need to re-do
1335 <Command>gmake boot</Command> if you should re-configure your build tree at a later
1336 stage (no harm caused if you do though).
1337 </Para>
1338 </ListItem></VarListEntry>
1339 <VarListEntry>
1340 <Term><Literal>all</Literal>:</Term>
1341 <ListItem>
1342 <Para>
1343 makes all the final target(s) for this Makefile.
1344 Depending on which directory you are in a ``final target'' may be an
1345 executable program, a library archive, a shell script, or a Postscript
1346 file.  Typing <Command>gmake</Command> alone is generally the same as typing <Command>gmake all</Command>.
1347 </Para>
1348 </ListItem></VarListEntry>
1349 <VarListEntry>
1350 <Term><Literal>install</Literal>:</Term>
1351 <ListItem>
1352 <Para>
1353 installs the things built by <Literal>all</Literal>.  Where does it
1354 install them?  That is specified by <Filename>mk/config.mk.in</Filename>; you can 
1355 override it in <Filename>mk/build.mk</Filename>.
1356 </Para>
1357 </ListItem></VarListEntry>
1358 <VarListEntry>
1359 <Term><Literal>uninstall</Literal>:</Term>
1360 <ListItem>
1361 <Para>
1362 reverses the effect of <Literal>install</Literal>.
1363 </Para>
1364 </ListItem></VarListEntry>
1365 <VarListEntry>
1366 <Term><Literal>clean</Literal>:</Term>
1367 <ListItem>
1368 <Para>
1369 remove all easily-rebuilt files.
1370 </Para>
1371 </ListItem></VarListEntry>
1372 <VarListEntry>
1373 <Term><Literal>veryclean</Literal>:</Term>
1374 <ListItem>
1375 <Para>
1376 remove all files that can be rebuilt at all.
1377 There's a danger here that you may remove a file that needs a more
1378 obscure utility to rebuild it (especially if you started from a source
1379 distribution).
1380 </Para>
1381 </ListItem></VarListEntry>
1382 <VarListEntry>
1383 <Term><Literal>check</Literal>:</Term>
1384 <ListItem>
1385 <Para>
1386 run the test suite.
1387 </Para>
1388 </ListItem></VarListEntry>
1389 </VariableList>
1390 </Para>
1391
1392 <Para>
1393 All of these standard targets automatically recurse into
1394 sub-directories.  Certain other standard targets do not:
1395 </Para>
1396
1397 <Para>
1398 <VariableList>
1399
1400 <VarListEntry>
1401 <Term><Literal>configure</Literal>:</Term>
1402 <ListItem>
1403 <Para>
1404 is only available in the root directory
1405 <Constant>&dollar;(FPTOOLS&lowbar;TOP)</Constant>; it has been discussed in <XRef LinkEnd="sec-build-config">.
1406 </Para>
1407 </ListItem></VarListEntry>
1408 <VarListEntry>
1409 <Term><Literal>depend</Literal>:</Term>
1410 <ListItem>
1411 <Para>
1412 make a <Filename>.depend</Filename> file in each directory that needs
1413 it. This <Filename>.depend</Filename> file contains mechanically-generated dependency
1414 information; for example, suppose a directory contains a Haskell 
1415 source module <Filename>Foo.lhs</Filename> which imports another module <Literal>Baz</Literal>.
1416 Then the generated <Filename>.depend</Filename> file will contain the dependency:
1417 </Para>
1418
1419 <Para>
1420
1421 <ProgramListing>
1422 Foo.o : Baz.hi
1423 </ProgramListing>
1424
1425 </Para>
1426
1427 <Para>
1428 which says that the object file <Filename>Foo.o</Filename> depends on the interface file
1429 <Filename>Baz.hi</Filename> generated by compiling module <Literal>Baz</Literal>.  The <Filename>.depend</Filename> file is
1430 automatically included by every Makefile.
1431 </Para>
1432 </ListItem></VarListEntry>
1433 <VarListEntry>
1434 <Term><Literal>binary-dist</Literal>:</Term>
1435 <ListItem>
1436 <Para>
1437 make a binary distribution.  This is the
1438 target we use to build the binary distributions of GHC and Happy.
1439 </Para>
1440 </ListItem></VarListEntry>
1441 <VarListEntry>
1442 <Term><Literal>dist</Literal>:</Term>
1443 <ListItem>
1444 <Para>
1445 make a source distribution.  You must be in a
1446 linked build tree to make this target.
1447 </Para>
1448 </ListItem></VarListEntry>
1449 </VariableList>
1450 </Para>
1451
1452 <Para>
1453 Most <Filename>Makefile</Filename>s have targets other than these.  You can discover them by looking in the <Filename>Makefile</Filename> itself.
1454 </Para>
1455
1456 </Sect2>
1457
1458 <Sect2>
1459 <Title>Fast Making
1460 <IndexTerm><Primary>fastmake</Primary></IndexTerm>
1461 <IndexTerm><Primary>dependencies, omitting</Primary></IndexTerm>
1462 <IndexTerm><Primary>FAST, makefile variable</Primary></IndexTerm></Title>
1463
1464 <Para>
1465 Sometimes the dependencies get in the way: if you've made a small
1466 change to one file, and you're absolutely sure that it won't affect
1467 anything else, but you know that <Command>make</Command> is going to rebuild everything
1468 anyway, the following hack may be useful:
1469 </Para>
1470
1471 <Para>
1472
1473 <ProgramListing>
1474 gmake FAST=YES 
1475 </ProgramListing>
1476
1477 </Para>
1478
1479 <Para>
1480 This tells the make system to ignore dependencies and just build what
1481 you tell it to.  In other words, it's equivalent to temporarily
1482 removing the <Filename>.depend</Filename> file in the current directory (where
1483 <Command>mkdependHS</Command> and friends store their dependency information).
1484 </Para>
1485
1486 <Para>
1487 A bit of history: GHC used to come with a <Command>fastmake</Command> script that did
1488 the above job, but GNU make provides the features we need to do it
1489 without resorting to a script.  Also, we've found that fastmaking is
1490 less useful since the advent of GHC's recompilation checker (see the
1491 User's Guide section on "Separate Compilation").
1492 </Para>
1493
1494 </Sect2>
1495
1496 </Sect1>
1497
1498 <Sect1>
1499 <Title>The <Filename>Makefile</Filename> architecture
1500 <IndexTerm><Primary>makefile architecture</Primary></IndexTerm></Title>
1501
1502 <Para>
1503 <Command>make</Command> is great if everything works&mdash;you type <Command>gmake install</Command> and
1504 lo! the right things get compiled and installed in the right places.
1505 Our goal is to make this happen often, but somehow it often doesn't;
1506 instead some weird error message eventually emerges from the bowels of
1507 a directory you didn't know existed.
1508 </Para>
1509
1510 <Para>
1511 The purpose of this section is to give you a road-map to help you figure
1512 out what is going right and what is going wrong.
1513 </Para>
1514
1515 <Sect2>
1516 <Title>A small project</Title>
1517
1518 <Para>
1519 To get started, let us look at the <Filename>Makefile</Filename> for an imaginary small
1520 <Literal>fptools</Literal> project, <Literal>small</Literal>.  Each project in <Literal>fptools</Literal> has its own
1521 directory in <Constant>FPTOOLS&lowbar;TOP</Constant>, so the <Literal>small</Literal> project will have its own
1522 directory <Constant>FPOOLS&lowbar;TOP/small/</Constant>.  Inside the <Filename>small/</Filename> directory there
1523 will be a <Filename>Makefile</Filename>, looking something like this:
1524 </Para>
1525
1526 <Para>
1527 <IndexTerm><Primary>Makefile, minimal</Primary></IndexTerm>
1528
1529 <ProgramListing>
1530 #     Makefile for fptools project "small"
1531
1532 TOP = ..
1533 include $(TOP)/mk/boilerplate.mk
1534
1535 SRCS = $(wildcard *.lhs) $(wildcard *.c)
1536 HS_PROG = small
1537
1538 include $(TOP)/target.mk
1539 </ProgramListing>
1540
1541 </Para>
1542
1543 <Para>
1544 This <Filename>Makefile</Filename> has three sections:
1545 </Para>
1546
1547 <Para>
1548
1549 <OrderedList>
1550 <ListItem>
1551
1552 <Para>
1553  The first section includes
1554 <FOOTNOTE>
1555
1556 <Para>
1557 One of the most important
1558 features of GNU <Command>make</Command> that we use is the ability for a <Filename>Makefile</Filename> to
1559 include another named file, very like <Command>cpp</Command>'s <Literal>&num;include</Literal>
1560 directive.
1561 </Para>
1562
1563 </FOOTNOTE>
1564  a file of ``boilerplate'' code from the level
1565 above (which in this case will be
1566 <Filename><Constant>FPTOOLS&lowbar;TOP</Constant>/mk/boilerplate.mk</Filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm>).  As its name
1567 suggests, <Filename>boilerplate.mk</Filename> consists of a large quantity of standard
1568 <Filename>Makefile</Filename> code.  We discuss this boilerplate in more detail in
1569 <XRef LinkEnd="sec-boiler">.
1570 <IndexTerm><Primary>include, directive in Makefiles</Primary></IndexTerm>
1571 <IndexTerm><Primary>Makefile inclusion</Primary></IndexTerm>
1572
1573 Before the <Literal>include</Literal> statement, you must define the <Command>make</Command> variable
1574 <Constant>TOP</Constant><IndexTerm><Primary>TOP</Primary></IndexTerm> to be the directory containing the <Filename>mk</Filename> directory in
1575 which the <Filename>boilerplate.mk</Filename> file is.  It is <Emphasis>not</Emphasis> OK to simply say
1576
1577
1578 <ProgramListing>
1579 include ../mk/boilerplate.mk  # NO NO NO
1580 </ProgramListing>
1581
1582
1583 Why?  Because the <Filename>boilerplate.mk</Filename> file needs to know where it is, so
1584 that it can, in turn, <Literal>include</Literal> other files.  (Unfortunately, when an
1585 <Literal>include</Literal>d file does an <Literal>include</Literal>, the filename is treated relative to
1586 the directory in which <Command>gmake</Command> is being run, not the directory in
1587 which the <Literal>include</Literal>d sits.)  In general, <Emphasis>every file <Filename>foo.mk</Filename>
1588 assumes that <Filename><Constant>&dollar;(TOP)</Constant>/mk/foo.mk</Filename> refers to itself.</Emphasis> It is up to the
1589 <Filename>Makefile</Filename> doing the <Literal>include</Literal> to ensure this is the case.
1590
1591 Files intended for inclusion in other <Filename>Makefile</Filename>s are written to have
1592 the following property: <Emphasis>after <Filename>foo.mk</Filename> is <Literal>include</Literal>d, it leaves
1593 <Constant>TOP</Constant> containing the same value as it had just before the <Literal>include</Literal>
1594 statement</Emphasis>.  In our example, this invariant guarantees that the
1595 <Literal>include</Literal> for <Filename>target.mk</Filename> will look in the same directory as that for
1596 <Filename>boilerplate.mk</Filename>.
1597
1598 </Para>
1599 </ListItem>
1600 <ListItem>
1601
1602 <Para>
1603  The second section defines the following standard <Command>make</Command>
1604 variables: <Constant>SRCS</Constant><IndexTerm><Primary>SRCS</Primary></IndexTerm> (the source files from which is to be
1605 built), and <Constant>HS&lowbar;PROG</Constant><IndexTerm><Primary>HS&lowbar;PROG</Primary></IndexTerm> (the executable binary to be
1606 built).  We will discuss in more detail what the ``standard
1607 variables'' are, and how they affect what happens, in <XRef LinkEnd="sec-targets">.
1608
1609 The definition for <Constant>SRCS</Constant> uses the useful GNU <Command>make</Command> construct
1610 <Literal>&dollar;(wildcard&nbsp;$pat$)</Literal><IndexTerm><Primary>wildcard</Primary></IndexTerm>, which expands to a list of all
1611 the files matching the pattern <Literal>pat</Literal> in the current directory.  In
1612 this example, <Constant>SRCS</Constant> is set to the list of all the <Filename>.lhs</Filename> and <Filename>.c</Filename>
1613 files in the directory.  (Let's suppose there is one of each,
1614 <Filename>Foo.lhs</Filename> and <Filename>Baz.c</Filename>.)
1615
1616 </Para>
1617 </ListItem>
1618 <ListItem>
1619
1620 <Para>
1621  The last section includes a second file of standard code,
1622 called <Filename>target.mk</Filename><IndexTerm><Primary>target.mk</Primary></IndexTerm>.  It contains the rules that tell
1623 <Command>gmake</Command> how to make the standard targets (<Xref LinkEnd="sec-standard-targets">).  Why, you ask,
1624 can't this standard code be part of <Filename>boilerplate.mk</Filename>?  Good question.
1625 We discuss the reason later, in <Xref LinkEnd="sec-boiler-arch">.
1626
1627 You do not <Emphasis>have</Emphasis> to <Literal>include</Literal> the <Filename>target.mk</Filename> file.  Instead, you
1628 can write rules of your own for all the standard targets.  Usually,
1629 though, you will find quite a big payoff from using the canned rules
1630 in <Filename>target.mk</Filename>; the price tag is that you have to understand what
1631 canned rules get enabled, and what they do (<Xref LinkEnd="sec-targets">).
1632
1633 </Para>
1634 </ListItem>
1635
1636 </OrderedList>
1637
1638 </Para>
1639
1640 <Para>
1641 In our example <Filename>Makefile</Filename>, most of the work is done by the two
1642 <Literal>include</Literal>d files.  When you say <Command>gmake all</Command>, the following things
1643 happen:
1644 </Para>
1645
1646 <Para>
1647
1648 <ItemizedList>
1649 <ListItem>
1650
1651 <Para>
1652  <Command>gmake</Command> figures out that the object files are <Filename>Foo.o</Filename> and
1653 <Filename>Baz.o</Filename>.
1654
1655 </Para>
1656 </ListItem>
1657 <ListItem>
1658
1659 <Para>
1660  It uses a boilerplate pattern rule to compile <Filename>Foo.lhs</Filename> to
1661 <Filename>Foo.o</Filename> using a Haskell compiler.  (Which one?  That is set in the
1662 build configuration.)
1663
1664 </Para>
1665 </ListItem>
1666 <ListItem>
1667
1668 <Para>
1669  It uses another standard pattern rule to compile <Filename>Baz.c</Filename> to
1670 <Filename>Baz.o</Filename>, using a C compiler.  (Ditto.)
1671
1672 </Para>
1673 </ListItem>
1674 <ListItem>
1675
1676 <Para>
1677  It links the resulting <Filename>.o</Filename> files together to make <Literal>small</Literal>,
1678 using the Haskell compiler to do the link step.  (Why not use <Command>ld</Command>?
1679 Because the Haskell compiler knows what standard libraries to link in.
1680 How did <Command>gmake</Command> know to use the Haskell compiler to do the link,
1681 rather than the C compiler?  Because we set the variable <Constant>HS&lowbar;PROG</Constant>
1682 rather than <Constant>C&lowbar;PROG</Constant>.)
1683
1684 </Para>
1685 </ListItem>
1686
1687 </ItemizedList>
1688
1689 </Para>
1690
1691 <Para>
1692 All <Filename>Makefile</Filename>s should follow the above three-section format.
1693 </Para>
1694
1695 </Sect2>
1696
1697 <Sect2>
1698 <Title>A larger project</Title>
1699
1700 <Para>
1701 Larger projects are usually structured into a number of sub-directories,
1702 each of which has its own <Filename>Makefile</Filename>.  (In very large projects, this
1703 sub-structure might be iterated recursively, though that is rare.)
1704 To give you the idea, here's part of the directory structure for
1705 the (rather large) GHC project:
1706 </Para>
1707
1708 <Para>
1709
1710 <Screen>
1711 $(FPTOOLS_TOP)/ghc/
1712   Makefile
1713   mk/
1714     boilerplate.mk
1715     rules.mk
1716    docs/
1717     Makefile
1718     ...source files for documentation...
1719    driver/
1720     Makefile
1721     ...source files for driver...
1722    compiler/
1723     Makefile
1724     parser/...source files for parser...
1725     renamer/...source files for renamer...
1726     ...etc...
1727 </Screen>
1728
1729 </Para>
1730
1731 <Para>
1732 The sub-directories <Filename>docs</Filename>, <Filename>driver</Filename>, <Filename>compiler</Filename>, and so on, each
1733 contains a sub-component of GHC, and each has its own <Filename>Makefile</Filename>.
1734 There must also be a <Filename>Makefile</Filename> in <Filename><Constant>&dollar;(FPTOOLS&lowbar;TOP)</Constant>/ghc</Filename>.  It does most
1735 of its work by recursively invoking <Command>gmake</Command> on the <Filename>Makefile</Filename>s in the
1736 sub-directories.  We say that <Filename>ghc/Makefile</Filename> is a <Emphasis>non-leaf
1737 <Filename>Makefile</Filename></Emphasis>, because it does little except organise its children,
1738 while the <Filename>Makefile</Filename>s in the sub-directories are all <Emphasis>leaf
1739 <Filename>Makefile</Filename>s</Emphasis>.  (In principle the sub-directories might themselves
1740 contain a non-leaf <Filename>Makefile</Filename> and several sub-sub-directories, but
1741 that does not happen in GHC.)
1742 </Para>
1743
1744 <Para>
1745 The <Filename>Makefile</Filename> in <Filename>ghc/compiler</Filename> is considered a leaf <Filename>Makefile</Filename> even
1746 though the <Filename>ghc/compiler</Filename> has sub-directories, because these sub-directories
1747 do not themselves have <Filename>Makefile</Filename>s in them.  They are just used to structure
1748 the collection of modules that make up GHC, but all are managed by the
1749 single <Filename>Makefile</Filename> in <Filename>ghc/compiler</Filename>.
1750 </Para>
1751
1752 <Para>
1753 You will notice that <Filename>ghc/</Filename> also contains a directory <Filename>ghc/mk/</Filename>.  It
1754 contains GHC-specific <Filename>Makefile</Filename> boilerplate code.  More precisely:
1755 </Para>
1756
1757 <Para>
1758
1759 <ItemizedList>
1760 <ListItem>
1761
1762 <Para>
1763  <Filename>ghc/mk/boilerplate.mk</Filename> is included at the top of
1764 <Filename>ghc/Makefile</Filename>, and of all the leaf <Filename>Makefile</Filename>s in the
1765 sub-directories.  It in turn <Literal>include</Literal>s the main boilerplate file
1766 <Filename>mk/boilerplate.mk</Filename>.
1767
1768
1769 </Para>
1770 </ListItem>
1771 <ListItem>
1772
1773 <Para>
1774  <Filename>ghc/mk/target.mk</Filename> is <Literal>include</Literal>d at the bottom of
1775 <Filename>ghc/Makefile</Filename>, and of all the leaf <Filename>Makefile</Filename>s in the
1776 sub-directories.  It in turn <Literal>include</Literal>s the file <Filename>mk/target.mk</Filename>.
1777
1778 </Para>
1779 </ListItem>
1780
1781 </ItemizedList>
1782
1783 </Para>
1784
1785 <Para>
1786 So these two files are the place to look for GHC-wide customisation
1787 of the standard boilerplate.
1788 </Para>
1789
1790 </Sect2>
1791
1792 <Sect2 id="sec-boiler-arch">
1793 <Title>Boilerplate architecture
1794 <IndexTerm><Primary>boilerplate architecture</Primary></IndexTerm>
1795 </Title>
1796
1797 <Para>
1798 Every <Filename>Makefile</Filename> includes a <Filename>boilerplate.mk</Filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm> file
1799 at the top, and <Filename>target.mk</Filename><IndexTerm><Primary>target.mk</Primary></IndexTerm> file at the bottom.  In
1800 this section we discuss what is in these files, and why there have to
1801 be two of them.  In general:
1802 </Para>
1803
1804 <Para>
1805
1806 <ItemizedList>
1807 <ListItem>
1808
1809 <Para>
1810  <Filename>boilerplate.mk</Filename> consists of:
1811
1812 <ItemizedList>
1813 <ListItem>
1814
1815 <Para>
1816  <Emphasis>Definitions of millions of <Command>make</Command> variables</Emphasis> that
1817 collectively specify the build configuration.  Examples:
1818 <Constant>HC&lowbar;OPTS</Constant><IndexTerm><Primary>HC&lowbar;OPTS</Primary></IndexTerm>, the options to feed to the Haskell compiler;
1819 <Constant>NoFibSubDirs</Constant><IndexTerm><Primary>NoFibSubDirs</Primary></IndexTerm>, the sub-directories to enable within the
1820 <Literal>nofib</Literal> project; <Constant>GhcWithHc</Constant><IndexTerm><Primary>GhcWithHc</Primary></IndexTerm>, the name of the Haskell
1821 compiler to use when compiling GHC in the <Literal>ghc</Literal> project.  
1822 </Para>
1823 </ListItem>
1824 <ListItem>
1825
1826 <Para>
1827 <Emphasis>Standard pattern rules</Emphasis> that tell <Command>gmake</Command> how to construct one
1828 file from another.
1829 </Para>
1830 </ListItem>
1831
1832 </ItemizedList>
1833
1834
1835 <Filename>boilerplate.mk</Filename> needs to be <Literal>include</Literal>d at the <Emphasis>top</Emphasis>
1836 of each <Filename>Makefile</Filename>, so that the user can replace the
1837 boilerplate definitions or pattern rules by simply giving a new
1838 definition or pattern rule in the <Filename>Makefile</Filename>.  <Command>gmake</Command>
1839 simply takes the last definition as the definitive one.
1840
1841 Instead of <Emphasis>replacing</Emphasis> boilerplate definitions, it is also quite
1842 common to <Emphasis>augment</Emphasis> them. For example, a <Filename>Makefile</Filename> might say:
1843
1844
1845 <ProgramListing>
1846 SRC_HC_OPTS += -O
1847 </ProgramListing>
1848
1849
1850 thereby adding ``<Option>-O</Option>'' to the end of <Constant>SRC&lowbar;HC&lowbar;OPTS</Constant><IndexTerm><Primary>SRC&lowbar;HC&lowbar;OPTS</Primary></IndexTerm>.
1851
1852 </Para>
1853 </ListItem>
1854 <ListItem>
1855
1856 <Para>
1857  <Filename>target.mk</Filename> contains <Command>make</Command> rules for the standard
1858 targets described in <Xref LinkEnd="sec-standard-targets">.  These rules are selectively included,
1859 depending on the setting of certain <Command>make</Command> variables.  These
1860 variables are usually set in the middle section of the
1861 <Filename>Makefile</Filename> between the two <Literal>include</Literal>s.
1862
1863 <Filename>target.mk</Filename> must be included at the end (rather than being part of
1864 <Filename>boilerplate.mk</Filename>) for several tiresome reasons:
1865
1866
1867 <ItemizedList>
1868 <ListItem>
1869
1870 <Para>
1871  <Command>gmake</Command> commits target and dependency lists earlier than
1872 it should.  For example, <FIlename>target.mk</FIlename> has a rule that looks like
1873 this: 
1874
1875
1876 <ProgramListing>
1877 $(HS_PROG) : $(OBJS)
1878       $(HC) $(LD_OPTS) $&#60; -o $@
1879 </ProgramListing>
1880
1881
1882 If this rule was in <Filename>boilerplate.mk</Filename> then <Constant>&dollar;(HS&lowbar;PROG)</Constant><IndexTerm><Primary>HS&lowbar;PROG</Primary></IndexTerm>
1883 and <Constant>&dollar;(OBJS)</Constant><IndexTerm><Primary>OBJS</Primary></IndexTerm> would not have their final values at the
1884 moment <Command>gmake</Command> encountered the rule.  Alas, <Command>gmake</Command> takes a snapshot
1885 of their current values, and wires that snapshot into the rule.  (In
1886 contrast, the commands executed when the rule ``fires'' are only
1887 substituted at the moment of firing.)  So, the rule must follow the
1888 definitions given in the <Filename>Makefile</Filename> itself.
1889
1890 </Para>
1891 </ListItem>
1892 <ListItem>
1893
1894 <Para>
1895  Unlike pattern rules, ordinary rules cannot be overriden or
1896 replaced by subsequent rules for the same target (at least, not without an
1897 error message).  Including ordinary rules in <Filename>boilerplate.mk</Filename> would
1898 prevent the user from writing rules for specific targets in specific cases.
1899
1900 </Para>
1901 </ListItem>
1902 <ListItem>
1903
1904 <Para>
1905  There are a couple of other reasons I've forgotten, but it doesn't
1906 matter too much.
1907 </Para>
1908 </ListItem>
1909
1910 </ItemizedList>
1911
1912 </Para>
1913 </ListItem>
1914
1915 </ItemizedList>
1916
1917 </Para>
1918
1919 </Sect2>
1920
1921 <Sect2 id="sec-boiler">
1922 <Title>The main <Filename>mk/boilerplate.mk</Filename> file
1923
1924 <IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm></Title>
1925
1926 <Para>
1927 If you look at <Filename><Constant>&dollar;(FPTOOLS&lowbar;TOP)</Constant>/mk/boilerplate.mk</Filename> you will find
1928 that it consists of the following sections, each held in a separate
1929 file: 
1930 </Para>
1931
1932 <Para>
1933 <VariableList>
1934
1935 <VarListEntry>
1936 <Term><Filename>config.mk</Filename><IndexTerm><Primary>config.mk</Primary></IndexTerm></Term>
1937 <ListItem>
1938 <Para>
1939 is the build configuration file we
1940 discussed at length in <Xref LinkEnd="sec-build-config">.
1941 </Para>
1942 </ListItem></VarListEntry>
1943 <VarListEntry>
1944 <Term><Filename>paths.mk</Filename><IndexTerm><Primary>paths.mk</Primary></IndexTerm></Term>
1945 <ListItem>
1946 <Para>
1947 defines <Command>make</Command> variables for
1948 pathnames and file lists.  In particular, it gives definitions for:
1949 </Para>
1950
1951 <Para>
1952 <VariableList>
1953
1954 <VarListEntry>
1955 <Term><Constant>SRCS</Constant><IndexTerm><Primary>SRCS</Primary></IndexTerm>:</Term>
1956 <ListItem>
1957 <Para>
1958 all source files in the current directory.
1959 </Para>
1960 </ListItem></VarListEntry>
1961 <VarListEntry>
1962 <Term><Constant>HS&lowbar;SRCS</Constant><IndexTerm><Primary>HS&lowbar;SRCS</Primary></IndexTerm>:</Term>
1963 <ListItem>
1964 <Para>
1965 all Haskell source files in the current directory.
1966 It is derived from <Constant>&dollar;(SRCS)</Constant>, so if you override <Constant>SRCS</Constant> with a new value
1967 <Constant>HS&lowbar;SRCS</Constant> will follow suit.
1968 </Para>
1969 </ListItem></VarListEntry>
1970 <VarListEntry>
1971 <Term><Constant>C&lowbar;SRCS</Constant><IndexTerm><Primary>C&lowbar;SRCS</Primary></IndexTerm>:</Term>
1972 <ListItem>
1973 <Para>
1974 similarly for C source files.
1975 </Para>
1976 </ListItem></VarListEntry>
1977 <VarListEntry>
1978 <Term><Constant>HS&lowbar;OBJS</Constant><IndexTerm><Primary>HS&lowbar;OBJS</Primary></IndexTerm>:</Term>
1979 <ListItem>
1980 <Para>
1981 the <Filename>.o</Filename> files derived from <Constant>&dollar;(HS&lowbar;SRCS)</Constant>.
1982 </Para>
1983 </ListItem></VarListEntry>
1984 <VarListEntry>
1985 <Term><Constant>C&lowbar;OBJS</Constant><IndexTerm><Primary>C&lowbar;OBJS</Primary></IndexTerm>:</Term>
1986 <ListItem>
1987 <Para>
1988 similarly for <Constant>&dollar;(C&lowbar;SRCS)</Constant>.
1989 </Para>
1990 </ListItem></VarListEntry>
1991 <VarListEntry>
1992 <Term><Constant>OBJS</Constant><IndexTerm><Primary>OBJS</Primary></IndexTerm>:</Term>
1993 <ListItem>
1994 <Para>
1995 the concatenation of <Constant>&dollar;(HS&lowbar;OBJS)</Constant> and <Constant>&dollar;(C&lowbar;OBJS)</Constant>.
1996 </Para>
1997 </ListItem></VarListEntry>
1998 </VariableList>
1999 </Para>
2000
2001 <Para>
2002 Any or all of these definitions can easily be overriden by giving new
2003 definitions in your <Filename>Makefile</Filename>.  For example, if there are things in
2004 the current directory that look like source files but aren't, then
2005 you'll need to set <Constant>SRCS</Constant> manually in your <Filename>Makefile</Filename>.  The other
2006 definitions will then work from this new definition.
2007 </Para>
2008
2009 <Para>
2010 What, exactly, does <Filename>paths.mk</Filename> consider a ``source file'' to be?  It's
2011 based on the file's suffix (e.g. <Filename>.hs</Filename>, <Filename>.lhs</Filename>, <Filename>.c</Filename>, <Filename>.lc</Filename>, etc), but
2012 this is the kind of detail that changes, so rather than
2013 enumerate the source suffices here the best thing to do is to look in
2014 <Filename>paths.mk</Filename>.
2015 </Para>
2016 </ListItem></VarListEntry>
2017 <VarListEntry>
2018 <Term><Filename>opts.mk</Filename><IndexTerm><Primary>opts.mk</Primary></IndexTerm></Term>
2019 <ListItem>
2020 <Para>
2021 defines <Command>make</Command> variables for option
2022 strings to pass to each program. For example, it defines
2023 <Constant>HC&lowbar;OPTS</Constant><IndexTerm><Primary>HC&lowbar;OPTS</Primary></IndexTerm>, the option strings to pass to the Haskell
2024 compiler.  See <Xref LinkEnd="sec-suffix">.
2025 </Para>
2026 </ListItem></VarListEntry>
2027 <VarListEntry>
2028 <Term><Filename>suffix.mk</Filename><IndexTerm><Primary>suffix.mk</Primary></IndexTerm></Term>
2029 <ListItem>
2030 <Para>
2031 defines standard pattern rules&mdash;see <Xref LinkEnd="sec-suffix">.
2032 </Para>
2033 </ListItem></VarListEntry>
2034 </VariableList>
2035 </Para>
2036
2037 <Para>
2038 Any of the variables and pattern rules defined by the boilerplate file
2039 can easily be overridden in any particular <Filename>Makefile</Filename>, because the
2040 boilerplate <Literal>include</Literal> comes first.  Definitions after this <Literal>include</Literal>
2041 directive simply override the default ones in <Filename>boilerplate.mk</Filename>.
2042 </Para>
2043
2044 </Sect2>
2045
2046 <Sect2 id="sec-suffix">
2047 <Title>Pattern rules and options
2048
2049 <IndexTerm><Primary>Pattern rules</Primary></IndexTerm></Title>
2050
2051 <Para>
2052 The file <Filename>suffix.mk</Filename><IndexTerm><Primary>suffix.mk</Primary></IndexTerm> defines standard <Emphasis>pattern
2053 rules</Emphasis> that say how to build one kind of file from another, for
2054 example, how to build a <Filename>.o</Filename> file from a <Filename>.c</Filename> file.  (GNU <Command>make</Command>'s
2055 <Emphasis>pattern rules</Emphasis> are more powerful and easier to use than Unix
2056 <Command>make</Command>'s <Emphasis>suffix rules</Emphasis>.)
2057 </Para>
2058
2059 <Para>
2060 Almost all the rules look something like this:
2061 </Para>
2062
2063 <Para>
2064
2065 <ProgramListing>
2066 %.o : %.c
2067       $(RM) $@
2068       $(CC) $(CC_OPTS) -c $&#60; -o $@
2069 </ProgramListing>
2070
2071 </Para>
2072
2073 <Para>
2074 Here's how to understand the rule.  It says that
2075 <Emphasis>something</Emphasis><Filename>.o</Filename> (say <Filename>Foo.o</Filename>) can be built from
2076 <Emphasis>something</Emphasis><Filename>.c</Filename> (<Filename>Foo.c</Filename>), by invoking the C compiler
2077 (path name held in <Constant>&dollar;(CC)</Constant>), passing to it the options
2078 <Constant>&dollar;(CC&lowbar;OPTS)</Constant> and the rule's dependent file of the rule
2079 <Literal>&dollar;&lt;</Literal> (<Filename>Foo.c</Filename> in this case), and putting the result in
2080 the rule's target <Literal>&dollar;@</Literal> (<Filename>Foo.o</Filename> in this case).
2081 </Para>
2082
2083 <Para>
2084 Every program is held in a <Command>make</Command> variable defined in
2085 <Filename>mk/config.mk</Filename>&mdash;look in <Filename>mk/config.mk</Filename> for the
2086 complete list.  One important one is the Haskell compiler, which is
2087 called <Constant>&dollar;(HC)</Constant>.
2088 </Para>
2089
2090 <Para>
2091 Every program's options are are held in a <Command>make</Command> variables called
2092 <Constant>&lt;prog&gt;&lowbar;OPTS</Constant>.  the <Constant>&lt;prog&gt;&lowbar;OPTS</Constant> variables are defined in
2093 <Filename>mk/opts.mk</Filename>.  Almost all of them are defined like this:
2094 </Para>
2095
2096 <Para>
2097
2098 <ProgramListing>
2099 CC_OPTS = $(SRC_CC_OPTS) $(WAY$(_way)_CC_OPTS) $($*_CC_OPTS) $(EXTRA_CC_OPTS)
2100 </ProgramListing>
2101
2102 </Para>
2103
2104 <Para>
2105 The four variables from which <Constant>CC&lowbar;OPTS</Constant> is built have the following meaning:
2106 </Para>
2107
2108 <Para>
2109 <VariableList>
2110
2111 <VarListEntry>
2112 <Term><Constant>SRC&lowbar;CC&lowbar;OPTS</Constant><IndexTerm><Primary>SRC&lowbar;CC&lowbar;OPTS</Primary></IndexTerm>:</Term>
2113 <ListItem>
2114 <Para>
2115 options passed to all C
2116 compilations.
2117 </Para>
2118 </ListItem></VarListEntry>
2119 <VarListEntry>
2120 <Term><Constant>WAY&lowbar;&lt;way&gt;&lowbar;CC&lowbar;OPTS</Constant>:</Term>
2121 <ListItem>
2122 <Para>
2123 options passed to C
2124 compilations for way <Literal>&lt;way&gt;</Literal>. For example,
2125 <Constant>WAY&lowbar;mp&lowbar;CC&lowbar;OPTS</Constant> gives options to pass to the C compiler when
2126 compiling way <Literal>mp</Literal>.  The variable <Constant>WAY&lowbar;CC&lowbar;OPTS</Constant> holds
2127 options to pass to the C compiler when compiling the standard way.
2128 (<Xref LinkEnd="sec-ways"> dicusses multi-way
2129 compilation.)  
2130 </Para>
2131 </ListItem></VarListEntry>
2132 <VarListEntry>
2133 <Term><Constant>&lt;module&gt;&lowbar;CC&lowbar;OPTS</Constant>:</Term>
2134 <ListItem>
2135 <Para>
2136 options to
2137 pass to the C compiler that are specific to module <Literal>&lt;module&gt;</Literal>.  For example, <Constant>SMap&lowbar;CC&lowbar;OPTS</Constant> gives the specific options
2138 to pass to the C compiler when compiling <Filename>SMap.c</Filename>.
2139 </Para>
2140 </ListItem></VarListEntry>
2141 <VarListEntry>
2142 <Term><Constant>EXTRA&lowbar;CC&lowbar;OPTS</Constant><IndexTerm><Primary>EXTRA&lowbar;CC&lowbar;OPTS</Primary></IndexTerm>:</Term>
2143 <ListItem>
2144 <Para>
2145 extra options to pass to all
2146 C compilations.  This is intended for command line use, thus:
2147 </Para>
2148
2149 <Para>
2150
2151 <ProgramListing>
2152 gmake libHS.a EXTRA_CC_OPTS="-v"
2153 </ProgramListing>
2154
2155 </Para>
2156 </ListItem></VarListEntry>
2157 </VariableList>
2158 </Para>
2159
2160 </Sect2>
2161
2162 <Sect2 id="sec-targets">
2163 <Title>The main <Filename>mk/target.mk</Filename> file
2164
2165 <IndexTerm><Primary>target.mk</Primary></IndexTerm></Title>
2166
2167 <Para>
2168 <Filename>target.mk</Filename> contains canned rules for all the standard targets
2169 described in <Xref LinkEnd="sec-standard-targets">.  It is complicated by the fact that you don't want all of
2170 these rules to be active in every <Filename>Makefile</Filename>.  Rather than have a
2171 plethora of tiny files which you can include selectively, there is a
2172 single file, <Filename>target.mk</Filename>, which selectively includes rules based on
2173 whether you have defined certain variables in your <Filename>Makefile</Filename>.  This
2174 section explains what rules you get, what variables control them, and
2175 what the rules do.  Hopefully, you will also get enough of an idea of
2176 what is supposed to happen that you can read and understand any weird
2177 special cases yourself.
2178 </Para>
2179
2180 <Para>
2181 <VariableList>
2182
2183 <VarListEntry>
2184 <Term><Constant>HS&lowbar;PROG</Constant><IndexTerm><Primary>HS&lowbar;PROG</Primary></IndexTerm>.</Term>
2185 <ListItem>
2186 <Para>
2187 If <Constant>HS&lowbar;PROG</Constant> is defined, you get
2188 rules with the following targets:
2189 <VariableList>
2190
2191 <VarListEntry>
2192 <Term><Filename>HS&lowbar;PROG</Filename><IndexTerm><Primary>HS&lowbar;PROG</Primary></IndexTerm></Term>
2193 <ListItem>
2194 <Para>
2195 itself.  This rule links <Constant>&dollar;(OBJS)</Constant>
2196 with the Haskell runtime system to get an executable called
2197 <Constant>&dollar;(HS&lowbar;PROG)</Constant>.
2198 </Para>
2199 </ListItem></VarListEntry>
2200 <VarListEntry>
2201 <Term><Literal>install</Literal><IndexTerm><Primary>install</Primary></IndexTerm></Term>
2202 <ListItem>
2203 <Para>
2204 installs <Constant>&dollar;(HS&lowbar;PROG)</Constant>
2205 in <Constant>&dollar;(bindir)</Constant>.
2206 </Para>
2207 </ListItem></VarListEntry>
2208 </VariableList>
2209 </Para>
2210 </ListItem></VarListEntry>
2211 <VarListEntry>
2212 <Term><Constant>C&lowbar;PROG</Constant><IndexTerm><Primary>C&lowbar;PROG</Primary></IndexTerm></Term>
2213 <ListItem>
2214 <Para>
2215 is similar to <Constant>HS&lowbar;PROG</Constant>, except that
2216 the link step links <Constant>&dollar;(C&lowbar;OBJS)</Constant> with the C runtime system.
2217 </Para>
2218 </ListItem></VarListEntry>
2219 <VarListEntry>
2220 <Term><Constant>LIBRARY</Constant><IndexTerm><Primary>LIBRARY</Primary></IndexTerm></Term>
2221 <ListItem>
2222 <Para>
2223 is similar to <Constant>HS&lowbar;PROG</Constant>, except that
2224 it links <Constant>&dollar;(LIB&lowbar;OBJS)</Constant> to make the library archive <Constant>&dollar;(LIBRARY)</Constant>, and
2225 <Literal>install</Literal> installs it in <Constant>&dollar;(libdir)</Constant>.
2226 </Para>
2227 </ListItem></VarListEntry>
2228 <VarListEntry>
2229 <Term><Constant>LIB&lowbar;DATA</Constant><IndexTerm><Primary>LIB&lowbar;DATA</Primary></IndexTerm></Term>
2230 <ListItem>
2231 <Para>
2232 &hellip;
2233 </Para>
2234 </ListItem></VarListEntry>
2235 <VarListEntry>
2236 <Term><Constant>LIB&lowbar;EXEC</Constant><IndexTerm><Primary>LIB&lowbar;EXEC</Primary></IndexTerm></Term>
2237 <ListItem>
2238 <Para>
2239 &hellip;
2240 </Para>
2241 </ListItem></VarListEntry>
2242 <VarListEntry>
2243 <Term><Constant>HS&lowbar;SRCS</Constant><IndexTerm><Primary>HS&lowbar;SRCS</Primary></IndexTerm>, <Constant>C&lowbar;SRCS</Constant><IndexTerm><Primary>C&lowbar;SRCS</Primary></IndexTerm>.</Term>
2244 <ListItem>
2245 <Para>
2246 If <Constant>HS&lowbar;SRCS</Constant>
2247 is defined and non-empty, a rule for the target <Literal>depend</Literal> is included,
2248 which generates dependency information for Haskell programs.
2249 Similarly for <Constant>C&lowbar;SRCS</Constant>.
2250 </Para>
2251 </ListItem></VarListEntry>
2252 </VariableList>
2253 </Para>
2254
2255 <Para>
2256 All of these rules are ``double-colon'' rules, thus
2257 </Para>
2258
2259 <Para>
2260
2261 <ProgramListing>
2262 install :: $(HS_PROG)
2263       ...how to install it...
2264 </ProgramListing>
2265
2266 </Para>
2267
2268 <Para>
2269 GNU <Command>make</Command> treats double-colon rules as separate entities.  If there
2270 are several double-colon rules for the same target it takes each in
2271 turn and fires it if its dependencies say to do so.  This means that
2272 you can, for example, define both <Constant>HS&lowbar;PROG</Constant> and <Constant>LIBRARY</Constant>, which will
2273 generate two rules for <Literal>install</Literal>.  When you type <Command>gmake install</Command> both
2274 rules will be fired, and both the program and the library will be
2275 installed, just as you wanted.
2276 </Para>
2277
2278 </Sect2>
2279
2280 <Sect2 id="sec-subdirs">
2281 <Title>Recursion
2282
2283 <IndexTerm><Primary>recursion, in makefiles</Primary></IndexTerm>
2284 <IndexTerm><Primary>Makefile, recursing into subdirectories</Primary></IndexTerm></Title>
2285
2286 <Para>
2287 In leaf <Filename>Makefile</Filename>s the variable <Constant>SUBDIRS</Constant><IndexTerm><Primary>SUBDIRS</Primary></IndexTerm> is undefined.
2288 In non-leaf <Filename>Makefile</Filename>s, <Constant>SUBDIRS</Constant> is set to the list of
2289 sub-directories that contain subordinate <Filename>Makefile</Filename>s.  <Emphasis>It is up to
2290 you to set <Constant>SUBDIRS</Constant> in the <Filename>Makefile</Filename>.</Emphasis> There is no automation here&mdash;<Constant>SUBDIRS</Constant> is too important to automate.
2291 </Para>
2292
2293 <Para>
2294 When <Constant>SUBDIRS</Constant> is defined, <Filename>target.mk</Filename> includes a rather
2295 neat rule for the standard targets (<Xref LinkEnd="sec-standard-targets"> that simply invokes
2296 <Command>make</Command> recursively in each of the sub-directories.
2297 </Para>
2298
2299 <Para>
2300 <Emphasis>These recursive invocations are guaranteed to occur in the order
2301 in which the list of directories is specified in <Constant>SUBDIRS</Constant>. </Emphasis>This
2302 guarantee can be important.  For example, when you say <Command>gmake boot</Command> it
2303 can be important that the recursive invocation of <Command>make boot</Command> is done
2304 in one sub-directory (the include files, say) before another (the
2305 source files).  Generally, put the most independent sub-directory
2306 first, and the most dependent last.
2307 </Para>
2308
2309 </Sect2>
2310
2311 <Sect2 id="sec-ways">
2312 <Title>Way management
2313
2314 <IndexTerm><Primary>way management</Primary></IndexTerm></Title>
2315
2316 <Para>
2317 We sometimes want to build essentially the same system in several
2318 different ``ways''.  For example, we want to build GHC's <Literal>Prelude</Literal>
2319 libraries with and without profiling, with and without concurrency,
2320 and so on, so that there is an appropriately-built library archive to
2321 link with when the user compiles his program.  It would be possible to
2322 have a completely separate build tree for each such ``way'', but it
2323 would be horribly bureaucratic, especially since often only parts of
2324 the build tree need to be constructed in multiple ways.
2325 </Para>
2326
2327 <Para>
2328 Instead, the <Filename>target.mk</Filename><IndexTerm><Primary>target.mk</Primary></IndexTerm> contains some clever magic to
2329 allow you to build several versions of a system; and to control
2330 locally how many versions are built and how they differ.  This section
2331 explains the magic.
2332 </Para>
2333
2334 <Para>
2335 The files for a particular way are distinguished by munging the
2336 suffix.  The ``normal way'' is always built, and its files have the
2337 standard suffices <Filename>.o</Filename>, <Filename>.hi</Filename>, and so on.  In addition, you can build
2338 one or more extra ways, each distinguished by a <Emphasis>way tag</Emphasis>.  The
2339 object files and interface files for one of these extra ways are
2340 distinguished by their suffix.  For example, way <Literal>mp</Literal> has files
2341 <Filename>.mp&lowbar;o</Filename> and <Filename>.mp&lowbar;hi</Filename>.  Library archives have their way tag the other
2342 side of the dot, for boring reasons; thus, <Filename>libHS&lowbar;mp.a</Filename>.
2343 </Para>
2344
2345 <Para>
2346 A <Command>make</Command> variable called <Constant>way</Constant> holds the current way tag.  <Emphasis><Constant>way</Constant>
2347 is only ever set on the command line of a recursive invocation of
2348 <Command>gmake</Command>.</Emphasis> It is never set inside a <Filename>Makefile</Filename>.  So it is a global
2349 constant for any one invocation of <Command>gmake</Command>.  Two other <Command>make</Command>
2350 variables, <Constant>way&lowbar;</Constant> and <Constant>&lowbar;way</Constant> are immediately derived from <Constant>&dollar;(way)</Constant> and
2351 never altered.  If <Constant>way</Constant> is not set, then neither are <Constant>way&lowbar;</Constant> and
2352 <Constant>&lowbar;way</Constant>, and the invocation of <Command>make</Command> will build the ``normal way''.
2353 If <Constant>way</Constant> is set, then the other two variables are set in sympathy.
2354 For example, if <Constant>&dollar;(way)</Constant> is ``<Literal>mp</Literal>'', then <Constant>way&lowbar;</Constant> is set to ``<Literal>mp&lowbar;</Literal>''
2355 and <Constant>&lowbar;way</Constant> is set to ``<Literal>&lowbar;mp</Literal>''.  These three variables are then used
2356 when constructing file names.
2357 </Para>
2358
2359 <Para>
2360 So how does <Command>make</Command> ever get recursively invoked with <Constant>way</Constant> set?  There
2361 are two ways in which this happens:
2362 </Para>
2363
2364 <Para>
2365
2366 <ItemizedList>
2367 <ListItem>
2368
2369 <Para>
2370  For some (but not all) of the standard targets, when in a leaf
2371 sub-directory, <Command>make</Command> is recursively invoked for each way tag in
2372 <Constant>&dollar;(WAYS)</Constant>.  You set <Constant>WAYS</Constant> to the list of way tags you want these
2373 targets built for.  The mechanism here is very much like the recursive
2374 invocation of <Command>make</Command> in sub-directories (<Xref LinkEnd="sec-subdirs">).
2375
2376 It is up to you to set <Constant>WAYS</Constant> in your <Filename>Makefile</Filename>; this is how you
2377 control what ways will get built.  
2378 </Para>
2379 </ListItem>
2380 <ListItem>
2381
2382 <Para>
2383  For a useful collection of
2384 targets (such as <Filename>libHS&lowbar;mp.a</Filename>, <Filename>Foo.mp&lowbar;o</Filename>) there is a rule which
2385 recursively invokes <Command>make</Command> to make the specified target, setting the
2386 <Constant>way</Constant> variable.  So if you say <Command>gmake Foo.mp&lowbar;o</Command> you should see a
2387 recursive invocation <Command>gmake Foo.mp&lowbar;o way=mp</Command>, and <Emphasis>in this
2388 recursive invocation the pattern rule for compiling a Haskell file
2389 into a <Filename>.o</Filename> file will match</Emphasis>.  The key pattern rules (in <Filename>suffix.mk</Filename>)
2390 look like this:
2391
2392
2393 <ProgramListing>
2394 %.$(way_)o : %.lhs
2395       $(HC) $(HC_OPTS) $&#60; -o $@
2396 </ProgramListing>
2397
2398
2399 Neat, eh?
2400 </Para>
2401 </ListItem>
2402
2403 </ItemizedList>
2404
2405 </Para>
2406
2407 </Sect2>
2408
2409 <Sect2>
2410 <Title>When the canned rule isn't right</Title>
2411
2412 <Para>
2413 Sometimes the canned rule just doesn't do the right thing.  For
2414 example, in the <Literal>nofib</Literal> suite we want the link step to print out
2415 timing information.  The thing to do here is <Emphasis>not</Emphasis> to define
2416 <Constant>HS&lowbar;PROG</Constant> or <Constant>C&lowbar;PROG</Constant>, and instead define a special purpose rule in
2417 your own <Filename>Makefile</Filename>.  By using different variable names you will avoid
2418 the canned rules being included, and conflicting with yours.
2419 </Para>
2420
2421 </Sect2>
2422
2423 </Sect1>
2424
2425 <Sect1 id="sec-booting-from-C">
2426 <Title>Booting/porting from C (<Filename>.hc</Filename>) files
2427
2428 <IndexTerm><Primary>building GHC from .hc files</Primary></IndexTerm>
2429 <IndexTerm><Primary>booting GHC from .hc files</Primary></IndexTerm>
2430 <IndexTerm><Primary>porting GHC</Primary></IndexTerm></Title>
2431
2432 <Para>
2433 This section is for people trying to get GHC going by using the
2434 supplied intermediate C (<Filename>.hc</Filename>) files.  This would probably be because
2435 no binaries have been provided, or because the machine is not ``fully
2436 supported''.
2437 </Para>
2438
2439 <Para>
2440 The intermediate C files are normally made available together with a
2441 source release, please check the announce message for exact directions
2442 of where to find them. If we haven't made them available or you
2443 can't find them, please ask.
2444 </Para>
2445
2446 <Para>
2447 Assuming you've got them, unpack them on top of a fresh source tree.
2448 Then follow the `normal' instructions in <Xref LinkEnd="sec-building-from-source"> for setting
2449 up a build tree. When you invoke the configure script, you'll have
2450 to tell the script about your intentions:
2451 </Para>
2452
2453 <Para>
2454
2455 <Screen>
2456 foo% ./configure --enable-hc-boot
2457 </Screen>
2458
2459 <IndexTerm><Primary>--enable-hc-boot</Primary></IndexTerm>
2460 <IndexTerm><Primary>--disable-hc-boot</Primary></IndexTerm>
2461 </Para>
2462
2463 <Para>
2464 Assuming it configures OK and you don't need to create <Filename>mk/build.mk</Filename>
2465 for any other purposes, the next step is to proceed with a <Command>make boot</Command>
2466 followed by <Command>make all</Command>. At the successful completion of <Command>make all</Command>,
2467 you should end up with a binary of the compiler proper,
2468 <Filename>ghc/compiler/hsc</Filename>, plus archives (but no <Filename>.hi</Filename> files!) of the prelude
2469 libraries. To generate the Prelude interface files (and test drive the
2470 bootstrapped compiler), re-run the <Command>configure</Command> script, but this time
2471 without the <Option>--enable-hc-boot</Option> option. After that re-create the
2472 contents of <Filename>ghc/lib</Filename>:
2473 </Para>
2474
2475 <Para>
2476
2477 <Screen>
2478 foo% ./configure
2479  ....
2480 foo% cd ghc/lib
2481 foo% make clean
2482 foo% make boot
2483 foo% make all
2484 </Screen>
2485
2486 </Para>
2487
2488 <Para>
2489 That's the mechanics of the boot process, but, of course, if you're
2490 trying to boot on a platform that is not supported and significantly
2491 `different' from any of the supported ones, this is only the start of
2492 the adventure&hellip;(ToDo: porting tips&mdash;stuff to look out for, etc.)
2493 </Para>
2494
2495 </Sect1>
2496
2497 <Sect1 id="sec-build-pitfalls">
2498 <Title>Known pitfalls in building Glasgow Haskell
2499
2500 <IndexTerm><Primary>problems, building</Primary></IndexTerm>
2501 <IndexTerm><Primary>pitfalls, in building</Primary></IndexTerm>
2502 <IndexTerm><Primary>building pitfalls</Primary></IndexTerm></Title>
2503
2504 <Para>
2505 WARNINGS about pitfalls and known ``problems'':
2506 </Para>
2507
2508 <Para>
2509
2510 <OrderedList>
2511 <ListItem>
2512
2513 <Para>
2514 One difficulty that comes up from time to time is running out of space
2515 in <Filename>/tmp</Filename>.  (It is impossible for the configuration stuff to
2516 compensate for the vagaries of different sysadmin approaches to temp
2517 space.)
2518 <IndexTerm><Primary>tmp, running out of space in</Primary></IndexTerm>
2519
2520 The quickest way around it is <Command>setenv TMPDIR /usr/tmp</Command><IndexTerm><Primary>TMPDIR</Primary></IndexTerm> or
2521 even <Command>setenv TMPDIR .</Command> (or the equivalent incantation with your shell
2522 of choice).
2523
2524 The best way around it is to say
2525
2526 <ProgramListing>
2527 export TMPDIR=&#60;dir&#62;
2528 </ProgramListing>
2529
2530 in your <Filename>build.mk</Filename> file.
2531 Then GHC and the other <Literal>fptools</Literal> programs will use the appropriate directory
2532 in all cases.
2533
2534
2535 </Para>
2536 </ListItem>
2537 <ListItem>
2538
2539 <Para>
2540 In compiling some support-code bits, e.g., in <Filename>ghc/rts/gmp</Filename> and even
2541 in <Filename>ghc/lib</Filename>, you may get a few C-compiler warnings.  We think these
2542 are OK.
2543
2544 </Para>
2545 </ListItem>
2546 <ListItem>
2547
2548 <Para>
2549 When compiling via C, you'll sometimes get ``warning: assignment from
2550 incompatible pointer type'' out of GCC.  Harmless.
2551
2552 </Para>
2553 </ListItem>
2554 <ListItem>
2555
2556 <Para>
2557 Similarly, <Command>ar</Command>chiving warning messages like the following are not
2558 a problem:
2559
2560 <Screen>
2561 ar: filename GlaIOMonad__1_2s.o truncated to GlaIOMonad_
2562 ar: filename GlaIOMonad__2_2s.o truncated to GlaIOMonad_
2563 ...
2564 </Screen>
2565
2566
2567 </Para>
2568 </ListItem>
2569 <ListItem>
2570
2571 <Para>
2572  In compiling the compiler proper (in <Filename>compiler/</Filename>), you <Emphasis>may</Emphasis>
2573 get an ``Out of heap space'' error message.  These can vary with the
2574 vagaries of different systems, it seems.  The solution is simple:
2575
2576
2577 <ItemizedList>
2578 <ListItem>
2579
2580 <Para>
2581  If you're compiling with GHC 4.00 or above, then the
2582 <Emphasis>maximum</Emphasis> heap size must have been reached.  This is somewhat
2583 unlikely, since the maximum is set to 64M by default.  Anyway, you can
2584 raise it with the <Option>-optCrts-M&lt;size&gt;</Option> flag (add this flag to
2585 <Constant>&lt;module&gt;&lowbar;HC&lowbar;OPTS</Constant> <Command>make</Command> variable in the appropriate <Filename>Makefile</Filename>).
2586
2587 </Para>
2588 </ListItem>
2589 <ListItem>
2590
2591 <Para>
2592  For GHC &#60; 4.00, add a suitable <Option>-H</Option> flag to the <Filename>Makefile</Filename>, as
2593 above.
2594
2595 </Para>
2596 </ListItem>
2597
2598 </ItemizedList>
2599
2600
2601 and try again: <Command>gmake</Command>.  (see <Xref LinkEnd="sec-suffix"> for information about
2602 <Constant>&lt;module&gt;&lowbar;HC&lowbar;OPTS</Constant>.)
2603
2604 Alternatively, just cut to the chase:
2605
2606 <Screen>
2607 % cd ghc/compiler
2608 % make EXTRA_HC_OPTS=-optCrts-M128M
2609 </Screen>
2610
2611
2612 </Para>
2613 </ListItem>
2614 <ListItem>
2615
2616 <Para>
2617 If you try to compile some Haskell, and you get errors from GCC about
2618 lots of things from <Filename>/usr/include/math.h</Filename>, then your GCC was
2619 mis-installed.  <Command>fixincludes</Command> wasn't run when it should've been.
2620
2621 As <Command>fixincludes</Command> is now automagically run as part of GCC installation,
2622 this bug also suggests that you have an old GCC.
2623
2624
2625 </Para>
2626 </ListItem>
2627 <ListItem>
2628
2629 <Para>
2630 You <Emphasis>may</Emphasis> need to re-<Command>ranlib</Command><IndexTerm><Primary>ranlib</Primary></IndexTerm> your libraries (on Sun4s).
2631
2632
2633 <Screen>
2634 % cd $(libdir)/ghc-x.xx/sparc-sun-sunos4
2635 % foreach i ( `find . -name '*.a' -print` ) # or other-shell equiv...
2636 ?    ranlib $i
2637 ?    # or, on some machines: ar s $i
2638 ? end
2639 </Screen>
2640
2641
2642 We'd be interested to know if this is still necessary.
2643
2644
2645 </Para>
2646 </ListItem>
2647 <ListItem>
2648
2649 <Para>
2650 GHC's sources go through <Command>cpp</Command> before being compiled, and <Command>cpp</Command> varies
2651 a bit from one Unix to another.  One particular gotcha is macro calls
2652 like this:
2653
2654
2655 <ProgramListing>
2656 SLIT("Hello, world")
2657 </ProgramListing>
2658
2659
2660 Some <Command>cpp</Command>s treat the comma inside the string as separating two macro
2661 arguments, so you get
2662
2663
2664 <Screen>
2665 :731: macro `SLIT' used with too many (2) args
2666 </Screen>
2667
2668
2669 Alas, <Command>cpp</Command> doesn't tell you the offending file!
2670
2671 Workaround: don't put weird things in string args to <Command>cpp</Command> macros.
2672 </Para>
2673 </ListItem>
2674
2675 </OrderedList>
2676
2677 </Para>
2678
2679 </Sect1>
2680
2681
2682 <Sect1 id="winbuild"><Title>Notes for building under Windows</Title>
2683
2684 <Para>
2685 This section summarises how to get the utilities you need on your
2686 Win95/98/NT/2000 machine to use CVS and build GHC. Similar notes for installing and running GHC may be found in the user guide. In general, Win95/Win98 behave the same, and WinNT/Win2k behave the same. It is based largely on detailed advice from Sigbj&oslash;rn Finne.
2687 </Para>
2688
2689
2690 <Sect2><Title>Installing ssh</Title>
2691
2692 <ItemizedList>
2693
2694 <ListItem>
2695 <Para>
2696 Extract the whole of <ULink URL="http://research.microsoft.com/~simonpj/ssh-1_2_26-cygwinb19.tar.gz">the ssh archive</ULink> into your <Filename>C:\</Filename> directory, and use the ``All files'' and ``User folder names'' options in WinZip extract dialogue box. This populates your <Filename>C:\usr\local</Filename> tree.
2697 </Para>
2698 </ListItem>
2699
2700 <ListItem>
2701 <Para>
2702 Extract <ULink URL="http://research.microsoft.com/~simonpj/cygwinb19.dll.zip">cygwinb19.dll</ULink> into <Filename>/usr/local/bin</Filename>.  The current version
2703 of Cywin is b20, but this version of ssh was compiled with b19.
2704 </Para>
2705 </ListItem>
2706
2707 <ListItem>
2708 <Para>
2709 On a Win2k machine, open up a bash and do 
2710 </Para>
2711
2712 <Screen>
2713 foo$ cd /etc
2714 foo$ mkpasswd -l > passwd
2715 </Screen>
2716
2717 <Para>
2718 Check that your login entry is on the first line
2719 of that file. If not, move it to the top.  It's OK
2720 for 'Administrator' to be the first entry, assuming you are one.
2721 </Para>
2722
2723 <Para>
2724 However, Win9x doesn't support the calls that <Command>mkpasswd</Command> relies on
2725 (e.g., <Function>NetUserEnum</Function>). If you run <Command>mkpasswd</Command> you
2726 get errors like:
2727 </Para>
2728
2729 <Screen>
2730 linked to missing export netapi32.dll:NetUserEnum
2731 </Screen>
2732
2733 <Para>
2734 The passwd file is used
2735 by ssh in a fairly rudimentary manner, so I'd simply 
2736 synthesise/copy an existing Unix <Filename>/etc/passwd</Filename>, i.e., create
2737 an <Filename>/etc/passwd</Filename> file containing the line
2738 </Para>
2739
2740 <Screen>
2741 &lt;login&gt;::500:513:::/bin/sh
2742 </Screen>
2743
2744 <Para>
2745 where <Literal>&lt;login&gt;</Literal> is your login id.
2746 </Para>
2747 </ListItem>
2748
2749 <ListItem>
2750 <Para>
2751 Generate a key, by running <Filename>c:/user/local/bin/ssh-keygen1</Filename>.
2752   This generates a public key in <Filename>.ssh/identity.pub</Filename>, and a
2753   private key in <Filename>.ssh/identity</Filename>
2754 </Para>
2755
2756 <Para>
2757   In response to the 'Enter passphrase' question, just hit
2758   return (i.e. use an empty passphrase).  The passphrase is
2759   a password that protects your private key.  But it's a pain
2760   to type this passphrase everytime you use <Command>ssh</Command>, so the best
2761   thing to do is simply to protect your <Filename>.ssh</Filename> directory, and
2762   <Filename>.ssh/identity</Filename> from access by anyone else.  To do this 
2763   right-click your <Filename>.ssh</Filename> directory, and select Properties.
2764   If you are not on the access control list, add yourself, and
2765   give yourself full permissions (the second panel).  
2766   Remove everyone else from the access control list.  (Don't
2767   leave them there but deny them access, because 'they' may be
2768   a list that includes you!)
2769 </Para>
2770
2771 <Para>
2772   If you have problems running <Command>ssh-keygen1</Command>
2773   from within <Command>bash</Command>, start up <Filename>cmd.exe</Filename> and run it as follows:
2774 </Para>
2775
2776 <Screen>
2777 c:\tmp> set CYGWIN32=tty
2778 c:\tmp> c:/user/local/bin/ssh-keygen1
2779 </Screen>
2780 </ListItem>
2781
2782 <ListItem>
2783 <Para>
2784 If you don't have an account on <Literal>cvs.haskell.org</Literal>, send 
2785   your <Filename>.ssh/identity.pub</Filename> to the CVS repository administrator
2786   (currently Jeff Lewis <Email>jlewis@cse.ogi.edu</Email>).  He will set up
2787   your account.
2788 </Para>
2789
2790 <Para>
2791   If you do have an account on <Literal>cvs.haskell.org</Literal>, use TeraTerm
2792   to logon to it. Once in, copy the
2793   key that <Command>ssh-keygen1</Command> deposited in <Filename>/.ssh/identity.pub</Filename> into
2794   your <Filename>~/.ssh/authorized_keys</Filename>. Make sure that the new version
2795   of <Filename>authorized_keys</Filename> still has 600 file permission.
2796 </Para>
2797 </ListItem>
2798
2799 </ItemizedList>
2800
2801 </Sect2>
2802
2803
2804 <Sect2><Title>Installing CVS</Title>
2805
2806 <ItemizedList>
2807
2808 <ListItem>
2809 <Para>
2810 Unpack 
2811 <ULink URL="http://research.microsoft.com/~simonpj/cvs-1_10-win.zip">
2812 CVS</ULink> and, following the instructions in the <Filename>README</Filename>, copy the
2813 appropriate files into <Filename>/usr/local/bin</Filename>.
2814 </Para>
2815 </ListItem>
2816
2817 <ListItem>
2818 <Para>
2819 From the System control panel,
2820 set the following <Emphasis>user</Emphasis> environment variables (see the GHC user guide)
2821 </Para>
2822
2823 <ItemizedList>
2824 <ListItem>
2825 <Para>
2826 <Constant>HOME</Constant>: points to your home directory.  This is where CVS
2827 will look for its <Filename>.cvsrc</Filename> file.
2828 </Para>
2829 </ListItem>
2830
2831 <ListItem>
2832 <Para>
2833 <Constant>CVS_RSH</Constant>: <Filename>c:/usr/local/bin/ssh1</Filename>
2834 </Para>
2835 </ListItem>
2836
2837 <ListItem>
2838 <Para>
2839 <Constant>CVSROOT</Constant>: <Literal>:ext:username@cvs.haskell.org:/home/cvs/root</Literal>,
2840 where <Literal>username</Literal> is your userid
2841 </Para>
2842 </ListItem>
2843
2844 <ListItem>
2845 <Para>
2846 <Constant>CVSEDITOR</Constant>: <Filename>bin/gnuclient.exe</Filename> if you want to use an Emacs buffer for typing in those long commit messages.
2847 </Para>
2848 </ListItem>
2849 </ItemizedList>
2850 </ListItem>
2851
2852 <ListItem>
2853 <Para>
2854 Put the following in <Filename>$HOME/.cvsrc</Filename>:
2855 </Para>
2856
2857 <ProgramListing>
2858 checkout -P
2859 release -d
2860 update -P
2861 diff -u
2862 </ProgramListing>
2863
2864 <Para>
2865 These are the default options for the specified CVS commands,
2866 and represent better defaults than the usual ones.  (Feel
2867 free to change them.)
2868 </Para>
2869
2870 <Para>
2871 Filenames starting with "<Filename>.</Filename>" were illegal in 
2872 the 8.3 DOS filesystem, but that restriction should have
2873 been lifted by now (i.e., you're using VFAT or later filesystems.) If
2874 you're still having problems creating it, don't worry; <Filename>.cvsrc</Filename> is entirely
2875 optional.
2876 </Para>
2877 </ListItem>
2878
2879 <ListItem>
2880 <Para>
2881 Try doing <Command>cvs co fpconfig</Command>. All being well, bytes should
2882 start to trickle through, leaving a directory <Filename>fptools</Filename>
2883 in your current directory.  (You can <Command>rm</Command> it if you don't want to keep it.)  The following messages appear to be harmless:
2884 </Para>
2885
2886 <Screen>
2887 setsockopt IPTOS_LOWDELAY: Invalid argument
2888 setsockopt IPTOS_THROUGHPUT: Invalid argument
2889 </Screen>
2890
2891 <Para>
2892 At this point I found that CVS tried to invoke a little dialogue with
2893 me (along the lines of `do you want to talk to this host'), but
2894 somehow bombed out.  This was from a bash shell running in emacs.
2895 I solved this by invoking a Cygnus shell, and running CVS from there.
2896 Once things are dialogue free, it seems to work OK from within emacs.
2897 </Para>
2898 </ListItem>
2899
2900 <ListItem>
2901 <Para>
2902 If you want to check out part of large tree, proceed as follows:
2903 </Para>
2904
2905 <ProgramListing>
2906 cvs -f checkout -l papers
2907 cd papers
2908 cvs update cpr
2909 </ProgramListing>
2910
2911 <Para>
2912 This sequence checks out the <Literal>papers</Literal> module, but none
2913 of its sub-directories.
2914 The "<Option>-l</Option>" flag says not to check out sub-directories.
2915 The "<Option>-f</Option>" flag says not to read the <Filename>.cvsrc</Filename> file
2916 whose <Option>-P</Option> default (don't check out empty directories) is
2917 in this case bogus.
2918 </Para>
2919
2920 <Para>
2921 The <Command>cvs update</Command> command sucks in a named sub-directory.
2922 </Para>
2923 </ListItem>
2924
2925 </ItemizedList>
2926
2927 <Para>
2928 There is a very nice graphical front-end to CVS for Win32 platforms,
2929 with a UI that people will be familiar with, at 
2930 <ULink URL="http://www.wincvs.org/">wincvs.org</ULink>.
2931 I have not tried it yet.
2932 </Para>
2933
2934 </Sect2>
2935
2936
2937 <Sect2><Title>Installing autoconf</Title>
2938
2939 <Para>
2940 Only required if you are doing builds from GHC's sources
2941 checked out from the CVS tree.
2942 </Para>
2943
2944 <ItemizedList>
2945 <ListItem>
2946 <Para>
2947 Fetch the (standard, Unix) <Command>autoconf</Command> distribution from
2948 <ULink URL="ftp://ftp.gnu.org/gnu/autoconf">ftp.gnu.org</ULink>.
2949 </Para>
2950 </ListItem>
2951 <ListItem>
2952 <Para>
2953 Unpack it into an arbitrary directory.
2954 </Para>
2955 </ListItem>
2956 <ListItem>
2957 <Para>
2958 Make sure that the directory <Filename>/usr/local/bin</Filename> exists.
2959 </Para>
2960 </ListItem>
2961 <ListItem>
2962 <Para>
2963 Say "<Filename>./configure</Filename>".
2964 </Para>
2965 </ListItem>
2966 <ListItem>
2967 <Para>
2968 Now <Command>make install</Command>.  This should put <Filename>autoheader</Filename>
2969 and <Filename>autoconf</Filename> in <Filename>/usr/local/bin</Filename>.
2970 </Para>
2971 </ListItem>
2972 </ItemizedList>
2973
2974 <Para>
2975 <Command>autoheader</Command> doesn't seem to work, but you don't need it
2976 for GHC.
2977 </Para>
2978
2979 </Sect2>
2980
2981
2982 <Sect2><Title>Building GHC</Title>
2983
2984 <ItemizedList>
2985
2986 <ListItem>
2987 <Para>
2988 In the <Filename>./configure</Filename> output, ignore 
2989 "<Literal>
2990 checking whether #! works in shell scripts... 
2991 ./configure: ./conftest: No such file or directory</Literal>", 
2992 and "<Literal>not updating unwritable cache ./config.cache</Literal>".
2993 Nobody knows why these happen, but they seem to be harmless.
2994 </Para>
2995 </ListItem>
2996
2997 <ListItem>
2998 <Para>
2999 You have to run <Command>autoconf</Command> both in <Filename>fptools</Filename>
3000 and in <Filename>fptools/ghc</Filename>.  If you omit the latter step you'll
3001 get an error when you run <Filename>./configure</Filename>:
3002 </Para>
3003
3004 <Screen>
3005 ...lots of stuff...
3006 creating mk/config.h
3007 mk/config.h is unchanged
3008 configuring in ghc
3009 running /bin/sh ./configure  --cache-file=.././config.cache --srcdir=.
3010 ./configure: ./configure: No such file or directory
3011 configure: error: ./configure failed for ghc
3012 </Screen>
3013 </ListItem>
3014
3015 <ListItem>
3016 <Para>
3017 You need <Filename>ghc</Filename> to be in your <Constant>PATH</Constant> before you run
3018 <Command>configure</Command>.  The default GHC InstallShield creates only
3019 <Filename>ghc-4.05</Filename>, so you may need to duplicate this file as <Filename>ghc</Filename>
3020 in the same directory, in order that <Command>configure</Command> will see it (or
3021 just rename <Filename>ghc-4.05</Filename> to <Filename>ghc</Filename>.
3022 And make sure that the directory is in your path.
3023 </Para>
3024 </ListItem>
3025
3026 <ListItem>
3027 <Para>
3028 Compile <Command>happy</Command> and <Command>ghc</Command> 
3029 with <Option>-static</Option>.  To do this, set
3030 </Para>
3031
3032 <ProgramListing>
3033 GhcHcOpts=-static
3034 HappyHcOpts=-static
3035 </ProgramListing>
3036
3037 <Para>
3038 in your <Filename>build.mk</Filename> file.
3039 [Actually, I successfully compiled Happy without <Option>-static</Option> on Win2k, but not GHC.]
3040 </Para>
3041 </ListItem>
3042
3043 </ItemizedList>
3044
3045 </Sect2>
3046
3047 </Sect1>
3048
3049 </Article>