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