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