1 <!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
3 <Article id="building-guide">
7 <Title>Building the Glasgow Functional Programming Tools Suite</Title>
8 <Author><OtherName>The GHC Team</OtherName></Author>
9 <Address><Email>glasgow-haskell-{users,bugs}@haskell.org</Email></Address>
10 <PubDate>January 2000</PubDate>
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.
21 The bulk of this guide applies to building on Unix systems; see <XRef LinkEnd="winbuild"> for Windows notes.
29 <Sect1 id="sec-getting">
30 <Title>Getting the Glasgow <Literal>fptools</Literal> suite
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!
41 Happily, such complications don't apply to most people. A few common
42 ``strategies'' serve most purposes. Pick one and proceed
50 <Term><IndexTerm><Primary>Binary distribution</Primary></IndexTerm>Binary distribution.</Term>
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.
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
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.
74 </ListItem></VarListEntry>
76 <Term><IndexTerm><Primary>Source distribution</Primary></IndexTerm>Source distribution.</Term>
80 platform, but (a) you like the warm fuzzy feeling of compiling things
81 yourself; (b) you want to build something ``extra''—e.g., a set of
82 libraries with strictness-analysis turned off; or (c) you want to hack
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.
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.
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
111 </ListItem></VarListEntry>
113 <Term>Build GHC from intermediate C <Filename>.hc</Filename> files<IndexTerm><Primary>hc files</Primary></IndexTerm>:</Term>
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">.
125 Once you have built GHC, you can build the other Glasgow tools with
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).
134 </ListItem></VarListEntry>
136 <Term>The CVS repository.</Term>
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
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
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.
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 >.
163 </ListItem></VarListEntry>
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
175 <Sect1 id="sec-build-checks">
176 <Title>Things to check before you start typing</Title>
179 Here's a list of things to check before you get started.
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.)
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.
210 Be sure that the ``pre-supposed'' utilities are installed.
211 <Xref LinkEnd="sec-pre-supposed"> elaborates.
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
225 <IndexTerm><Primary>known bugs</Primary></IndexTerm>
226 <IndexTerm><Primary>bugs, known</Primary></IndexTerm>
228 If you feel there is still some shortcoming in our procedure or
229 instructions, please report it.
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>
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>
247 <Sect1 id="sec-port-info">
248 <Title>What machines the Glasgow tools run on
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
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>.
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.
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.
281 <Title>What platforms the Haskell compiler (GHC) runs on</Title>
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) Best is a native-code
289 generator; (b) next best is a ``registerised''
290 port; (c) the bare minimum is an ``unregisterised'' port.
291 (``Unregisterised'' is so terrible that we won't say more about it).
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.
300 We use Sparcs running Solaris 2.7 and x86 boxes running FreeBSD and
301 Linux, so those are the best supported platforms, unsurprisingly.
305 Here's everything that's known about GHC ports. We identify platforms
306 by their ``canonical'' CPU/Manufacturer/OS triple.
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>
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.
330 </ListItem></VarListEntry>
332 <Term>sparc-sun-sunos4:</Term>
333 <IndexTerm><Primary>sparc-sun-sunos4</Primary></IndexTerm>
337 Probably works with minor tweaks, hasn't been tested for a while.
340 </ListItem></VarListEntry>
342 <Term>sparc-sun-solaris2:</Term>
343 <IndexTerm><Primary>sparc-sun-solaris2</Primary></IndexTerm>
347 Fully supported, including native-code generator.
350 </ListItem></VarListEntry>
352 <Term>hppa1.1-hp-hpux (HP-PA boxes running HPUX 9.x)</Term>
353 <IndexTerm><Primary>hppa1.1-hp-hpux</Primary></IndexTerm>
357 Works registerised. No native-code generator.
360 </ListItem></VarListEntry>
362 <Term>i386-unknown-linux (PCs running Linux—ELF binary format):</Term>
363 <IndexTerm><Primary>i386-*-linux</Primary></IndexTerm>
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.
375 </ListItem></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>
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
390 </ListItem></VarListEntry>
392 <Term>i386-unknown-cygwin32:</Term>
393 <IndexTerm><Primary>i386-unknown-cygwin32</Primary></IndexTerm>
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
403 </ListItem></VarListEntry>
405 <Term>mips-sgi-irix5:</Term>
406 <IndexTerm><Primary>mips-sgi-irix[5-6]</Primary></IndexTerm>
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.
414 </ListItem></VarListEntry>
417 <Term>powerpc-ibm-aix:</Term>
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.
425 </ListItem></VarListEntry>
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
440 <Title>What machines the other tools run on</Title>
443 Unless you hear otherwise, the other tools work if GHC works.
451 <Sect1 id="sec-pre-supposed">
452 <Title>Installing pre-supposed utilities
454 <IndexTerm><Primary>pre-supposed utilities</Primary></IndexTerm>
455 <IndexTerm><Primary>utilities, pre-supposed</Primary></IndexTerm></Title>
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.
472 <IndexTerm><Primary>pre-supposed: Perl</Primary></IndexTerm>
473 <IndexTerm><Primary>Perl, pre-supposed</Primary></IndexTerm>
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.
482 Perl 5 is required. For Win32 platforms, we strongly suggest you
483 pick up a port of Perl 5 for <Literal>cygwin32</Literal>, as the
484 common Hip/ActiveWare port of Perl is Not Cool Enough for our
489 Perl should be put somewhere so that it can be invoked by the
490 <Literal>#!</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
497 </ListItem></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>
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.
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—you may need to fiddle with GHC's
516 <Option>-monly-N-regs</Option> option; see the User's Guide)
518 </ListItem></VarListEntry>
522 <indexterm><primary>Happy</primary></indexterm>
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>.
537 <Term>Autoconf:</Term>
538 <IndexTerm><Primary>pre-supposed: Autoconf</Primary></IndexTerm>
539 <IndexTerm><Primary>Autoconf, pre-supposed</Primary></IndexTerm>
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.
548 Autoconf builds the <Command>configure</Command> script from
549 <Filename>configure.in</Filename> and <Filename>aclocal.m4</Filename>.
550 If you modify either of these files, you'll need Autoconf to rebuild
551 <Filename>configure</Filename>.
554 </ListItem></VarListEntry>
556 <Term><Command>sed</Command></Term>
557 <IndexTerm><Primary>pre-supposed: sed</Primary></IndexTerm>
558 <IndexTerm><Primary>sed, pre-supposed</Primary></IndexTerm>
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.)
567 </ListItem></VarListEntry>
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.
579 <Sect2 id="pre-supposed-gph-tools">
580 <Title>Tools for building parallel GHC (GPH)
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>
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).
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>.
607 A PVM installation is slightly quirky, but easy to do. Just follow
608 the <Filename>Readme</Filename> instructions.
610 </ListItem></VarListEntry>
612 <Term><Command>bash</Command>:</Term>
613 <IndexTerm><Primary>bash, presupposed (Parallel Haskell only)</Primary></IndexTerm>
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).
620 </ListItem></VarListEntry>
626 <Sect2 id="pre-supposed-doc-tools">
627 <Title>Tools for building the Documentation
631 The following additional tools are required if you want to format the
632 documentation that comes with the <Literal>fptools</Literal> projects:
639 <Term>DocBook:</Term>
640 <IndexTerm><Primary>pre-supposed: DocBook</Primary></IndexTerm>
641 <IndexTerm><Primary>DocBook, pre-supposed</Primary></IndexTerm>
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).
649 </ListItem></VarListEntry>
652 <IndexTerm><Primary>pre-supposed: TeX</Primary></IndexTerm>
653 <IndexTerm><Primary>TeX, pre-supposed</Primary></IndexTerm>
656 A decent TeX distribution is required if you want to produce printable
657 documentation. We recomment teTeX, which includes just about
660 </ListItem></VarListEntry>
666 <Sect2 id="pre-supposed-other-tools">
667 <Title>Other useful tools
673 <IndexTerm><Primary>pre-supposed: flex</Primary></IndexTerm>
674 <IndexTerm><Primary>flex, pre-supposed</Primary></IndexTerm>
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.
683 </ListItem></VarListEntry>
690 <Sect1 id="sec-building-from-source">
691 <Title>Building from source
693 <IndexTerm><Primary>Building from source</Primary></IndexTerm>
694 <IndexTerm><Primary>Source, building from</Primary></IndexTerm></Title>
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
706 Gingerly, you type <Command>make</Command>. Wrong already!
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.
717 <Sect2 id="sec-source-tree">
718 <Title>Your source tree
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:
733 <Filename>Makefile</Filename>: the root Makefile.
739 <Filename>mk/</Filename>: the directory that contains the
740 main Makefile code, shared by all the
741 <Literal>fptools</Literal> software.
747 <Filename>configure.in</Filename>, <Filename>config.sub</Filename>, <Filename>config.guess</Filename>:
748 these files support the configuration process.
754 <Filename>install-sh</Filename>.
763 All the other directories are individual <Emphasis>projects</Emphasis> of the
764 <Literal>fptools</Literal> system—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.
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.
782 <IndexTerm><Primary>build trees</Primary></IndexTerm>
783 <IndexTerm><Primary>link trees, for building</Primary></IndexTerm></Title>
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
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>—check out <Filename>fptools/glafp-utils/lndir</Filename>). See <Xref LinkEnd="sec-storysofar"> for a typical invocation.
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—<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.
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!
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.)
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>$(FPTOOLS_TOP)</Constant><IndexTerm><Primary>FPTOOLS_TOP</Primary></IndexTerm>. In the rest of this document path
843 names are relative to <Constant>$(FPTOOLS_TOP)</Constant> unless otherwise stated. For
844 example, the file <Filename>ghc/mk/target.mk</Filename> is actually
845 <Filename><Constant>$(FPTOOLS_TOP)</Constant>/ghc/mk/target.mk</Filename>.
850 <Sect2 id="sec-build-config">
851 <Title>Getting the build you want
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
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)
875 All of this stuff is called the <Emphasis>configuration</Emphasis> of your build.
876 You set the configuration using a three-step process.
880 <Term>Step 1: get ready for configuration.</Term>
884 <Constant>$(FPTOOLS_TOP)</Constant> and issue the command <Command>autoconf</Command><IndexTerm><Primary>autoconf</Primary></IndexTerm> (with
885 no arguments). This GNU program converts <Filename><Constant>$(FPTOOLS_TOP)</Constant>/configure.in</Filename>
886 to a shell script called <Filename><Constant>$(FPTOOLS_TOP)</Constant>/configure</Filename>.
890 Some projects, including GHC, have their own configure script. If
892 <Constant>$(FPTOOLS_TOP)/<project>/configure.in</Constant>,
893 then you need to run <command>autoconf</command> in that directory too.
897 Both these steps are completely platform-independent; they just mean
898 that the human-written file (<Filename>configure.in</Filename>) can be short, although
899 the resulting shell script, <Command>configure</Command>, and <Filename>mk/config.h.in</Filename>, are
904 In case you don't have <Command>autoconf</Command> we distribute the results,
905 <Command>configure</Command>, and <Filename>mk/config.h.in</Filename>, with the source distribution. They
906 aren't kept in the repository, though.
908 </ListItem></VarListEntry>
910 <Term>Step 2: system configuration.</Term>
913 Runs the newly-created <Command>configure</Command> script, thus:
919 <Command>configure</Command>'s mission is to scurry round your
920 computer working out what architecture it has, what operating system,
921 whether it has the <Function>vfork</Function> system call, where
922 <Command>yacc</Command> is kept, whether <Command>gcc</Command> is
923 available, where various obscure <Literal>#include</Literal> files
924 are, whether it's a leap year, and what the systems manager had for
925 lunch. It communicates these snippets of information in two ways:
934 It translates <Filename>mk/config.mk.in</Filename><IndexTerm><Primary>config.mk.in</Primary></IndexTerm> to
935 <Filename>mk/config.mk</Filename><IndexTerm><Primary>config.mk</Primary></IndexTerm>, substituting for things between
936 ``<Literal>@</Literal>'' brackets. So, ``<Literal>@HaveGcc@</Literal>'' will be replaced by
937 ``<Literal>YES</Literal>'' or ``<Literal>NO</Literal>'' depending on what <Command>configure</Command> finds.
938 <Filename>mk/config.mk</Filename> is included by every Makefile (directly or indirectly),
939 so the configuration information is thereby communicated to all
947 It translates <Filename>mk/config.h.in</Filename><IndexTerm><Primary>config.h.in</Primary></IndexTerm> to
948 <Filename>mk/config.h</Filename><IndexTerm><Primary>config.h</Primary></IndexTerm>. The latter is <Literal>#include</Literal>d by various C
949 programs, which can thereby make use of configuration information.
959 <Command>configure</Command> caches the results of its run in <Filename>config.cache</Filename>. Quite
960 often you don't want that; you're running <Command>configure</Command> a second time
961 because something has changed. In that case, simply delete
962 <Filename>config.cache</Filename>.
964 </ListItem></VarListEntry>
966 <Term>Step 3: build configuration.</Term>
969 Next, you say how this build of <Literal>fptools</Literal> is to differ from the
970 standard defaults by creating a new file <Filename>mk/build.mk</Filename><IndexTerm><Primary>build.mk</Primary></IndexTerm>
971 <Emphasis>in the build tree</Emphasis>. This file is the one and only file you edit
972 in the build tree, precisely because it says how this build differs
973 from the source. (Just in case your build tree does die, you might
974 want to keep a private directory of <Filename>build.mk</Filename> files, and use a
975 symbolic link in each build tree to point to the appropriate one.) So
976 <Filename>mk/build.mk</Filename> never exists in the source tree—you create one in
977 each build tree from the template. We'll discuss what to put in it
980 </ListItem></VarListEntry>
985 And that's it for configuration. Simple, eh?
989 What do you put in your build-specific configuration file
990 <Filename>mk/build.mk</Filename>? <Emphasis>For almost all purposes all you will do is put
991 make variable definitions that override those in</Emphasis> <Filename>mk/config.mk.in</Filename>.
992 The whole point of <Filename>mk/config.mk.in</Filename>—and its derived counterpart
993 <Filename>mk/config.mk</Filename>—is to define the build configuration. It is heavily
994 commented, as you will see if you look at it. So generally, what you
995 do is look at <Filename>mk/config.mk.in</Filename>, and add definitions in <Filename>mk/build.mk</Filename>
996 that override any of the <Filename>config.mk</Filename> definitions that you want to
997 change. (The override occurs because the main boilerplate file,
998 <Filename>mk/boilerplate.mk</Filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm>, includes <Filename>build.mk</Filename> after
999 <Filename>config.mk</Filename>.)
1003 For example, <Filename>config.mk.in</Filename> contains the definition:
1009 ProjectsToBuild = glafp-utils ghc hslibs
1015 The accompanying comment explains that this is the list of enabled
1016 projects; that is, if (after configuring) you type <Command>gmake all</Command> in
1017 <Constant>FPTOOLS_TOP</Constant> three specified projects will be made. If you want to
1018 add <Command>green-card</Command>, you can add this line to <Filename>build.mk</Filename>:
1024 ProjectsToBuild += green-card
1036 ProjectsToBuild = glafp-utils ghc green-card
1042 (GNU <Command>make</Command> allows existing definitions to have new text appended
1043 using the ``<Literal>+=</Literal>'' operator, which is quite a convenient feature.)
1047 When reading <Filename>config.mk.in</Filename>, remember that anything between
1048 ``@...@'' signs is going to be substituted by <Command>configure</Command>
1049 later. You <Emphasis>can</Emphasis> override the resulting definition if you want,
1050 but you need to be a bit surer what you are doing. For example,
1051 there's a line that says:
1063 This defines the Make variables <Constant>YACC</Constant> to the pathname for a <Command>yacc</Command> that
1064 <Command>configure</Command> finds somewhere. If you have your own pet <Command>yacc</Command> you want
1065 to use instead, that's fine. Just add this line to <Filename>mk/build.mk</Filename>:
1077 You do not <Emphasis>have</Emphasis> to have a <Filename>mk/build.mk</Filename> file at all; if you
1078 don't, you'll get all the default settings from <Filename>mk/config.mk.in</Filename>.
1082 You can also use <Filename>build.mk</Filename> to override anything that <Command>configure</Command> got
1083 wrong. One place where this happens often is with the definition of
1084 <Constant>FPTOOLS_TOP_ABS</Constant>: this variable is supposed to be the canonical path
1085 to the top of your source tree, but if your system uses an automounter
1086 then the correct directory is hard to find automatically. If you find
1087 that <Command>configure</Command> has got it wrong, just put the correct definition in
1088 <Filename>build.mk</Filename>.
1093 <Sect2 id="sec-storysofar">
1094 <Title>The story so far</Title>
1097 Let's summarise the steps you need to carry to get yourself
1098 a fully-configured build tree from scratch.
1107 Get your source tree from somewhere (CVS repository or source
1108 distribution). Say you call the root directory <Filename>myfptools</Filename> (it
1109 does not have to be called <Filename>fptools</Filename>). Make sure that you have
1110 the essential files (see <XRef LinkEnd="sec-source-tree">).
1117 Use <Command>lndir</Command> or <Command>mkshadowdir</Command> to create a build tree.
1121 mkshadowdir . /scratch/joe-bloggs/myfptools-sun4
1124 (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
1125 suggests its main defining characteristic (in your mind at least),
1126 in case you later add others.
1133 Change directory to the build tree. Everything is going
1134 to happen there now.
1137 cd /scratch/joe-bloggs/myfptools-sun4
1145 Prepare for system configuration:
1151 (You can skip this step if you are starting from a source distribution,
1152 and you already have <Filename>configure</Filename> and <Filename>mk/config.h.in</Filename>.)
1159 Do system configuration:
1171 Create the file <Filename>mk/build.mk</Filename>,
1172 adding definitions for your desired configuration options.
1183 You can make subsequent changes to <Filename>mk/build.mk</Filename> as often
1184 as you like. You do not have to run any further configuration
1185 programs to make these changes take effect.
1186 In theory you should, however, say <Command>gmake clean</Command>, <Command>gmake all</Command>,
1187 because configuration option changes could affect anything—but in practice you are likely to know what's affected.
1193 <Title>Making things</Title>
1196 At this point you have made yourself a fully-configured build tree,
1197 so you are ready to start building real things.
1201 The first thing you need to know is that
1202 <Emphasis>you must use GNU <Command>make</Command>, usually called <Command>gmake</Command>, not standard Unix <Command>make</Command></Emphasis>.
1203 If you use standard Unix <Command>make</Command> you will get all sorts of error messages
1204 (but no damage) because the <Literal>fptools</Literal> <Command>Makefiles</Command> use GNU <Command>make</Command>'s facilities
1210 <Sect2 id="sec-standard-targets">
1211 <Title>Standard Targets
1213 <IndexTerm><Primary>targets, standard makefile</Primary></IndexTerm>
1214 <IndexTerm><Primary>makefile targets</Primary></IndexTerm></Title>
1217 In any directory you should be able to make the following:
1221 <Term><Literal>boot</Literal>:</Term>
1224 does the one-off preparation required to get ready for the real work.
1225 Notably, it does <Command>gmake depend</Command> in all directories that contain
1226 programs. It also builds the necessary tools for compilation to proceed.
1230 You should say <Command>gmake boot</Command> right after configuring your build tree,
1231 but note that this is a one-off, i.e., there's no need to re-do
1232 <Command>gmake boot</Command> if you should re-configure your build tree at a later
1233 stage (no harm caused if you do though).
1235 </ListItem></VarListEntry>
1237 <Term><Literal>all</Literal>:</Term>
1240 makes all the final target(s) for this Makefile.
1241 Depending on which directory you are in a ``final target'' may be an
1242 executable program, a library archive, a shell script, or a Postscript
1243 file. Typing <Command>gmake</Command> alone is generally the same as typing <Command>gmake all</Command>.
1245 </ListItem></VarListEntry>
1247 <Term><Literal>install</Literal>:</Term>
1250 installs the things built by <Literal>all</Literal>. Where does it
1251 install them? That is specified by
1252 <Filename>mk/config.mk.in</Filename>; you can override it in
1253 <Filename>mk/build.mk</Filename>, or by running
1254 <command>configure</command> with command-line arguments like
1255 <literal>--bindir=/home/simonpj/bin</literal>; see <literal>./configure
1256 --help</literal> for the full details.
1258 </ListItem></VarListEntry>
1260 <Term><Literal>uninstall</Literal>:</Term>
1263 reverses the effect of <Literal>install</Literal>.
1265 </ListItem></VarListEntry>
1268 <Term><Literal>clean</Literal>:</Term>
1271 Delete all files from the current directory that are normally
1272 created by building the program. Don't delete the files that
1273 record the configuration. Also preserve files that could be made
1274 by building, but normally aren't because the distribution comes
1276 </ListItem></VarListEntry>
1279 <term><literal>distclean</literal>:</term>
1281 <para>Delete all files from the current directory that are created by
1282 configuring or building the program. If you have unpacked the source
1283 and built the program without creating any other files, <literal>make
1284 distclean</literal> should leave only the files that were in the
1285 distribution.</para>
1290 <term><literal>mostlyclean</literal>:</term>
1292 <para>Like <literal>clean</literal>, but may refrain from deleting a
1293 few files that people normally don't want to recompile.</para>
1298 <Term><Literal>maintainer-clean</Literal>:</Term>
1301 Delete everything from the current directory that can be reconstructed
1302 with this Makefile. This typically includes everything deleted by
1303 <literal>distclean</literal>, plus more: C source files produced by
1304 Bison, tags tables, Info files, and so on.</para>
1306 <para>One exception, however: <literal>make maintainer-clean</literal>
1307 should not delete <filename>configure</filename> even if
1308 <filename>configure</filename> can be remade using a rule in the
1309 <filename>Makefile</filename>. More generally, <literal>make
1310 maintainer-clean</literal> should not delete anything that needs to
1311 exist in order to run <filename>configure</filename> and then begin to
1312 build the program.</para>
1317 <Term><Literal>check</Literal>:</Term>
1322 </ListItem></VarListEntry>
1327 All of these standard targets automatically recurse into
1328 sub-directories. Certain other standard targets do not:
1335 <Term><Literal>configure</Literal>:</Term>
1338 is only available in the root directory
1339 <Constant>$(FPTOOLS_TOP)</Constant>; it has been discussed in <XRef LinkEnd="sec-build-config">.
1341 </ListItem></VarListEntry>
1343 <Term><Literal>depend</Literal>:</Term>
1346 make a <Filename>.depend</Filename> file in each directory that needs
1347 it. This <Filename>.depend</Filename> file contains mechanically-generated dependency
1348 information; for example, suppose a directory contains a Haskell
1349 source module <Filename>Foo.lhs</Filename> which imports another module <Literal>Baz</Literal>.
1350 Then the generated <Filename>.depend</Filename> file will contain the dependency:
1362 which says that the object file <Filename>Foo.o</Filename> depends on the interface file
1363 <Filename>Baz.hi</Filename> generated by compiling module <Literal>Baz</Literal>. The <Filename>.depend</Filename> file is
1364 automatically included by every Makefile.
1366 </ListItem></VarListEntry>
1368 <Term><Literal>binary-dist</Literal>:</Term>
1371 make a binary distribution. This is the
1372 target we use to build the binary distributions of GHC and Happy.
1374 </ListItem></VarListEntry>
1376 <Term><Literal>dist</Literal>:</Term>
1379 make a source distribution. You must be in a
1380 linked build tree to make this target.
1382 </ListItem></VarListEntry>
1387 Most <Filename>Makefile</Filename>s have targets other than these. You can discover them by looking in the <Filename>Makefile</Filename> itself.
1393 <title>Using a project from the build tree</title>
1395 If you want to build GHC (say) and just use it direct from the build
1396 tree without doing <literal>make install</literal> first, you can run
1397 the in-place driver script:
1398 <filename>ghc/driver/ghc-inplace</filename>.
1401 <para> Do <emphasis>NOT</emphasis> use
1402 <filename>ghc/driver/ghc</filename>, or
1403 <filename>ghc/driver/ghc-4.xx</filename>, as these are the scripts
1404 intended for installation, and contain hard-wired paths to the
1405 installed libraries, rather than the libraries in the build tree.
1409 Happy can similarly be run from the build tree, using
1410 <filename>happy/src/happy-inplace</filename>.
1415 <Title>Fast Making <IndexTerm><Primary>fastmake</Primary></IndexTerm>
1416 <IndexTerm><Primary>dependencies, omitting</Primary></IndexTerm>
1417 <IndexTerm><Primary>FAST, makefile
1418 variable</Primary></IndexTerm></Title>
1421 Sometimes the dependencies get in the way: if you've made a small
1422 change to one file, and you're absolutely sure that it won't affect
1423 anything else, but you know that <Command>make</Command> is going to rebuild everything
1424 anyway, the following hack may be useful:
1436 This tells the make system to ignore dependencies and just build what
1437 you tell it to. In other words, it's equivalent to temporarily
1438 removing the <Filename>.depend</Filename> file in the current directory (where
1439 <Command>mkdependHS</Command> and friends store their dependency information).
1443 A bit of history: GHC used to come with a <Command>fastmake</Command> script that did
1444 the above job, but GNU make provides the features we need to do it
1445 without resorting to a script. Also, we've found that fastmaking is
1446 less useful since the advent of GHC's recompilation checker (see the
1447 User's Guide section on "Separate Compilation").
1454 <Sect1 id="sec-makefile-arch">
1455 <Title>The <Filename>Makefile</Filename> architecture
1456 <IndexTerm><Primary>makefile architecture</Primary></IndexTerm></Title>
1459 <Command>make</Command> is great if everything works—you type <Command>gmake install</Command> and
1460 lo! the right things get compiled and installed in the right places.
1461 Our goal is to make this happen often, but somehow it often doesn't;
1462 instead some weird error message eventually emerges from the bowels of
1463 a directory you didn't know existed.
1467 The purpose of this section is to give you a road-map to help you figure
1468 out what is going right and what is going wrong.
1472 <Title>A small project</Title>
1475 To get started, let us look at the <Filename>Makefile</Filename> for an imaginary small
1476 <Literal>fptools</Literal> project, <Literal>small</Literal>. Each project in <Literal>fptools</Literal> has its own
1477 directory in <Constant>FPTOOLS_TOP</Constant>, so the <Literal>small</Literal> project will have its own
1478 directory <Constant>FPOOLS_TOP/small/</Constant>. Inside the <Filename>small/</Filename> directory there
1479 will be a <Filename>Makefile</Filename>, looking something like this:
1483 <IndexTerm><Primary>Makefile, minimal</Primary></IndexTerm>
1486 # Makefile for fptools project "small"
1489 include $(TOP)/mk/boilerplate.mk
1491 SRCS = $(wildcard *.lhs) $(wildcard *.c)
1494 include $(TOP)/target.mk
1500 This <Filename>Makefile</Filename> has three sections:
1509 The first section includes
1513 One of the most important
1514 features of GNU <Command>make</Command> that we use is the ability for a <Filename>Makefile</Filename> to
1515 include another named file, very like <Command>cpp</Command>'s <Literal>#include</Literal>
1520 a file of ``boilerplate'' code from the level
1521 above (which in this case will be
1522 <Filename><Constant>FPTOOLS_TOP</Constant>/mk/boilerplate.mk</Filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm>). As its name
1523 suggests, <Filename>boilerplate.mk</Filename> consists of a large quantity of standard
1524 <Filename>Makefile</Filename> code. We discuss this boilerplate in more detail in
1525 <XRef LinkEnd="sec-boiler">.
1526 <IndexTerm><Primary>include, directive in Makefiles</Primary></IndexTerm>
1527 <IndexTerm><Primary>Makefile inclusion</Primary></IndexTerm>
1529 Before the <Literal>include</Literal> statement, you must define the <Command>make</Command> variable
1530 <Constant>TOP</Constant><IndexTerm><Primary>TOP</Primary></IndexTerm> to be the directory containing the <Filename>mk</Filename> directory in
1531 which the <Filename>boilerplate.mk</Filename> file is. It is <Emphasis>not</Emphasis> OK to simply say
1535 include ../mk/boilerplate.mk # NO NO NO
1539 Why? Because the <Filename>boilerplate.mk</Filename> file needs to know where it is, so
1540 that it can, in turn, <Literal>include</Literal> other files. (Unfortunately, when an
1541 <Literal>include</Literal>d file does an <Literal>include</Literal>, the filename is treated relative to
1542 the directory in which <Command>gmake</Command> is being run, not the directory in
1543 which the <Literal>include</Literal>d sits.) In general, <Emphasis>every file <Filename>foo.mk</Filename>
1544 assumes that <Filename><Constant>$(TOP)</Constant>/mk/foo.mk</Filename> refers to itself.</Emphasis> It is up to the
1545 <Filename>Makefile</Filename> doing the <Literal>include</Literal> to ensure this is the case.
1547 Files intended for inclusion in other <Filename>Makefile</Filename>s are written to have
1548 the following property: <Emphasis>after <Filename>foo.mk</Filename> is <Literal>include</Literal>d, it leaves
1549 <Constant>TOP</Constant> containing the same value as it had just before the <Literal>include</Literal>
1550 statement</Emphasis>. In our example, this invariant guarantees that the
1551 <Literal>include</Literal> for <Filename>target.mk</Filename> will look in the same directory as that for
1552 <Filename>boilerplate.mk</Filename>.
1559 The second section defines the following standard <Command>make</Command>
1560 variables: <Constant>SRCS</Constant><IndexTerm><Primary>SRCS</Primary></IndexTerm> (the source files from which is to be
1561 built), and <Constant>HS_PROG</Constant><IndexTerm><Primary>HS_PROG</Primary></IndexTerm> (the executable binary to be
1562 built). We will discuss in more detail what the ``standard
1563 variables'' are, and how they affect what happens, in <XRef LinkEnd="sec-targets">.
1565 The definition for <Constant>SRCS</Constant> uses the useful GNU <Command>make</Command> construct
1566 <Literal>$(wildcard $pat$)</Literal><IndexTerm><Primary>wildcard</Primary></IndexTerm>, which expands to a list of all
1567 the files matching the pattern <Literal>pat</Literal> in the current directory. In
1568 this example, <Constant>SRCS</Constant> is set to the list of all the <Filename>.lhs</Filename> and <Filename>.c</Filename>
1569 files in the directory. (Let's suppose there is one of each,
1570 <Filename>Foo.lhs</Filename> and <Filename>Baz.c</Filename>.)
1577 The last section includes a second file of standard code,
1578 called <Filename>target.mk</Filename><IndexTerm><Primary>target.mk</Primary></IndexTerm>. It contains the rules that tell
1579 <Command>gmake</Command> how to make the standard targets (<Xref LinkEnd="sec-standard-targets">). Why, you ask,
1580 can't this standard code be part of <Filename>boilerplate.mk</Filename>? Good question.
1581 We discuss the reason later, in <Xref LinkEnd="sec-boiler-arch">.
1583 You do not <Emphasis>have</Emphasis> to <Literal>include</Literal> the <Filename>target.mk</Filename> file. Instead, you
1584 can write rules of your own for all the standard targets. Usually,
1585 though, you will find quite a big payoff from using the canned rules
1586 in <Filename>target.mk</Filename>; the price tag is that you have to understand what
1587 canned rules get enabled, and what they do (<Xref LinkEnd="sec-targets">).
1597 In our example <Filename>Makefile</Filename>, most of the work is done by the two
1598 <Literal>include</Literal>d files. When you say <Command>gmake all</Command>, the following things
1608 <Command>gmake</Command> figures out that the object files are <Filename>Foo.o</Filename> and
1609 <Filename>Baz.o</Filename>.
1616 It uses a boilerplate pattern rule to compile <Filename>Foo.lhs</Filename> to
1617 <Filename>Foo.o</Filename> using a Haskell compiler. (Which one? That is set in the
1618 build configuration.)
1625 It uses another standard pattern rule to compile <Filename>Baz.c</Filename> to
1626 <Filename>Baz.o</Filename>, using a C compiler. (Ditto.)
1633 It links the resulting <Filename>.o</Filename> files together to make <Literal>small</Literal>,
1634 using the Haskell compiler to do the link step. (Why not use <Command>ld</Command>?
1635 Because the Haskell compiler knows what standard libraries to link in.
1636 How did <Command>gmake</Command> know to use the Haskell compiler to do the link,
1637 rather than the C compiler? Because we set the variable <Constant>HS_PROG</Constant>
1638 rather than <Constant>C_PROG</Constant>.)
1648 All <Filename>Makefile</Filename>s should follow the above three-section format.
1654 <Title>A larger project</Title>
1657 Larger projects are usually structured into a number of sub-directories,
1658 each of which has its own <Filename>Makefile</Filename>. (In very large projects, this
1659 sub-structure might be iterated recursively, though that is rare.)
1660 To give you the idea, here's part of the directory structure for
1661 the (rather large) GHC project:
1674 ...source files for documentation...
1677 ...source files for driver...
1680 parser/...source files for parser...
1681 renamer/...source files for renamer...
1688 The sub-directories <Filename>docs</Filename>, <Filename>driver</Filename>, <Filename>compiler</Filename>, and so on, each
1689 contains a sub-component of GHC, and each has its own <Filename>Makefile</Filename>.
1690 There must also be a <Filename>Makefile</Filename> in <Filename><Constant>$(FPTOOLS_TOP)</Constant>/ghc</Filename>. It does most
1691 of its work by recursively invoking <Command>gmake</Command> on the <Filename>Makefile</Filename>s in the
1692 sub-directories. We say that <Filename>ghc/Makefile</Filename> is a <Emphasis>non-leaf
1693 <Filename>Makefile</Filename></Emphasis>, because it does little except organise its children,
1694 while the <Filename>Makefile</Filename>s in the sub-directories are all <Emphasis>leaf
1695 <Filename>Makefile</Filename>s</Emphasis>. (In principle the sub-directories might themselves
1696 contain a non-leaf <Filename>Makefile</Filename> and several sub-sub-directories, but
1697 that does not happen in GHC.)
1701 The <Filename>Makefile</Filename> in <Filename>ghc/compiler</Filename> is considered a leaf <Filename>Makefile</Filename> even
1702 though the <Filename>ghc/compiler</Filename> has sub-directories, because these sub-directories
1703 do not themselves have <Filename>Makefile</Filename>s in them. They are just used to structure
1704 the collection of modules that make up GHC, but all are managed by the
1705 single <Filename>Makefile</Filename> in <Filename>ghc/compiler</Filename>.
1709 You will notice that <Filename>ghc/</Filename> also contains a directory <Filename>ghc/mk/</Filename>. It
1710 contains GHC-specific <Filename>Makefile</Filename> boilerplate code. More precisely:
1719 <Filename>ghc/mk/boilerplate.mk</Filename> is included at the top of
1720 <Filename>ghc/Makefile</Filename>, and of all the leaf <Filename>Makefile</Filename>s in the
1721 sub-directories. It in turn <Literal>include</Literal>s the main boilerplate file
1722 <Filename>mk/boilerplate.mk</Filename>.
1730 <Filename>ghc/mk/target.mk</Filename> is <Literal>include</Literal>d at the bottom of
1731 <Filename>ghc/Makefile</Filename>, and of all the leaf <Filename>Makefile</Filename>s in the
1732 sub-directories. It in turn <Literal>include</Literal>s the file <Filename>mk/target.mk</Filename>.
1742 So these two files are the place to look for GHC-wide customisation
1743 of the standard boilerplate.
1748 <Sect2 id="sec-boiler-arch">
1749 <Title>Boilerplate architecture
1750 <IndexTerm><Primary>boilerplate architecture</Primary></IndexTerm>
1754 Every <Filename>Makefile</Filename> includes a <Filename>boilerplate.mk</Filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm> file
1755 at the top, and <Filename>target.mk</Filename><IndexTerm><Primary>target.mk</Primary></IndexTerm> file at the bottom. In
1756 this section we discuss what is in these files, and why there have to
1757 be two of them. In general:
1766 <Filename>boilerplate.mk</Filename> consists of:
1772 <Emphasis>Definitions of millions of <Command>make</Command> variables</Emphasis> that
1773 collectively specify the build configuration. Examples:
1774 <Constant>HC_OPTS</Constant><IndexTerm><Primary>HC_OPTS</Primary></IndexTerm>, the options to feed to the Haskell compiler;
1775 <Constant>NoFibSubDirs</Constant><IndexTerm><Primary>NoFibSubDirs</Primary></IndexTerm>, the sub-directories to enable within the
1776 <Literal>nofib</Literal> project; <Constant>GhcWithHc</Constant><IndexTerm><Primary>GhcWithHc</Primary></IndexTerm>, the name of the Haskell
1777 compiler to use when compiling GHC in the <Literal>ghc</Literal> project.
1783 <Emphasis>Standard pattern rules</Emphasis> that tell <Command>gmake</Command> how to construct one
1791 <Filename>boilerplate.mk</Filename> needs to be <Literal>include</Literal>d at the <Emphasis>top</Emphasis>
1792 of each <Filename>Makefile</Filename>, so that the user can replace the
1793 boilerplate definitions or pattern rules by simply giving a new
1794 definition or pattern rule in the <Filename>Makefile</Filename>. <Command>gmake</Command>
1795 simply takes the last definition as the definitive one.
1797 Instead of <Emphasis>replacing</Emphasis> boilerplate definitions, it is also quite
1798 common to <Emphasis>augment</Emphasis> them. For example, a <Filename>Makefile</Filename> might say:
1806 thereby adding ``<Option>-O</Option>'' to the end of <Constant>SRC_HC_OPTS</Constant><IndexTerm><Primary>SRC_HC_OPTS</Primary></IndexTerm>.
1813 <Filename>target.mk</Filename> contains <Command>make</Command> rules for the standard
1814 targets described in <Xref LinkEnd="sec-standard-targets">. These rules are selectively included,
1815 depending on the setting of certain <Command>make</Command> variables. These
1816 variables are usually set in the middle section of the
1817 <Filename>Makefile</Filename> between the two <Literal>include</Literal>s.
1819 <Filename>target.mk</Filename> must be included at the end (rather than being part of
1820 <Filename>boilerplate.mk</Filename>) for several tiresome reasons:
1827 <Command>gmake</Command> commits target and dependency lists earlier than
1828 it should. For example, <FIlename>target.mk</FIlename> has a rule that looks like
1833 $(HS_PROG) : $(OBJS)
1834 $(HC) $(LD_OPTS) $< -o $@
1838 If this rule was in <Filename>boilerplate.mk</Filename> then <Constant>$(HS_PROG)</Constant><IndexTerm><Primary>HS_PROG</Primary></IndexTerm>
1839 and <Constant>$(OBJS)</Constant><IndexTerm><Primary>OBJS</Primary></IndexTerm> would not have their final values at the
1840 moment <Command>gmake</Command> encountered the rule. Alas, <Command>gmake</Command> takes a snapshot
1841 of their current values, and wires that snapshot into the rule. (In
1842 contrast, the commands executed when the rule ``fires'' are only
1843 substituted at the moment of firing.) So, the rule must follow the
1844 definitions given in the <Filename>Makefile</Filename> itself.
1851 Unlike pattern rules, ordinary rules cannot be overriden or
1852 replaced by subsequent rules for the same target (at least, not without an
1853 error message). Including ordinary rules in <Filename>boilerplate.mk</Filename> would
1854 prevent the user from writing rules for specific targets in specific cases.
1861 There are a couple of other reasons I've forgotten, but it doesn't
1877 <Sect2 id="sec-boiler">
1878 <Title>The main <Filename>mk/boilerplate.mk</Filename> file
1880 <IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm></Title>
1883 If you look at <Filename><Constant>$(FPTOOLS_TOP)</Constant>/mk/boilerplate.mk</Filename> you will find
1884 that it consists of the following sections, each held in a separate
1892 <Term><Filename>config.mk</Filename><IndexTerm><Primary>config.mk</Primary></IndexTerm></Term>
1895 is the build configuration file we
1896 discussed at length in <Xref LinkEnd="sec-build-config">.
1898 </ListItem></VarListEntry>
1900 <Term><Filename>paths.mk</Filename><IndexTerm><Primary>paths.mk</Primary></IndexTerm></Term>
1903 defines <Command>make</Command> variables for
1904 pathnames and file lists. In particular, it gives definitions for:
1911 <Term><Constant>SRCS</Constant><IndexTerm><Primary>SRCS</Primary></IndexTerm>:</Term>
1914 all source files in the current directory.
1916 </ListItem></VarListEntry>
1918 <Term><Constant>HS_SRCS</Constant><IndexTerm><Primary>HS_SRCS</Primary></IndexTerm>:</Term>
1921 all Haskell source files in the current directory.
1922 It is derived from <Constant>$(SRCS)</Constant>, so if you override <Constant>SRCS</Constant> with a new value
1923 <Constant>HS_SRCS</Constant> will follow suit.
1925 </ListItem></VarListEntry>
1927 <Term><Constant>C_SRCS</Constant><IndexTerm><Primary>C_SRCS</Primary></IndexTerm>:</Term>
1930 similarly for C source files.
1932 </ListItem></VarListEntry>
1934 <Term><Constant>HS_OBJS</Constant><IndexTerm><Primary>HS_OBJS</Primary></IndexTerm>:</Term>
1937 the <Filename>.o</Filename> files derived from <Constant>$(HS_SRCS)</Constant>.
1939 </ListItem></VarListEntry>
1941 <Term><Constant>C_OBJS</Constant><IndexTerm><Primary>C_OBJS</Primary></IndexTerm>:</Term>
1944 similarly for <Constant>$(C_SRCS)</Constant>.
1946 </ListItem></VarListEntry>
1948 <Term><Constant>OBJS</Constant><IndexTerm><Primary>OBJS</Primary></IndexTerm>:</Term>
1951 the concatenation of <Constant>$(HS_OBJS)</Constant> and <Constant>$(C_OBJS)</Constant>.
1953 </ListItem></VarListEntry>
1958 Any or all of these definitions can easily be overriden by giving new
1959 definitions in your <Filename>Makefile</Filename>. For example, if there are things in
1960 the current directory that look like source files but aren't, then
1961 you'll need to set <Constant>SRCS</Constant> manually in your <Filename>Makefile</Filename>. The other
1962 definitions will then work from this new definition.
1966 What, exactly, does <Filename>paths.mk</Filename> consider a ``source file'' to be? It's
1967 based on the file's suffix (e.g. <Filename>.hs</Filename>, <Filename>.lhs</Filename>, <Filename>.c</Filename>, <Filename>.lc</Filename>, etc), but
1968 this is the kind of detail that changes, so rather than
1969 enumerate the source suffices here the best thing to do is to look in
1970 <Filename>paths.mk</Filename>.
1972 </ListItem></VarListEntry>
1974 <Term><Filename>opts.mk</Filename><IndexTerm><Primary>opts.mk</Primary></IndexTerm></Term>
1977 defines <Command>make</Command> variables for option
1978 strings to pass to each program. For example, it defines
1979 <Constant>HC_OPTS</Constant><IndexTerm><Primary>HC_OPTS</Primary></IndexTerm>, the option strings to pass to the Haskell
1980 compiler. See <Xref LinkEnd="sec-suffix">.
1982 </ListItem></VarListEntry>
1984 <Term><Filename>suffix.mk</Filename><IndexTerm><Primary>suffix.mk</Primary></IndexTerm></Term>
1987 defines standard pattern rules—see <Xref LinkEnd="sec-suffix">.
1989 </ListItem></VarListEntry>
1994 Any of the variables and pattern rules defined by the boilerplate file
1995 can easily be overridden in any particular <Filename>Makefile</Filename>, because the
1996 boilerplate <Literal>include</Literal> comes first. Definitions after this <Literal>include</Literal>
1997 directive simply override the default ones in <Filename>boilerplate.mk</Filename>.
2002 <Sect2 id="sec-suffix">
2003 <Title>Pattern rules and options
2005 <IndexTerm><Primary>Pattern rules</Primary></IndexTerm></Title>
2008 The file <Filename>suffix.mk</Filename><IndexTerm><Primary>suffix.mk</Primary></IndexTerm> defines standard <Emphasis>pattern
2009 rules</Emphasis> that say how to build one kind of file from another, for
2010 example, how to build a <Filename>.o</Filename> file from a <Filename>.c</Filename> file. (GNU <Command>make</Command>'s
2011 <Emphasis>pattern rules</Emphasis> are more powerful and easier to use than Unix
2012 <Command>make</Command>'s <Emphasis>suffix rules</Emphasis>.)
2016 Almost all the rules look something like this:
2024 $(CC) $(CC_OPTS) -c $< -o $@
2030 Here's how to understand the rule. It says that
2031 <Emphasis>something</Emphasis><Filename>.o</Filename> (say <Filename>Foo.o</Filename>) can be built from
2032 <Emphasis>something</Emphasis><Filename>.c</Filename> (<Filename>Foo.c</Filename>), by invoking the C compiler
2033 (path name held in <Constant>$(CC)</Constant>), passing to it the options
2034 <Constant>$(CC_OPTS)</Constant> and the rule's dependent file of the rule
2035 <Literal>$<</Literal> (<Filename>Foo.c</Filename> in this case), and putting the result in
2036 the rule's target <Literal>$@</Literal> (<Filename>Foo.o</Filename> in this case).
2040 Every program is held in a <Command>make</Command> variable defined in
2041 <Filename>mk/config.mk</Filename>—look in <Filename>mk/config.mk</Filename> for the
2042 complete list. One important one is the Haskell compiler, which is
2043 called <Constant>$(HC)</Constant>.
2047 Every program's options are are held in a <Command>make</Command> variables called
2048 <Constant><prog>_OPTS</Constant>. the <Constant><prog>_OPTS</Constant> variables are defined in
2049 <Filename>mk/opts.mk</Filename>. Almost all of them are defined like this:
2055 CC_OPTS = $(SRC_CC_OPTS) $(WAY$(_way)_CC_OPTS) $($*_CC_OPTS) $(EXTRA_CC_OPTS)
2061 The four variables from which <Constant>CC_OPTS</Constant> is built have the following meaning:
2068 <Term><Constant>SRC_CC_OPTS</Constant><IndexTerm><Primary>SRC_CC_OPTS</Primary></IndexTerm>:</Term>
2071 options passed to all C
2074 </ListItem></VarListEntry>
2076 <Term><Constant>WAY_<way>_CC_OPTS</Constant>:</Term>
2080 compilations for way <Literal><way></Literal>. For example,
2081 <Constant>WAY_mp_CC_OPTS</Constant> gives options to pass to the C compiler when
2082 compiling way <Literal>mp</Literal>. The variable <Constant>WAY_CC_OPTS</Constant> holds
2083 options to pass to the C compiler when compiling the standard way.
2084 (<Xref LinkEnd="sec-ways"> dicusses multi-way
2087 </ListItem></VarListEntry>
2089 <Term><Constant><module>_CC_OPTS</Constant>:</Term>
2093 pass to the C compiler that are specific to module <Literal><module></Literal>. For example, <Constant>SMap_CC_OPTS</Constant> gives the specific options
2094 to pass to the C compiler when compiling <Filename>SMap.c</Filename>.
2096 </ListItem></VarListEntry>
2098 <Term><Constant>EXTRA_CC_OPTS</Constant><IndexTerm><Primary>EXTRA_CC_OPTS</Primary></IndexTerm>:</Term>
2101 extra options to pass to all
2102 C compilations. This is intended for command line use, thus:
2108 gmake libHS.a EXTRA_CC_OPTS="-v"
2112 </ListItem></VarListEntry>
2118 <Sect2 id="sec-targets">
2119 <Title>The main <Filename>mk/target.mk</Filename> file
2121 <IndexTerm><Primary>target.mk</Primary></IndexTerm></Title>
2124 <Filename>target.mk</Filename> contains canned rules for all the standard targets
2125 described in <Xref LinkEnd="sec-standard-targets">. It is complicated by the fact that you don't want all of
2126 these rules to be active in every <Filename>Makefile</Filename>. Rather than have a
2127 plethora of tiny files which you can include selectively, there is a
2128 single file, <Filename>target.mk</Filename>, which selectively includes rules based on
2129 whether you have defined certain variables in your <Filename>Makefile</Filename>. This
2130 section explains what rules you get, what variables control them, and
2131 what the rules do. Hopefully, you will also get enough of an idea of
2132 what is supposed to happen that you can read and understand any weird
2133 special cases yourself.
2140 <Term><Constant>HS_PROG</Constant><IndexTerm><Primary>HS_PROG</Primary></IndexTerm>.</Term>
2143 If <Constant>HS_PROG</Constant> is defined, you get
2144 rules with the following targets:
2148 <Term><Filename>HS_PROG</Filename><IndexTerm><Primary>HS_PROG</Primary></IndexTerm></Term>
2151 itself. This rule links <Constant>$(OBJS)</Constant>
2152 with the Haskell runtime system to get an executable called
2153 <Constant>$(HS_PROG)</Constant>.
2155 </ListItem></VarListEntry>
2157 <Term><Literal>install</Literal><IndexTerm><Primary>install</Primary></IndexTerm></Term>
2160 installs <Constant>$(HS_PROG)</Constant>
2161 in <Constant>$(bindir)</Constant>.
2163 </ListItem></VarListEntry>
2166 </ListItem></VarListEntry>
2168 <Term><Constant>C_PROG</Constant><IndexTerm><Primary>C_PROG</Primary></IndexTerm></Term>
2171 is similar to <Constant>HS_PROG</Constant>, except that
2172 the link step links <Constant>$(C_OBJS)</Constant> with the C runtime system.
2174 </ListItem></VarListEntry>
2176 <Term><Constant>LIBRARY</Constant><IndexTerm><Primary>LIBRARY</Primary></IndexTerm></Term>
2179 is similar to <Constant>HS_PROG</Constant>, except that
2180 it links <Constant>$(LIB_OBJS)</Constant> to make the library archive <Constant>$(LIBRARY)</Constant>, and
2181 <Literal>install</Literal> installs it in <Constant>$(libdir)</Constant>.
2183 </ListItem></VarListEntry>
2185 <Term><Constant>LIB_DATA</Constant><IndexTerm><Primary>LIB_DATA</Primary></IndexTerm></Term>
2190 </ListItem></VarListEntry>
2192 <Term><Constant>LIB_EXEC</Constant><IndexTerm><Primary>LIB_EXEC</Primary></IndexTerm></Term>
2197 </ListItem></VarListEntry>
2199 <Term><Constant>HS_SRCS</Constant><IndexTerm><Primary>HS_SRCS</Primary></IndexTerm>, <Constant>C_SRCS</Constant><IndexTerm><Primary>C_SRCS</Primary></IndexTerm>.</Term>
2202 If <Constant>HS_SRCS</Constant>
2203 is defined and non-empty, a rule for the target <Literal>depend</Literal> is included,
2204 which generates dependency information for Haskell programs.
2205 Similarly for <Constant>C_SRCS</Constant>.
2207 </ListItem></VarListEntry>
2212 All of these rules are ``double-colon'' rules, thus
2218 install :: $(HS_PROG)
2219 ...how to install it...
2225 GNU <Command>make</Command> treats double-colon rules as separate entities. If there
2226 are several double-colon rules for the same target it takes each in
2227 turn and fires it if its dependencies say to do so. This means that
2228 you can, for example, define both <Constant>HS_PROG</Constant> and <Constant>LIBRARY</Constant>, which will
2229 generate two rules for <Literal>install</Literal>. When you type <Command>gmake install</Command> both
2230 rules will be fired, and both the program and the library will be
2231 installed, just as you wanted.
2236 <Sect2 id="sec-subdirs">
2239 <IndexTerm><Primary>recursion, in makefiles</Primary></IndexTerm>
2240 <IndexTerm><Primary>Makefile, recursing into subdirectories</Primary></IndexTerm></Title>
2243 In leaf <Filename>Makefile</Filename>s the variable <Constant>SUBDIRS</Constant><IndexTerm><Primary>SUBDIRS</Primary></IndexTerm> is undefined.
2244 In non-leaf <Filename>Makefile</Filename>s, <Constant>SUBDIRS</Constant> is set to the list of
2245 sub-directories that contain subordinate <Filename>Makefile</Filename>s. <Emphasis>It is up to
2246 you to set <Constant>SUBDIRS</Constant> in the <Filename>Makefile</Filename>.</Emphasis> There is no automation here—<Constant>SUBDIRS</Constant> is too important to automate.
2250 When <Constant>SUBDIRS</Constant> is defined, <Filename>target.mk</Filename> includes a rather
2251 neat rule for the standard targets (<Xref LinkEnd="sec-standard-targets"> that simply invokes
2252 <Command>make</Command> recursively in each of the sub-directories.
2256 <Emphasis>These recursive invocations are guaranteed to occur in the order
2257 in which the list of directories is specified in <Constant>SUBDIRS</Constant>. </Emphasis>This
2258 guarantee can be important. For example, when you say <Command>gmake boot</Command> it
2259 can be important that the recursive invocation of <Command>make boot</Command> is done
2260 in one sub-directory (the include files, say) before another (the
2261 source files). Generally, put the most independent sub-directory
2262 first, and the most dependent last.
2267 <Sect2 id="sec-ways">
2268 <Title>Way management
2270 <IndexTerm><Primary>way management</Primary></IndexTerm></Title>
2273 We sometimes want to build essentially the same system in several
2274 different ``ways''. For example, we want to build GHC's <Literal>Prelude</Literal>
2275 libraries with and without profiling, with and without concurrency,
2276 and so on, so that there is an appropriately-built library archive to
2277 link with when the user compiles his program. It would be possible to
2278 have a completely separate build tree for each such ``way'', but it
2279 would be horribly bureaucratic, especially since often only parts of
2280 the build tree need to be constructed in multiple ways.
2284 Instead, the <Filename>target.mk</Filename><IndexTerm><Primary>target.mk</Primary></IndexTerm> contains some clever magic to
2285 allow you to build several versions of a system; and to control
2286 locally how many versions are built and how they differ. This section
2291 The files for a particular way are distinguished by munging the
2292 suffix. The ``normal way'' is always built, and its files have the
2293 standard suffices <Filename>.o</Filename>, <Filename>.hi</Filename>, and so on. In addition, you can build
2294 one or more extra ways, each distinguished by a <Emphasis>way tag</Emphasis>. The
2295 object files and interface files for one of these extra ways are
2296 distinguished by their suffix. For example, way <Literal>mp</Literal> has files
2297 <Filename>.mp_o</Filename> and <Filename>.mp_hi</Filename>. Library archives have their way tag the other
2298 side of the dot, for boring reasons; thus, <Filename>libHS_mp.a</Filename>.
2302 A <Command>make</Command> variable called <Constant>way</Constant> holds the current way tag. <Emphasis><Constant>way</Constant>
2303 is only ever set on the command line of a recursive invocation of
2304 <Command>gmake</Command>.</Emphasis> It is never set inside a <Filename>Makefile</Filename>. So it is a global
2305 constant for any one invocation of <Command>gmake</Command>. Two other <Command>make</Command>
2306 variables, <Constant>way_</Constant> and <Constant>_way</Constant> are immediately derived from <Constant>$(way)</Constant> and
2307 never altered. If <Constant>way</Constant> is not set, then neither are <Constant>way_</Constant> and
2308 <Constant>_way</Constant>, and the invocation of <Command>make</Command> will build the ``normal way''.
2309 If <Constant>way</Constant> is set, then the other two variables are set in sympathy.
2310 For example, if <Constant>$(way)</Constant> is ``<Literal>mp</Literal>'', then <Constant>way_</Constant> is set to ``<Literal>mp_</Literal>''
2311 and <Constant>_way</Constant> is set to ``<Literal>_mp</Literal>''. These three variables are then used
2312 when constructing file names.
2316 So how does <Command>make</Command> ever get recursively invoked with <Constant>way</Constant> set? There
2317 are two ways in which this happens:
2326 For some (but not all) of the standard targets, when in a leaf
2327 sub-directory, <Command>make</Command> is recursively invoked for each way tag in
2328 <Constant>$(WAYS)</Constant>. You set <Constant>WAYS</Constant> to the list of way tags you want these
2329 targets built for. The mechanism here is very much like the recursive
2330 invocation of <Command>make</Command> in sub-directories (<Xref LinkEnd="sec-subdirs">).
2332 It is up to you to set <Constant>WAYS</Constant> in your <Filename>Makefile</Filename>; this is how you
2333 control what ways will get built.
2339 For a useful collection of
2340 targets (such as <Filename>libHS_mp.a</Filename>, <Filename>Foo.mp_o</Filename>) there is a rule which
2341 recursively invokes <Command>make</Command> to make the specified target, setting the
2342 <Constant>way</Constant> variable. So if you say <Command>gmake Foo.mp_o</Command> you should see a
2343 recursive invocation <Command>gmake Foo.mp_o way=mp</Command>, and <Emphasis>in this
2344 recursive invocation the pattern rule for compiling a Haskell file
2345 into a <Filename>.o</Filename> file will match</Emphasis>. The key pattern rules (in <Filename>suffix.mk</Filename>)
2351 $(HC) $(HC_OPTS) $< -o $@
2366 <Title>When the canned rule isn't right</Title>
2369 Sometimes the canned rule just doesn't do the right thing. For
2370 example, in the <Literal>nofib</Literal> suite we want the link step to print out
2371 timing information. The thing to do here is <Emphasis>not</Emphasis> to define
2372 <Constant>HS_PROG</Constant> or <Constant>C_PROG</Constant>, and instead define a special purpose rule in
2373 your own <Filename>Makefile</Filename>. By using different variable names you will avoid
2374 the canned rules being included, and conflicting with yours.
2381 <Sect1 id="sec-booting-from-C">
2382 <Title>Booting/porting from C (<Filename>.hc</Filename>) files
2384 <IndexTerm><Primary>building GHC from .hc files</Primary></IndexTerm>
2385 <IndexTerm><Primary>booting GHC from .hc files</Primary></IndexTerm>
2386 <IndexTerm><Primary>porting GHC</Primary></IndexTerm></Title>
2389 This section is for people trying to get GHC going by using the supplied
2390 intermediate C (<Filename>.hc</Filename>) files. This would probably be
2391 because no binaries have been provided, or because the machine is not ``fully
2396 The intermediate C files are normally made available together with a source
2397 release, please check the announce message for exact directions of where to
2398 find them. If we haven't made them available or you can't find them, please
2403 Assuming you've got them, unpack them on top of a fresh source tree. This
2404 will place matching <Filename>.hc</Filename> files next to the corresponding
2405 Haskell source in the compiler subdirectory <Filename>ghc</Filename> and in
2406 the language package of hslibs (i.e., in <Filename>hslibs/lang</Filename>).
2407 Then follow the `normal' instructions in <Xref
2408 LinkEnd="sec-building-from-source"> for setting up a build tree.
2412 The actual build process is fully automated by the
2413 <Filename>hc-build</Filename> script located in the
2414 <Filename>distrib</Filename> directory. If you eventually want to install GHC
2415 into the directory <Filename>INSTALL_DIRECTORY</Filename>, the following
2416 command will execute the whole build process (it won't install yet):
2419 foo% distrib/hc-build --prefix=INSTALL_DIRECTORY
2421 <IndexTerm><Primary>--hc-build</Primary></IndexTerm>
2423 By default, the installation directory is <Filename>/usr/local</Filename>. If
2424 that is what you want, you may omit the argument to
2425 <Filename>hc-build</Filename>. Generally, any option given to
2426 <Filename>hc-build</Filename> is passed through to the configuration script
2427 <Filename>configure</Filename>. If <Filename>hc-build</Filename>
2428 successfully completes the build process, you can install the resulting
2429 system, as normal, with
2436 That's the mechanics of the boot process, but, of course, if you're
2437 trying to boot on a platform that is not supported and significantly
2438 `different' from any of the supported ones, this is only the start of
2439 the adventure…(ToDo: porting tips—stuff to look out for, etc.)
2444 <Sect1 id="sec-build-pitfalls">
2445 <Title>Known pitfalls in building Glasgow Haskell
2447 <IndexTerm><Primary>problems, building</Primary></IndexTerm>
2448 <IndexTerm><Primary>pitfalls, in building</Primary></IndexTerm>
2449 <IndexTerm><Primary>building pitfalls</Primary></IndexTerm></Title>
2452 WARNINGS about pitfalls and known ``problems'':
2461 One difficulty that comes up from time to time is running out of space
2462 in <Filename>/tmp</Filename>. (It is impossible for the configuration stuff to
2463 compensate for the vagaries of different sysadmin approaches to temp
2465 <IndexTerm><Primary>tmp, running out of space in</Primary></IndexTerm>
2467 The quickest way around it is <Command>setenv TMPDIR /usr/tmp</Command><IndexTerm><Primary>TMPDIR</Primary></IndexTerm> or
2468 even <Command>setenv TMPDIR .</Command> (or the equivalent incantation with your shell
2471 The best way around it is to say
2474 export TMPDIR=<dir>
2477 in your <Filename>build.mk</Filename> file.
2478 Then GHC and the other <Literal>fptools</Literal> programs will use the appropriate directory
2487 In compiling some support-code bits, e.g., in <Filename>ghc/rts/gmp</Filename> and even
2488 in <Filename>ghc/lib</Filename>, you may get a few C-compiler warnings. We think these
2496 When compiling via C, you'll sometimes get ``warning: assignment from
2497 incompatible pointer type'' out of GCC. Harmless.
2504 Similarly, <Command>ar</Command>chiving warning messages like the following are not
2508 ar: filename GlaIOMonad__1_2s.o truncated to GlaIOMonad_
2509 ar: filename GlaIOMonad__2_2s.o truncated to GlaIOMonad_
2519 In compiling the compiler proper (in <Filename>compiler/</Filename>), you <Emphasis>may</Emphasis>
2520 get an ``Out of heap space'' error message. These can vary with the
2521 vagaries of different systems, it seems. The solution is simple:
2528 If you're compiling with GHC 4.00 or later, then the
2529 <Emphasis>maximum</Emphasis> heap size must have been reached. This
2530 is somewhat unlikely, since the maximum is set to 64M by default.
2531 Anyway, you can raise it with the
2532 <Option>-optCrts-M<size></Option> flag (add this flag to
2533 <Constant><module>_HC_OPTS</Constant>
2534 <Command>make</Command> variable in the appropriate
2535 <Filename>Makefile</Filename>).
2542 For GHC < 4.00, add a suitable <Option>-H</Option> flag to the <Filename>Makefile</Filename>, as
2551 and try again: <Command>gmake</Command>. (see <Xref LinkEnd="sec-suffix"> for information about
2552 <Constant><module>_HC_OPTS</Constant>.)
2554 Alternatively, just cut to the chase:
2558 % make EXTRA_HC_OPTS=-optCrts-M128M
2567 If you try to compile some Haskell, and you get errors from GCC about
2568 lots of things from <Filename>/usr/include/math.h</Filename>, then your GCC was
2569 mis-installed. <Command>fixincludes</Command> wasn't run when it should've been.
2571 As <Command>fixincludes</Command> is now automagically run as part of GCC installation,
2572 this bug also suggests that you have an old GCC.
2580 You <Emphasis>may</Emphasis> need to re-<Command>ranlib</Command><IndexTerm><Primary>ranlib</Primary></IndexTerm> your libraries (on Sun4s).
2584 % cd $(libdir)/ghc-x.xx/sparc-sun-sunos4
2585 % foreach i ( `find . -name '*.a' -print` ) # or other-shell equiv...
2587 ? # or, on some machines: ar s $i
2592 We'd be interested to know if this is still necessary.
2600 GHC's sources go through <Command>cpp</Command> before being compiled, and <Command>cpp</Command> varies
2601 a bit from one Unix to another. One particular gotcha is macro calls
2606 SLIT("Hello, world")
2610 Some <Command>cpp</Command>s treat the comma inside the string as separating two macro
2611 arguments, so you get
2615 :731: macro `SLIT' used with too many (2) args
2619 Alas, <Command>cpp</Command> doesn't tell you the offending file!
2621 Workaround: don't put weird things in string args to <Command>cpp</Command> macros.
2632 <Sect1 id="winbuild"><Title>Notes for building under Windows</Title>
2635 This section summarises how to get the utilities you need on your
2636 Win95/98/NT/2000 machine to use CVS and build GHC. Similar notes for installing and running GHC may be found in the user guide. In general, Win95/Win98 behave the same, and WinNT/Win2k behave the same. It is based largely on detailed advice from Sigbjørn Finne.
2640 <Sect2><Title>Installing ssh</Title>
2646 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.
2652 Extract <ULink URL="http://research.microsoft.com/~simonpj/cygwinb19.dll.zip">cygwinb19.dll</ULink> into <Filename>/usr/local/bin</Filename>. The current version
2653 of Cywin is b20, but this version of ssh was compiled with b19.
2659 On a Win2k machine, open up a bash and do
2664 foo$ mkpasswd -l > passwd
2668 Check that your login entry is on the first line
2669 of that file. If not, move it to the top. It's OK
2670 for 'Administrator' to be the first entry, assuming you are one.
2674 However, Win9x doesn't support the calls that <Command>mkpasswd</Command> relies on
2675 (e.g., <Function>NetUserEnum</Function>). If you run <Command>mkpasswd</Command> you
2680 linked to missing export netapi32.dll:NetUserEnum
2684 The passwd file is used
2685 by ssh in a fairly rudimentary manner, so I'd simply
2686 synthesise/copy an existing Unix <Filename>/etc/passwd</Filename>, i.e., create
2687 an <Filename>/etc/passwd</Filename> file containing the line
2691 <login>::500:513:::/bin/sh
2695 where <Literal><login></Literal> is your login id.
2701 Generate a key, by running <Filename>c:/user/local/bin/ssh-keygen1</Filename>.
2702 This generates a public key in <Filename>.ssh/identity.pub</Filename>, and a
2703 private key in <Filename>.ssh/identity</Filename>
2707 In response to the 'Enter passphrase' question, just hit
2708 return (i.e. use an empty passphrase). The passphrase is
2709 a password that protects your private key. But it's a pain
2710 to type this passphrase everytime you use <Command>ssh</Command>, so the best
2711 thing to do is simply to protect your <Filename>.ssh</Filename> directory, and
2712 <Filename>.ssh/identity</Filename> from access by anyone else. To do this
2713 right-click your <Filename>.ssh</Filename> directory, and select Properties.
2714 If you are not on the access control list, add yourself, and
2715 give yourself full permissions (the second panel).
2716 Remove everyone else from the access control list. (Don't
2717 leave them there but deny them access, because 'they' may be
2718 a list that includes you!)
2722 If you have problems running <Command>ssh-keygen1</Command>
2723 from within <Command>bash</Command>, start up <Filename>cmd.exe</Filename> and run it as follows:
2727 c:\tmp> set CYGWIN32=tty
2728 c:\tmp> c:/user/local/bin/ssh-keygen1
2734 If you don't have an account on <Literal>cvs.haskell.org</Literal>, send
2735 your <Filename>.ssh/identity.pub</Filename> to the CVS repository administrator
2736 (currently Jeff Lewis <Email>jlewis@cse.ogi.edu</Email>). He will set up
2741 If you do have an account on <Literal>cvs.haskell.org</Literal>, use TeraTerm
2742 to logon to it. Once in, copy the
2743 key that <Command>ssh-keygen1</Command> deposited in <Filename>/.ssh/identity.pub</Filename> into
2744 your <Filename>~/.ssh/authorized_keys</Filename>. Make sure that the new version
2745 of <Filename>authorized_keys</Filename> still has 600 file permission.
2754 <Sect2><Title>Installing CVS</Title>
2761 <ULink URL="http://research.microsoft.com/~simonpj/cvs-1_10-win.zip">
2762 CVS</ULink> and, following the instructions in the <Filename>README</Filename>, copy the
2763 appropriate files into <Filename>/usr/local/bin</Filename>.
2769 From the System control panel,
2770 set the following <Emphasis>user</Emphasis> environment variables (see the GHC user guide)
2776 <Constant>HOME</Constant>: points to your home directory. This is where CVS
2777 will look for its <Filename>.cvsrc</Filename> file.
2783 <Constant>CVS_RSH</Constant>: <Filename>c:/usr/local/bin/ssh1</Filename>
2789 <Constant>CVSROOT</Constant>: <Literal>:ext:username@cvs.haskell.org:/home/cvs/root</Literal>,
2790 where <Literal>username</Literal> is your userid
2796 <Constant>CVSEDITOR</Constant>: <Filename>bin/gnuclient.exe</Filename> if you want to use an Emacs buffer for typing in those long commit messages.
2804 Put the following in <Filename>$HOME/.cvsrc</Filename>:
2815 These are the default options for the specified CVS commands,
2816 and represent better defaults than the usual ones. (Feel
2817 free to change them.)
2821 Filenames starting with "<Filename>.</Filename>" were illegal in
2822 the 8.3 DOS filesystem, but that restriction should have
2823 been lifted by now (i.e., you're using VFAT or later filesystems.) If
2824 you're still having problems creating it, don't worry; <Filename>.cvsrc</Filename> is entirely
2831 Try doing <Command>cvs co fpconfig</Command>. All being well, bytes should
2832 start to trickle through, leaving a directory <Filename>fptools</Filename>
2833 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:
2837 setsockopt IPTOS_LOWDELAY: Invalid argument
2838 setsockopt IPTOS_THROUGHPUT: Invalid argument
2842 At this point I found that CVS tried to invoke a little dialogue with
2843 me (along the lines of `do you want to talk to this host'), but
2844 somehow bombed out. This was from a bash shell running in emacs.
2845 I solved this by invoking a Cygnus shell, and running CVS from there.
2846 Once things are dialogue free, it seems to work OK from within emacs.
2852 If you want to check out part of large tree, proceed as follows:
2856 cvs -f checkout -l papers
2862 This sequence checks out the <Literal>papers</Literal> module, but none
2863 of its sub-directories.
2864 The "<Option>-l</Option>" flag says not to check out sub-directories.
2865 The "<Option>-f</Option>" flag says not to read the <Filename>.cvsrc</Filename> file
2866 whose <Option>-P</Option> default (don't check out empty directories) is
2871 The <Command>cvs update</Command> command sucks in a named sub-directory.
2878 There is a very nice graphical front-end to CVS for Win32 platforms,
2879 with a UI that people will be familiar with, at
2880 <ULink URL="http://www.wincvs.org/">wincvs.org</ULink>.
2881 I have not tried it yet.
2887 <Sect2><Title>Installing autoconf</Title>
2890 Only required if you are doing builds from GHC's sources
2891 checked out from the CVS tree.
2897 Fetch the (standard, Unix) <Command>autoconf</Command> distribution from
2898 <ULink URL="ftp://ftp.gnu.org/gnu/autoconf">ftp.gnu.org</ULink>.
2903 Unpack it into an arbitrary directory.
2908 Make sure that the directory <Filename>/usr/local/bin</Filename> exists.
2913 Say "<Filename>./configure</Filename>".
2918 Now <Command>make install</Command>. This should put <Filename>autoheader</Filename>
2919 and <Filename>autoconf</Filename> in <Filename>/usr/local/bin</Filename>.
2925 <Command>autoheader</Command> doesn't seem to work, but you don't need it
2932 <Sect2><Title>Building GHC</Title>
2938 In the <Filename>./configure</Filename> output, ignore
2940 checking whether #! works in shell scripts...
2941 ./configure: ./conftest: No such file or directory</Literal>",
2942 and "<Literal>not updating unwritable cache ./config.cache</Literal>".
2943 Nobody knows why these happen, but they seem to be harmless.
2949 You have to run <Command>autoconf</Command> both in <Filename>fptools</Filename>
2950 and in <Filename>fptools/ghc</Filename>. If you omit the latter step you'll
2951 get an error when you run <Filename>./configure</Filename>:
2956 creating mk/config.h
2957 mk/config.h is unchanged
2959 running /bin/sh ./configure --cache-file=.././config.cache --srcdir=.
2960 ./configure: ./configure: No such file or directory
2961 configure: error: ./configure failed for ghc
2967 You need <Filename>ghc</Filename> to be in your <Constant>PATH</Constant> before you run
2968 <Command>configure</Command>. The default GHC InstallShield creates only
2969 <Filename>ghc-4.05</Filename>, so you may need to duplicate this file as <Filename>ghc</Filename>
2970 in the same directory, in order that <Command>configure</Command> will see it (or
2971 just rename <Filename>ghc-4.05</Filename> to <Filename>ghc</Filename>.
2972 And make sure that the directory is in your path.
2978 Compile <Command>happy</Command> and <Command>ghc</Command>
2979 with <Option>-static</Option>. To do this, set
2988 in your <Filename>build.mk</Filename> file.
2989 [Actually, I successfully compiled Happy without <Option>-static</Option> on Win2k, but not GHC.]