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
89 the more awkward machine-independent steps are done for you. For
90 example, if you don't have
91 <Command>happy</Command><IndexTerm><Primary>happy</Primary></IndexTerm>
92 you'll find it convenient that the source distribution contains the
93 result of running <Command>happy</Command> on the parser
94 specifications. If you don't want to alter the parser then this saves
95 you having to find and install <Command>happy</Command>. You will
96 still need a working version of GHC (preferably version 4.08+) on your
97 machine in order to compile (most of) the sources, however.
100 </ListItem></VarListEntry>
102 <Term>Build GHC from intermediate C <Filename>.hc</Filename> files<IndexTerm><Primary>hc files</Primary></IndexTerm>:</Term>
106 need a working GHC to use a source distribution. What if you don't
107 have a working GHC? Then you have no choice but to ``bootstrap'' up
108 from the intermediate C (<Filename>.hc</Filename>) files that we provide. Building GHC
109 on an unsupported platform falls into this category. Please see
110 <Xref LinkEnd="sec-booting-from-C">.
114 Once you have built GHC, you can build the other Glasgow tools with
119 In theory, you can (could?) build GHC with another Haskell compiler
120 (e.g., HBC). We haven't tried to do this for ages and it almost
121 certainly doesn't work any more (for tedious reasons).
123 </ListItem></VarListEntry>
125 <Term>The CVS repository.</Term>
128 We make releases infrequently. If you want more up-to-the minute (but
129 less tested) source code then you need to get access to our CVS
133 <para>All the <Literal>fptools</Literal> source code is held in a CVS
134 repository. CVS is a pretty good source-code control system, and best
135 of all it works over the network.</para>
137 <para>The repository holds source code only. It holds no mechanically
138 generated files at all. So if you check out a source tree from CVS
139 you will need to install every utility so that you can build all the
140 derived files from scratch.</para>
142 <para>More information about our CVS repository is available in the
143 <ULink URL="http://www.haskell.org/ghc/cvs-cheat-sheet.html">fptools
144 CVS Cheat Sheet</ULink>.</para>
146 </ListItem></VarListEntry>
150 <para>If you are going to do any building from sources (either from a
151 source distribution or the CVS repository) then you need to read all
152 of this manual in detail.</para>
156 <Sect1 id="sec-build-checks">
157 <Title>Things to check before you start typing</Title>
160 Here's a list of things to check before you get started.
166 <IndexTerm><Primary>Disk space needed</Primary></IndexTerm>
167 Disk space needed: About 40MB (one tenth of one hamburger's worth) of disk
168 space for the most basic binary distribution of GHC; more for some
169 platforms, e.g., Alphas. An extra ``bundle'' (e.g., concurrent Haskell
170 libraries) might take you to up to one fifth of a hamburger. You'll need
171 over 100MB (say, one fifth a hamburger's worth) if you need to build the
172 basic stuff from scratch. All of the above are
173 <Emphasis>estimates</Emphasis> of disk-space needs. (Note: our benchmark hamburger is a standard Double Whopper with Cheese, with an RRP of UKP2.99.)
179 Use an appropriate machine, compilers, and things. SPARC boxes, and
180 PCs running Linux, BSD (any variant), or Solaris are all fully
181 supported. Win32 and HP boxes are in pretty good shape. DEC Alphas
182 running OSF/1, Linux or some BSD variant, MIPS and AIX boxes will need
183 some minimal porting effort before they work (as of 4.06). <Xref
184 LinkEnd="sec-port-info"> gives the full run-down on ports or lack
191 Be sure that the ``pre-supposed'' utilities are installed.
192 <Xref LinkEnd="sec-pre-supposed"> elaborates.
199 If you have any problem when building or installing the Glasgow
200 tools, please check the ``known pitfalls'' (<Xref
201 LinkEnd="sec-build-pitfalls">). Also check the FAQ for the version
202 you're building, which should be available from the relevant download
203 page on the <ULink URL="http://www.haskell.org/ghc/" >GHC web
206 <IndexTerm><Primary>known bugs</Primary></IndexTerm>
207 <IndexTerm><Primary>bugs, known</Primary></IndexTerm>
209 If you feel there is still some shortcoming in our procedure or
210 instructions, please report it.
212 For GHC, please see the bug-reporting section of the GHC Users' Guide
213 (separate document), to maximise the usefulness of your report.
214 <IndexTerm><Primary>bugs, reporting</Primary></IndexTerm>
216 If in doubt, please send a message to
217 <Email>glasgow-haskell-bugs@haskell.org</Email>.
218 <IndexTerm><Primary>bugs, mailing list</Primary></IndexTerm>
228 <Sect1 id="sec-port-info">
229 <Title>What machines the Glasgow tools run on
233 <IndexTerm><Primary>ports, GHC</Primary></IndexTerm>
234 <IndexTerm><Primary>GHC ports</Primary></IndexTerm>
235 <IndexTerm><Primary>supported platforms</Primary></IndexTerm>
236 <IndexTerm><Primary>platforms, supported</Primary></IndexTerm>
237 The main question is whether or not the Haskell compiler (GHC) runs on
242 A ``platform'' is a architecture/manufacturer/operating-system
243 combination, such as <Literal>sparc-sun-solaris2</Literal>. Other common ones are
244 <Literal>alpha-dec-osf2</Literal>, <Literal>hppa1.1-hp-hpux9</Literal>, <Literal>i386-unknown-linux</Literal>,
245 <Literal>i386-unknown-solaris2</Literal>, <Literal>i386-unknown-freebsd</Literal>,
246 <Literal>i386-unknown-cygwin32</Literal>, <Literal>m68k-sun-sunos4</Literal>, <Literal>mips-sgi-irix5</Literal>,
247 <Literal>sparc-sun-sunos4</Literal>, <Literal>sparc-sun-solaris2</Literal>, <Literal>powerpc-ibm-aix</Literal>.
251 Bear in mind that certain ``bundles'', e.g. parallel Haskell, may not
252 work on all machines for which basic Haskell compiling is supported.
256 Some libraries may only work on a limited number of platforms; for
257 example, a sockets library is of no use unless the operating system
258 supports the underlying BSDisms.
262 <Title>What platforms the Haskell compiler (GHC) runs on</Title>
265 <IndexTerm><Primary>fully-supported platforms</Primary></IndexTerm>
266 <IndexTerm><Primary>native-code generator</Primary></IndexTerm>
267 <IndexTerm><Primary>registerised ports</Primary></IndexTerm>
268 <IndexTerm><Primary>unregisterised ports</Primary></IndexTerm>
269 The GHC hierarchy of Porting Goodness: (a) Best is a native-code
270 generator; (b) next best is a ``registerised''
271 port; (c) the bare minimum is an ``unregisterised'' port.
272 (``Unregisterised'' is so terrible that we won't say more about it).
276 We use Sparcs running Solaris 2.7 and x86 boxes running FreeBSD and
277 Linux, so those are the best supported platforms, unsurprisingly.
281 Here's everything that's known about GHC ports. We identify platforms
282 by their ``canonical'' CPU/Manufacturer/OS triple.
289 <Term>alpha-dec-{osf,linux,freebsd,openbsd,netbsd}:</Term>
290 <IndexTerm><Primary>alpha-dec-osf</Primary></IndexTerm>
291 <IndexTerm><Primary>alpha-dec-linux</Primary></IndexTerm>
292 <IndexTerm><Primary>alpha-dec-freebsd</Primary></IndexTerm>
293 <IndexTerm><Primary>alpha-dec-openbsd</Primary></IndexTerm>
294 <IndexTerm><Primary>alpha-dec-netbsd</Primary></IndexTerm>
298 Currently non-working. The last working version (osf[1-3]) is GHC
299 3.02. A small amount of porting effort will be required to get Alpha
300 support into GHC 4.xx, but we don't have easy access to machines right
301 now, and there hasn't been a massive demand for support, so Alphas
302 remain unsupported for the time being. Please get in touch if you
303 either need Alpha support and/or can provide access to boxes.
306 </ListItem></VarListEntry>
308 <Term>sparc-sun-sunos4:</Term>
309 <IndexTerm><Primary>sparc-sun-sunos4</Primary></IndexTerm>
313 Probably works with minor tweaks, hasn't been tested for a while.
316 </ListItem></VarListEntry>
318 <Term>sparc-sun-solaris2:</Term>
319 <IndexTerm><Primary>sparc-sun-solaris2</Primary></IndexTerm>
323 Fully supported, including native-code generator.
326 </ListItem></VarListEntry>
328 <Term>hppa1.1-hp-hpux (HP-PA boxes running HPUX 9.x)</Term>
329 <IndexTerm><Primary>hppa1.1-hp-hpux</Primary></IndexTerm>
333 Works registerised. No native-code generator.
336 </ListItem></VarListEntry>
338 <Term>i386-unknown-linux (PCs running Linux—ELF binary format):</Term>
339 <IndexTerm><Primary>i386-*-linux</Primary></IndexTerm>
342 <para>GHC works registerised, has a native code generator. You
343 <Emphasis>must</Emphasis> have GCC 2.7.x or later. NOTE about
344 <literal>glibc</literal> versions: GHC binaries built on a system
345 running <literal>glibc 2.0</literal> won't work on a system running
346 <literal>glibc 2.1</literal>, and vice versa. In general, don't
347 expect compatibility between <literal>glibc</literal> versions, even
348 if the shared library version hasn't changed.
351 </ListItem></VarListEntry>
353 <Term>i386-unknown-{freebsd,netbsd,openbsd) (PCs running FreeBSD 2.2
354 or higher, NetBSD, and possibly OpenBSD):</Term>
355 <IndexTerm><Primary>i386-unknown-freebsd</Primary></IndexTerm>
356 <IndexTerm><Primary>i386-unknown-netbsd</Primary></IndexTerm>
357 <IndexTerm><Primary>i386-unknown-openbsd</Primary></IndexTerm>
361 GHC works registerised. These systems provide ready-built packages of
362 GHC, so if you just need binaries you're better off just installing
366 </ListItem></VarListEntry>
368 <Term>i386-unknown-cygwin32:</Term>
369 <IndexTerm><Primary>i386-unknown-cygwin32</Primary></IndexTerm>
373 Fully supported under Win9x/NT, including a native code
374 generator. Requires the <Literal>cygwin32</Literal> compatibility
375 library and a healthy collection of GNU tools (i.e., gcc, GNU ld, bash
379 </ListItem></VarListEntry>
381 <Term>mips-sgi-irix5:</Term>
382 <IndexTerm><Primary>mips-sgi-irix[5-6]</Primary></IndexTerm>
386 Port currently doesn't work, needs some minimal porting effort. As
387 usual, we don't have access to machines and there hasn't been an
388 overwhelming demand for this port, but feel free to get in touch.
390 </ListItem></VarListEntry>
393 <Term>powerpc-ibm-aix:</Term>
396 <IndexTerm><Primary>powerpc-ibm-aix</Primary></IndexTerm>
397 Port currently doesn't work, needs some minimal porting effort. As
398 usual, we don't have access to machines and there hasn't been an
399 overwhelming demand for this port, but feel free to get in touch.
401 </ListItem></VarListEntry>
407 Various other systems have had GHC ported to them in the distant past,
408 including various Motorola 68k boxes. The 68k support still remains,
409 but porting to one of these systems will certainly be a non-trivial
416 <Title>What machines the other tools run on</Title>
419 Unless you hear otherwise, the other tools work if GHC works.
427 <Sect1 id="sec-pre-supposed">
428 <Title>Installing pre-supposed utilities
430 <IndexTerm><Primary>pre-supposed utilities</Primary></IndexTerm>
431 <IndexTerm><Primary>utilities, pre-supposed</Primary></IndexTerm></Title>
434 Here are the gory details about some utility programs you may need;
435 <Command>perl</Command>, <Command>gcc</Command> and
436 <command>happy</command> are the only important
437 ones. (PVM<IndexTerm><Primary>PVM</Primary></IndexTerm> is important
438 if you're going for Parallel Haskell.) The
439 <Command>configure</Command><IndexTerm><Primary>configure</Primary></IndexTerm>
440 script will tell you if you are missing something.
448 <IndexTerm><Primary>pre-supposed: Perl</Primary></IndexTerm>
449 <IndexTerm><Primary>Perl, pre-supposed</Primary></IndexTerm>
452 <Emphasis>You have to have Perl to proceed!</Emphasis> Perl is a
453 language quite good for doing shell-scripty tasks that involve lots of
454 text processing. It is pretty easy to install.
458 Perl 5 is required. For Win32 platforms, you should use the binary
459 supplied in the InstallShield (copy it to <filename>cygwin/bin</filename>).
460 The Cygwin-supplied Perl seems not to work (it has problems with line
465 Perl should be put somewhere so that it can be invoked by the
466 <Literal>#!</Literal> script-invoking mechanism. The full
467 pathname may need to be less than 32 characters long on some
471 </ListItem></VarListEntry>
473 <Term>GNU C (<Command>gcc</Command>):</Term>
474 <IndexTerm><Primary>pre-supposed: GCC (GNU C compiler)</Primary></IndexTerm>
475 <IndexTerm><Primary>GCC (GNU C compiler), pre-supposed</Primary></IndexTerm>
479 We recommend using GCC version 2.95.2 on all platforms. Failing that,
480 version 2.7.2 is stable on most platforms. Earlier versions of GCC
481 can be assumed not to work, and versions in between 2.7.2 and 2.95.2
482 (including <command>egcs</command>) have varying degrees of stability
483 depending on the platform.
487 If your GCC dies with ``internal error'' on some GHC source file,
488 please let us know, so we can report it and get things improved.
489 (Exception: on iX86 boxes—you may need to fiddle with GHC's
490 <Option>-monly-N-regs</Option> option; see the User's Guide)
492 </ListItem></VarListEntry>
496 <indexterm><primary>Happy</primary></indexterm>
498 <para>Happy is a parser generator tool for Haskell, and is used to
499 generate GHC's parsers. Happy is written in Haskell, and is a project
500 in the CVS repository (<literal>fptools/happy</literal>). It can be
501 built from source, but bear in mind that you'll need GHC installed in
502 order to build it. To avoid the chicken/egg problem, install a binary
503 distribtion of either Happy or GHC to get started. Happy
504 distributions are available from <ulink
505 url="http://www.haskell.org/happy/">Happy's Web Page</ulink>.
511 <Term>Autoconf:</Term>
512 <IndexTerm><Primary>pre-supposed: Autoconf</Primary></IndexTerm>
513 <IndexTerm><Primary>Autoconf, pre-supposed</Primary></IndexTerm>
516 GNU Autoconf is needed if you intend to build from the CVS sources, it
517 is <Emphasis>not</Emphasis> needed if you just intend to build a
518 standard source distribution.
522 Autoconf builds the <Command>configure</Command> script from
523 <Filename>configure.in</Filename> and <Filename>aclocal.m4</Filename>.
524 If you modify either of these files, you'll need
525 <command>autoconf</command> to rebuild <Filename>configure</Filename>.
528 </ListItem></VarListEntry>
530 <Term><Command>sed</Command></Term>
531 <IndexTerm><Primary>pre-supposed: sed</Primary></IndexTerm>
532 <IndexTerm><Primary>sed, pre-supposed</Primary></IndexTerm>
535 You need a working <Command>sed</Command> if you are going to build
536 from sources. The build-configuration stuff needs it. GNU sed
537 version 2.0.4 is no good! It has a bug in it that is tickled by the
538 build-configuration. 2.0.5 is OK. Others are probably OK too
539 (assuming we don't create too elaborate configure scripts.)
541 </ListItem></VarListEntry>
546 One <Literal>fptools</Literal> project is worth a quick note at this
547 point, because it is useful for all the others:
548 <Literal>glafp-utils</Literal> contains several utilities which aren't
549 particularly Glasgow-ish, but Occasionally Indispensable. Like
550 <Command>lndir</Command> for creating symbolic link trees.
553 <Sect2 id="pre-supposed-gph-tools">
554 <Title>Tools for building parallel GHC (GPH)
561 <Term>PVM version 3:</Term>
562 <IndexTerm><Primary>pre-supposed: PVM3 (Parallel Virtual Machine)</Primary></IndexTerm>
563 <IndexTerm><Primary>PVM3 (Parallel Virtual Machine), pre-supposed</Primary></IndexTerm>
567 PVM is the Parallel Virtual Machine on which Parallel Haskell programs
568 run. (You only need this if you plan to run Parallel Haskell.
569 Concurent Haskell, which runs concurrent threads on a uniprocessor
570 doesn't need it.) Underneath PVM, you can have (for example) a
571 network of workstations (slow) or a multiprocessor box (faster).
575 The current version of PVM is 3.3.11; we use 3.3.7. It is readily
576 available on the net; I think I got it from
577 <Literal>research.att.com</Literal>, in <Filename>netlib</Filename>.
581 A PVM installation is slightly quirky, but easy to do. Just follow
582 the <Filename>Readme</Filename> instructions.
584 </ListItem></VarListEntry>
586 <Term><Command>bash</Command>:</Term>
587 <IndexTerm><Primary>bash, presupposed (Parallel Haskell only)</Primary></IndexTerm>
590 Sadly, the <Command>gr2ps</Command> script, used to convert ``parallelism profiles''
591 to PostScript, is written in Bash (GNU's Bourne Again shell).
592 This bug will be fixed (someday).
594 </ListItem></VarListEntry>
600 <Sect2 id="pre-supposed-doc-tools">
601 <Title>Tools for building the Documentation
605 The following additional tools are required if you want to format the
606 documentation that comes with the <Literal>fptools</Literal> projects:
613 <Term>DocBook:</Term>
614 <IndexTerm><Primary>pre-supposed: DocBook</Primary></IndexTerm>
615 <IndexTerm><Primary>DocBook, pre-supposed</Primary></IndexTerm>
618 All our documentation is written in SGML, using the DocBook DTD.
619 Instructions on installing and configuring the DocBook tools are in the
620 installation guide (in the GHC user guide).
623 </ListItem></VarListEntry>
626 <IndexTerm><Primary>pre-supposed: TeX</Primary></IndexTerm>
627 <IndexTerm><Primary>TeX, pre-supposed</Primary></IndexTerm>
630 A decent TeX distribution is required if you want to produce printable
631 documentation. We recomment teTeX, which includes just about
634 </ListItem></VarListEntry>
640 <Sect2 id="pre-supposed-other-tools">
641 <Title>Other useful tools
647 <IndexTerm><Primary>pre-supposed: flex</Primary></IndexTerm>
648 <IndexTerm><Primary>flex, pre-supposed</Primary></IndexTerm>
652 This is a quite-a-bit-better-than-Lex lexer. Used to build a couple
653 of utilities in <Literal>glafp-utils</Literal>. Depending on your
654 operating system, the supplied <Command>lex</Command> may or may not
655 work; you should get the GNU version.
657 </ListItem></VarListEntry>
664 <Sect1 id="sec-building-from-source">
665 <Title>Building from source
667 <IndexTerm><Primary>Building from source</Primary></IndexTerm>
668 <IndexTerm><Primary>Source, building from</Primary></IndexTerm></Title>
671 You've been rash enough to want to build some of
672 the Glasgow Functional Programming tools (GHC, Happy,
673 nofib, etc.) from source. You've slurped the source,
674 from the CVS repository or from a source distribution, and
675 now you're sitting looking at a huge mound of bits, wondering
680 Gingerly, you type <Command>make</Command>. Wrong already!
684 This rest of this guide is intended for duffers like me, who aren't
685 really interested in Makefiles and systems configurations, but who
686 need a mental model of the interlocking pieces so that they can make
687 them work, extend them consistently when adding new software, and lay
688 hands on them gently when they don't work.
691 <Sect2 id="sec-source-tree">
692 <Title>Your source tree
696 The source code is held in your <Emphasis>source tree</Emphasis>.
697 The root directory of your source tree <Emphasis>must</Emphasis>
698 contain the following directories and files:
707 <Filename>Makefile</Filename>: the root Makefile.
713 <Filename>mk/</Filename>: the directory that contains the
714 main Makefile code, shared by all the
715 <Literal>fptools</Literal> software.
721 <Filename>configure.in</Filename>, <Filename>config.sub</Filename>, <Filename>config.guess</Filename>:
722 these files support the configuration process.
728 <Filename>install-sh</Filename>.
737 All the other directories are individual <Emphasis>projects</Emphasis> of the
738 <Literal>fptools</Literal> system—for example, the Glasgow Haskell Compiler
739 (<Literal>ghc</Literal>), the Happy parser generator (<Literal>happy</Literal>), the <Literal>nofib</Literal> benchmark
740 suite, and so on. You can have zero or more of these. Needless to
741 say, some of them are needed to build others.
745 The important thing to remember is that even if you want only one
746 project (<Literal>happy</Literal>, say), you must have a source tree whose root
747 directory contains <Filename>Makefile</Filename>, <Filename>mk/</Filename>, <Filename>configure.in</Filename>, and the
748 project(s) you want (<Filename>happy/</Filename> in this case). You cannot get by with
749 just the <Filename>happy/</Filename> directory.
756 <IndexTerm><Primary>build trees</Primary></IndexTerm>
757 <IndexTerm><Primary>link trees, for building</Primary></IndexTerm></Title>
760 While you can build a system in the source tree, we don't recommend it.
761 We often want to build multiple versions of our software
762 for different architectures, or with different options (e.g. profiling).
763 It's very desirable to share a single copy of the source code among
768 So for every source tree we have zero or more <Emphasis>build trees</Emphasis>. Each
769 build tree is initially an exact copy of the source tree, except that
770 each file is a symbolic link to the source file, rather than being a
771 copy of the source file. There are ``standard'' Unix utilities that
772 make such copies, so standard that they go by different names:
773 <Command>lndir</Command><IndexTerm><Primary>lndir</Primary></IndexTerm>, <Command>mkshadowdir</Command><IndexTerm><Primary>mkshadowdir</Primary></IndexTerm> are two (If you
774 don't have either, the source distribution includes sources for the
775 X11 <Command>lndir</Command>—check out <Filename>fptools/glafp-utils/lndir</Filename>). See <Xref LinkEnd="sec-storysofar"> for a typical invocation.
779 The build tree does not need to be anywhere near the source tree in
780 the file system. Indeed, one advantage of separating the build tree
781 from the source is that the build tree can be placed in a
782 non-backed-up partition, saving your systems support people from
783 backing up untold megabytes of easily-regenerated, and
784 rapidly-changing, gubbins. The golden rule is that (with a single
785 exception—<XRef LinkEnd="sec-build-config">)
786 <Emphasis>absolutely everything in the build tree is either a symbolic
787 link to the source tree, or else is mechanically generated</Emphasis>.
788 It should be perfectly OK for your build tree to vanish overnight; an
789 hour or two compiling and you're on the road again.
793 You need to be a bit careful, though, that any new files you create
794 (if you do any development work) are in the source tree, not a build tree!
798 Remember, that the source files in the build tree are <Emphasis>symbolic
799 links</Emphasis> to the files in the source tree. (The build tree soon
800 accumulates lots of built files like <Filename>Foo.o</Filename>, as well.) You
801 can <Emphasis>delete</Emphasis> a source file from the build tree without affecting
802 the source tree (though it's an odd thing to do). On the other hand,
803 if you <Emphasis>edit</Emphasis> a source file from the build tree, you'll edit the
804 source-tree file directly. (You can set up Emacs so that if you edit
805 a source file from the build tree, Emacs will silently create an
806 edited copy of the source file in the build tree, leaving the source
807 file unchanged; but the danger is that you think you've edited the
808 source file whereas actually all you've done is edit the build-tree
809 copy. More commonly you do want to edit the source file.)
813 Like the source tree, the top level of your build tree must be (a
814 linked copy of) the root directory of the <Literal>fptools</Literal> suite. Inside
815 Makefiles, the root of your build tree is called
816 <Constant>$(FPTOOLS_TOP)</Constant><IndexTerm><Primary>FPTOOLS_TOP</Primary></IndexTerm>. In the rest of this document path
817 names are relative to <Constant>$(FPTOOLS_TOP)</Constant> unless otherwise stated. For
818 example, the file <Filename>ghc/mk/target.mk</Filename> is actually
819 <Filename><Constant>$(FPTOOLS_TOP)</Constant>/ghc/mk/target.mk</Filename>.
824 <Sect2 id="sec-build-config">
825 <Title>Getting the build you want
829 When you build <Literal>fptools</Literal> you will be compiling code on a particular
830 <Emphasis>host platform</Emphasis>, to run on a particular <Emphasis>target platform</Emphasis>
831 (usually the same as the host platform)<IndexTerm><Primary>platform</Primary></IndexTerm>. The
832 difficulty is that there are minor differences between different
833 platforms; minor, but enough that the code needs to be a bit different
834 for each. There are some big differences too: for a different
835 architecture we need to build GHC with a different native-code
840 There are also knobs you can turn to control how the <Literal>fptools</Literal>
841 software is built. For example, you might want to build GHC optimised
842 (so that it runs fast) or unoptimised (so that you can compile it fast
843 after you've modified it. Or, you might want to compile it with
844 debugging on (so that extra consistency-checking code gets included)
849 All of this stuff is called the <Emphasis>configuration</Emphasis> of your build.
850 You set the configuration using a three-step process.
854 <Term>Step 1: get ready for configuration.</Term>
856 <para>Change directory to
857 <Constant>$(FPTOOLS_TOP)</Constant> and
859 <Command>autoconf</Command><IndexTerm><Primary>autoconf</Primary></IndexTerm>
860 (with no arguments). This GNU program converts
861 <Filename><Constant>$(FPTOOLS_TOP)</Constant>/configure.in</Filename>
862 to a shell script called
863 <Filename><Constant>$(FPTOOLS_TOP)</Constant>/configure</Filename>.
866 <para>Some projects, including GHC, have their own
867 configure script. If there's an
868 <Constant>$(FPTOOLS_TOP)/<project>/configure.in</Constant>,
869 then you need to run <command>autoconf</command> in that
870 directory too.</para>
872 <para>Both these steps are completely
873 platform-independent; they just mean that the
874 human-written file (<Filename>configure.in</Filename>)
875 can be short, although the resulting shell script,
876 <Command>configure</Command>, and
877 <Filename>mk/config.h.in</Filename>, are long.</para>
879 <para>In case you don't have <Command>autoconf</Command>
880 we distribute the results, <Command>configure</Command>,
881 and <Filename>mk/config.h.in</Filename>, with the source
882 distribution. They aren't kept in the repository,
888 <term>Step 2: system configuration.</term>
890 <para>Runs the newly-created
891 <Command>configure</Command> script, thus:</para>
894 ./configure <optional><parameter>args</parameter></optional>
897 <para><Command>configure</Command>'s mission is to
898 scurry round your computer working out what architecture
899 it has, what operating system, whether it has the
900 <Function>vfork</Function> system call, where
901 <Command>yacc</Command> is kept, whether
902 <Command>gcc</Command> is available, where various
903 obscure <Literal>#include</Literal> files are,
904 whether it's a leap year, and what the systems manager
905 had for lunch. It communicates these snippets of
906 information in two ways:</para>
912 <Filename>mk/config.mk.in</Filename><IndexTerm><Primary>config.mk.in</Primary></IndexTerm>
914 <Filename>mk/config.mk</Filename><IndexTerm><Primary>config.mk</Primary></IndexTerm>,
915 substituting for things between
916 ``<Literal>@</Literal>'' brackets. So,
917 ``<Literal>@HaveGcc@</Literal>'' will be replaced by
918 ``<Literal>YES</Literal>'' or
919 ``<Literal>NO</Literal>'' depending on what
920 <Command>configure</Command> finds.
921 <Filename>mk/config.mk</Filename> is included by
922 every Makefile (directly or indirectly), so the
923 configuration information is thereby communicated to
924 all Makefiles.</para>
929 <Filename>mk/config.h.in</Filename><IndexTerm><Primary>config.h.in</Primary></IndexTerm>
931 <Filename>mk/config.h</Filename><IndexTerm><Primary>config.h</Primary></IndexTerm>.
932 The latter is <Literal>#include</Literal>d by
933 various C programs, which can thereby make use of
934 configuration information.</para>
938 <para><command>configure</command> takes some optional
939 arguments. Use <literal>./configure --help</literal> to
940 get a list of the available arguments. Here are some of
941 the ones you might need:</para>
945 <term><literal>--with-ghc=<parameter>path</parameter></literal></term>
946 <indexterm><primary><literal>--with-ghc</literal></primary>
949 <para>Specifies the path to an installed GHC which
950 you would like to use. This compiler will be used
951 for compiling GHC-specific code (eg. GHC itself).
952 This option <emphasis>cannot</emphasis> be
953 specified using <filename>build.mk</filename> (see
954 later), because <command>configure</command> needs
955 to auto-detect the version of GHC you're using.
956 The default is to look for a compiler named
957 <literal>ghc</literal> in your path.</para>
962 <term><literal>--with-hc=<parameter>path</parameter></literal></term>
963 <indexterm><primary><literal>--with-hhc</literal></primary>
966 <para>Specifies the path to any installed Haskell
967 compiler. This compiler will be used for
968 compiling generic Haskell code. The default is to
969 use <literal>ghc</literal>.</para>
974 <para><command>configure</command> caches the results of
975 its run in <Filename>config.cache</Filename>. Quite
976 often you don't want that; you're running
977 <Command>configure</Command> a second time because
978 something has changed. In that case, simply delete
979 <Filename>config.cache</Filename>.</para>
984 <Term>Step 3: build configuration.</Term>
987 Next, you say how this build of <Literal>fptools</Literal> is to differ from the
988 standard defaults by creating a new file <Filename>mk/build.mk</Filename><IndexTerm><Primary>build.mk</Primary></IndexTerm>
989 <Emphasis>in the build tree</Emphasis>. This file is the one and only file you edit
990 in the build tree, precisely because it says how this build differs
991 from the source. (Just in case your build tree does die, you might
992 want to keep a private directory of <Filename>build.mk</Filename> files, and use a
993 symbolic link in each build tree to point to the appropriate one.) So
994 <Filename>mk/build.mk</Filename> never exists in the source tree—you create one in
995 each build tree from the template. We'll discuss what to put in it
998 </ListItem></VarListEntry>
1003 And that's it for configuration. Simple, eh?
1006 <para>What do you put in your build-specific configuration file
1007 <filename>mk/build.mk</filename>? <Emphasis>For almost all
1008 purposes all you will do is put make variable definitions that
1009 override those in</Emphasis>
1010 <filename>mk/config.mk.in</filename>. The whole point of
1011 <filename>mk/config.mk.in</filename>—and its derived
1012 counterpart <filename>mk/config.mk</filename>—is to define
1013 the build configuration. It is heavily commented, as you will
1014 see if you look at it. So generally, what you do is look at
1015 <filename>mk/config.mk.in</filename>, and add definitions in
1016 <filename>mk/build.mk</filename> that override any of the
1017 <filename>config.mk</filename> definitions that you want to
1018 change. (The override occurs because the main boilerplate file,
1019 <filename>mk/boilerplate.mk</filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm>,
1020 includes <filename>build.mk</filename> after
1021 <filename>config.mk</filename>.)</para>
1023 <para>For example, <filename>config.mk.in</filename> contains
1024 the definition:</para>
1027 GhcHcOpts=-O -Rghc-timing
1030 <para>The accompanying comment explains that this is the list of
1031 flags passed to GHC when building GHC itself. For doing
1032 development, it is wise to add <literal>-DDEBUG</literal>, to
1033 enable debugging code. So you would add the following to
1034 <filename>build.mk</filename>:</para>
1036 <para>or, if you prefer,</para>
1039 GhcHcOpts += -DDEBUG
1042 <para>GNU <Command>make</Command> allows existing definitions to
1043 have new text appended using the ``<Literal>+=</Literal>''
1044 operator, which is quite a convenient feature.)</para>
1046 <para>If you want to remove the <literal>-O</literal> as well (a
1047 good idea when developing, because the turn-around cycle gets a
1048 lot quicker), you can just override
1049 <literal>GhcLibHcOpts</literal> altogether:</para>
1052 GhcHcOpts=-DDEBUG -Rghc-timing
1055 <para>When reading <filename>config.mk.in</filename>, remember
1056 that anything between ``@...@'' signs is going to be substituted
1057 by <Command>configure</Command> later. You
1058 <Emphasis>can</Emphasis> override the resulting definition if
1059 you want, but you need to be a bit surer what you are doing.
1060 For example, there's a line that says:</para>
1066 <para>This defines the Make variables <Constant>YACC</Constant>
1067 to the pathname for a <Command>yacc</Command> that
1068 <Command>configure</Command> finds somewhere. If you have your
1069 own pet <Command>yacc</Command> you want to use instead, that's
1070 fine. Just add this line to <filename>mk/build.mk</filename>:</para>
1076 <para>You do not <Emphasis>have</Emphasis> to have a
1077 <filename>mk/build.mk</filename> file at all; if you don't,
1078 you'll get all the default settings from
1079 <filename>mk/config.mk.in</filename>.</para>
1081 <para>You can also use <filename>build.mk</filename> to override
1082 anything that <Command>configure</Command> got wrong. One place
1083 where this happens often is with the definition of
1084 <Constant>FPTOOLS_TOP_ABS</Constant>: this
1085 variable is supposed to be the canonical path to the top of your
1086 source tree, but if your system uses an automounter then the
1087 correct directory is hard to find automatically. If you find
1088 that <Command>configure</Command> has got it wrong, just put the
1089 correct definition in <filename>build.mk</filename>.</para>
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 programs to
1185 make these changes take effect. In theory you should, however, say
1186 <Command>gmake clean</Command>, <Command>gmake all</Command>, because
1187 configuration option changes could affect anything—but in practice you
1188 are likely to know what's affected.
1194 <Title>Making things</Title>
1196 <para>At this point you have made yourself a fully-configured
1197 build tree, so you are ready to start building real
1200 <para>The first thing you need to know is that <Emphasis>you
1201 must use GNU <Command>make</Command>, usually called
1202 <Command>gmake</Command>, not standard Unix
1203 <Command>make</Command></Emphasis>. If you use standard Unix
1204 <Command>make</Command> you will get all sorts of error messages
1205 (but no damage) because the <Literal>fptools</Literal>
1206 <Command>Makefiles</Command> use GNU <Command>make</Command>'s
1207 facilities extensively.</para>
1209 <para>To just build the whole thing, <command>cd</command> to
1210 the top of your <literal>fptools</literal> tree and type
1211 <command>gmake</command>. This will prepare the tree and build
1212 the various projects in the correct order.</para>
1216 <Sect2 id="sec-standard-targets">
1217 <Title>Standard Targets</title>
1218 <IndexTerm><Primary>targets, standard makefile</Primary></IndexTerm>
1219 <IndexTerm><Primary>makefile targets</Primary></IndexTerm>
1221 <para>In any directory you should be able to make the following:
1226 <Term><Literal>boot</Literal>:</Term>
1228 <para>does the one-off preparation required to get ready for the real
1229 work. Notably, it does <Command>gmake depend</Command> in all
1230 directories that contain programs. It also builds the necessary tools
1231 for compilation to proceed.</para>
1233 <para>Invoking the <literal>boot</literal> target explicitly is not
1234 normally necessary. From the top-level <literal>fptools</literal>
1235 directory, invoking <literal>gmake</literal> causes <literal>gmake
1236 boot all</literal> to be invoked in each of the project
1237 subdirectories, in the order specified by
1238 <literal>$(AllTargets)</literal> in
1239 <literal>config.mk</literal>.</para>
1241 <para>If you're working in a subdirectory somewhere and need to update
1242 the dependencies, <literal>gmake boot</literal> is a good way to do it.</para>
1244 </ListItem></VarListEntry>
1246 <Term><Literal>all</Literal>:</Term>
1249 makes all the final target(s) for this Makefile.
1250 Depending on which directory you are in a ``final target'' may be an
1251 executable program, a library archive, a shell script, or a Postscript
1252 file. Typing <Command>gmake</Command> alone is generally the same as typing <Command>gmake all</Command>.
1254 </ListItem></VarListEntry>
1256 <Term><Literal>install</Literal>:</Term>
1259 installs the things built by <Literal>all</Literal>. Where does it
1260 install them? That is specified by
1261 <filename>mk/config.mk.in</filename>; you can override it in
1262 <filename>mk/build.mk</filename>, or by running
1263 <command>configure</command> with command-line arguments like
1264 <literal>--bindir=/home/simonpj/bin</literal>; see <literal>./configure
1265 --help</literal> for the full details.
1267 </ListItem></VarListEntry>
1269 <Term><Literal>uninstall</Literal>:</Term>
1272 reverses the effect of <Literal>install</Literal>.
1274 </ListItem></VarListEntry>
1277 <Term><Literal>clean</Literal>:</Term>
1280 Delete all files from the current directory that are normally created
1281 by building the program. Don't delete the files that record the
1282 configuration, or files generated by <Command>gmake boot</Command>.
1283 Also preserve files that could be made by building, but normally
1284 aren't because the distribution comes with them.</para>
1285 </ListItem></VarListEntry>
1288 <term><literal>distclean</literal>:</term>
1290 <para>Delete all files from the current directory that are created by
1291 configuring or building the program. If you have unpacked the source
1292 and built the program without creating any other files, <literal>make
1293 distclean</literal> should leave only the files that were in the
1294 distribution.</para>
1299 <term><literal>mostlyclean</literal>:</term>
1301 <para>Like <literal>clean</literal>, but may refrain from deleting a
1302 few files that people normally don't want to recompile.</para>
1307 <Term><Literal>maintainer-clean</Literal>:</Term>
1310 Delete everything from the current directory that can be reconstructed
1311 with this Makefile. This typically includes everything deleted by
1312 <literal>distclean</literal>, plus more: C source files produced by
1313 Bison, tags tables, Info files, and so on.</para>
1315 <para>One exception, however: <literal>make maintainer-clean</literal>
1316 should not delete <filename>configure</filename> even if
1317 <filename>configure</filename> can be remade using a rule in the
1318 <filename>Makefile</filename>. More generally, <literal>make
1319 maintainer-clean</literal> should not delete anything that needs to
1320 exist in order to run <filename>configure</filename> and then begin to
1321 build the program.</para>
1326 <Term><Literal>check</Literal>:</Term>
1331 </ListItem></VarListEntry>
1336 All of these standard targets automatically recurse into
1337 sub-directories. Certain other standard targets do not:
1344 <Term><Literal>configure</Literal>:</Term>
1347 is only available in the root directory
1348 <Constant>$(FPTOOLS_TOP)</Constant>; it has been discussed in <XRef LinkEnd="sec-build-config">.
1350 </ListItem></VarListEntry>
1352 <Term><Literal>depend</Literal>:</Term>
1355 make a <filename>.depend</filename> file in each directory that needs
1356 it. This <filename>.depend</filename> file contains mechanically-generated dependency
1357 information; for example, suppose a directory contains a Haskell
1358 source module <filename>Foo.lhs</filename> which imports another module <Literal>Baz</Literal>.
1359 Then the generated <filename>.depend</filename> file will contain the dependency:
1371 which says that the object file <filename>Foo.o</filename> depends on the interface file
1372 <filename>Baz.hi</filename> generated by compiling module <Literal>Baz</Literal>. The <filename>.depend</filename> file is
1373 automatically included by every Makefile.
1375 </ListItem></VarListEntry>
1377 <Term><Literal>binary-dist</Literal>:</Term>
1380 make a binary distribution. This is the
1381 target we use to build the binary distributions of GHC and Happy.
1383 </ListItem></VarListEntry>
1385 <Term><Literal>dist</Literal>:</Term>
1388 make a source distribution. Note that this target does “make
1389 distclean” as part of its work; don't use it if you want to keep
1392 </ListItem></VarListEntry>
1397 Most <filename>Makefile</filename>s have targets other than these. You can discover them by looking in the <filename>Makefile</filename> itself.
1403 <title>Using a project from the build tree</title>
1405 If you want to build GHC (say) and just use it direct from the build
1406 tree without doing <literal>make install</literal> first, you can run
1407 the in-place driver script:
1408 <filename>ghc/compiler/ghc-inplace</filename>.
1411 <para> Do <emphasis>NOT</emphasis> use
1412 <filename>ghc/compiler/ghc</filename>, or
1413 <filename>ghc/compiler/ghc-5.xx</filename>, as these are the scripts
1414 intended for installation, and contain hard-wired paths to the
1415 installed libraries, rather than the libraries in the build tree.
1419 Happy can similarly be run from the build tree, using
1420 <filename>happy/src/happy-inplace</filename>.
1425 <Title>Fast Making <IndexTerm><Primary>fastmake</Primary></IndexTerm>
1426 <IndexTerm><Primary>dependencies, omitting</Primary></IndexTerm>
1427 <IndexTerm><Primary>FAST, makefile
1428 variable</Primary></IndexTerm></Title>
1431 Sometimes the dependencies get in the way: if you've made a small
1432 change to one file, and you're absolutely sure that it won't affect
1433 anything else, but you know that <Command>make</Command> is going to rebuild everything
1434 anyway, the following hack may be useful:
1446 This tells the make system to ignore dependencies and just build what
1447 you tell it to. In other words, it's equivalent to temporarily
1448 removing the <filename>.depend</filename> file in the current directory (where
1449 <Command>mkdependHS</Command> and friends store their dependency information).
1453 A bit of history: GHC used to come with a <Command>fastmake</Command> script that did
1454 the above job, but GNU make provides the features we need to do it
1455 without resorting to a script. Also, we've found that fastmaking is
1456 less useful since the advent of GHC's recompilation checker (see the
1457 User's Guide section on "Separate Compilation").
1464 <Sect1 id="sec-makefile-arch">
1465 <Title>The <filename>Makefile</filename> architecture
1466 <IndexTerm><Primary>makefile architecture</Primary></IndexTerm></Title>
1469 <Command>make</Command> is great if everything works—you type <Command>gmake install</Command> and
1470 lo! the right things get compiled and installed in the right places.
1471 Our goal is to make this happen often, but somehow it often doesn't;
1472 instead some weird error message eventually emerges from the bowels of
1473 a directory you didn't know existed.
1477 The purpose of this section is to give you a road-map to help you figure
1478 out what is going right and what is going wrong.
1482 <Title>A small project</Title>
1485 To get started, let us look at the <filename>Makefile</filename> for an imaginary small
1486 <Literal>fptools</Literal> project, <Literal>small</Literal>. Each project in <Literal>fptools</Literal> has its own
1487 directory in <Constant>FPTOOLS_TOP</Constant>, so the <Literal>small</Literal> project will have its own
1488 directory <Constant>FPOOLS_TOP/small/</Constant>. Inside the <filename>small/</filename> directory there
1489 will be a <filename>Makefile</filename>, looking something like this:
1493 <IndexTerm><Primary>Makefile, minimal</Primary></IndexTerm>
1496 # Makefile for fptools project "small"
1499 include $(TOP)/mk/boilerplate.mk
1501 SRCS = $(wildcard *.lhs) $(wildcard *.c)
1504 include $(TOP)/target.mk
1510 This <filename>Makefile</filename> has three sections:
1519 The first section includes
1523 One of the most important
1524 features of GNU <Command>make</Command> that we use is the ability for a <filename>Makefile</filename> to
1525 include another named file, very like <Command>cpp</Command>'s <Literal>#include</Literal>
1530 a file of ``boilerplate'' code from the level
1531 above (which in this case will be
1532 <filename><Constant>FPTOOLS_TOP</Constant>/mk/boilerplate.mk</filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm>). As its name
1533 suggests, <filename>boilerplate.mk</filename> consists of a large quantity of standard
1534 <filename>Makefile</filename> code. We discuss this boilerplate in more detail in
1535 <XRef LinkEnd="sec-boiler">.
1536 <IndexTerm><Primary>include, directive in Makefiles</Primary></IndexTerm>
1537 <IndexTerm><Primary>Makefile inclusion</Primary></IndexTerm>
1539 Before the <Literal>include</Literal> statement, you must define the <Command>make</Command> variable
1540 <Constant>TOP</Constant><IndexTerm><Primary>TOP</Primary></IndexTerm> to be the directory containing the <filename>mk</filename> directory in
1541 which the <filename>boilerplate.mk</filename> file is. It is <Emphasis>not</Emphasis> OK to simply say
1545 include ../mk/boilerplate.mk # NO NO NO
1549 Why? Because the <filename>boilerplate.mk</filename> file needs to know where it is, so
1550 that it can, in turn, <Literal>include</Literal> other files. (Unfortunately, when an
1551 <Literal>include</Literal>d file does an <Literal>include</Literal>, the filename is treated relative to
1552 the directory in which <Command>gmake</Command> is being run, not the directory in
1553 which the <Literal>include</Literal>d sits.) In general, <Emphasis>every file <filename>foo.mk</filename>
1554 assumes that <filename><Constant>$(TOP)</Constant>/mk/foo.mk</filename> refers to itself.</Emphasis> It is up to the
1555 <filename>Makefile</filename> doing the <Literal>include</Literal> to ensure this is the case.
1557 Files intended for inclusion in other <filename>Makefile</filename>s are written to have
1558 the following property: <Emphasis>after <filename>foo.mk</filename> is <Literal>include</Literal>d, it leaves
1559 <Constant>TOP</Constant> containing the same value as it had just before the <Literal>include</Literal>
1560 statement</Emphasis>. In our example, this invariant guarantees that the
1561 <Literal>include</Literal> for <filename>target.mk</filename> will look in the same directory as that for
1562 <filename>boilerplate.mk</filename>.
1569 The second section defines the following standard <Command>make</Command>
1570 variables: <Constant>SRCS</Constant><IndexTerm><Primary>SRCS</Primary></IndexTerm> (the source files from which is to be
1571 built), and <Constant>HS_PROG</Constant><IndexTerm><Primary>HS_PROG</Primary></IndexTerm> (the executable binary to be
1572 built). We will discuss in more detail what the ``standard
1573 variables'' are, and how they affect what happens, in <XRef LinkEnd="sec-targets">.
1575 The definition for <Constant>SRCS</Constant> uses the useful GNU <Command>make</Command> construct
1576 <Literal>$(wildcard $pat$)</Literal><IndexTerm><Primary>wildcard</Primary></IndexTerm>, which expands to a list of all
1577 the files matching the pattern <Literal>pat</Literal> in the current directory. In
1578 this example, <Constant>SRCS</Constant> is set to the list of all the <filename>.lhs</filename> and <filename>.c</filename>
1579 files in the directory. (Let's suppose there is one of each,
1580 <filename>Foo.lhs</filename> and <filename>Baz.c</filename>.)
1587 The last section includes a second file of standard code,
1588 called <filename>target.mk</filename><IndexTerm><Primary>target.mk</Primary></IndexTerm>. It contains the rules that tell
1589 <Command>gmake</Command> how to make the standard targets (<Xref LinkEnd="sec-standard-targets">). Why, you ask,
1590 can't this standard code be part of <filename>boilerplate.mk</filename>? Good question.
1591 We discuss the reason later, in <Xref LinkEnd="sec-boiler-arch">.
1593 You do not <Emphasis>have</Emphasis> to <Literal>include</Literal> the <filename>target.mk</filename> file. Instead, you
1594 can write rules of your own for all the standard targets. Usually,
1595 though, you will find quite a big payoff from using the canned rules
1596 in <filename>target.mk</filename>; the price tag is that you have to understand what
1597 canned rules get enabled, and what they do (<Xref LinkEnd="sec-targets">).
1607 In our example <filename>Makefile</filename>, most of the work is done by the two
1608 <Literal>include</Literal>d files. When you say <Command>gmake all</Command>, the following things
1618 <Command>gmake</Command> figures out that the object files are <filename>Foo.o</filename> and
1619 <filename>Baz.o</filename>.
1626 It uses a boilerplate pattern rule to compile <filename>Foo.lhs</filename> to
1627 <filename>Foo.o</filename> using a Haskell compiler. (Which one? That is set in the
1628 build configuration.)
1635 It uses another standard pattern rule to compile <filename>Baz.c</filename> to
1636 <filename>Baz.o</filename>, using a C compiler. (Ditto.)
1643 It links the resulting <filename>.o</filename> files together to make <Literal>small</Literal>,
1644 using the Haskell compiler to do the link step. (Why not use <Command>ld</Command>?
1645 Because the Haskell compiler knows what standard libraries to link in.
1646 How did <Command>gmake</Command> know to use the Haskell compiler to do the link,
1647 rather than the C compiler? Because we set the variable <Constant>HS_PROG</Constant>
1648 rather than <Constant>C_PROG</Constant>.)
1658 All <filename>Makefile</filename>s should follow the above three-section format.
1664 <Title>A larger project</Title>
1667 Larger projects are usually structured into a number of sub-directories,
1668 each of which has its own <filename>Makefile</filename>. (In very large projects, this
1669 sub-structure might be iterated recursively, though that is rare.)
1670 To give you the idea, here's part of the directory structure for
1671 the (rather large) GHC project:
1684 ...source files for documentation...
1687 ...source files for driver...
1690 parser/...source files for parser...
1691 renamer/...source files for renamer...
1698 The sub-directories <filename>docs</filename>, <filename>driver</filename>, <filename>compiler</filename>, and so on, each
1699 contains a sub-component of GHC, and each has its own <filename>Makefile</filename>.
1700 There must also be a <filename>Makefile</filename> in <filename><Constant>$(FPTOOLS_TOP)</Constant>/ghc</filename>. It does most
1701 of its work by recursively invoking <Command>gmake</Command> on the <filename>Makefile</filename>s in the
1702 sub-directories. We say that <filename>ghc/Makefile</filename> is a <Emphasis>non-leaf
1703 <filename>Makefile</filename></Emphasis>, because it does little except organise its children,
1704 while the <filename>Makefile</filename>s in the sub-directories are all <Emphasis>leaf
1705 <filename>Makefile</filename>s</Emphasis>. (In principle the sub-directories might themselves
1706 contain a non-leaf <filename>Makefile</filename> and several sub-sub-directories, but
1707 that does not happen in GHC.)
1711 The <filename>Makefile</filename> in <filename>ghc/compiler</filename> is considered a leaf <filename>Makefile</filename> even
1712 though the <filename>ghc/compiler</filename> has sub-directories, because these sub-directories
1713 do not themselves have <filename>Makefile</filename>s in them. They are just used to structure
1714 the collection of modules that make up GHC, but all are managed by the
1715 single <filename>Makefile</filename> in <filename>ghc/compiler</filename>.
1719 You will notice that <filename>ghc/</filename> also contains a directory <filename>ghc/mk/</filename>. It
1720 contains GHC-specific <filename>Makefile</filename> boilerplate code. More precisely:
1729 <filename>ghc/mk/boilerplate.mk</filename> is included at the top of
1730 <filename>ghc/Makefile</filename>, and of all the leaf <filename>Makefile</filename>s in the
1731 sub-directories. It in turn <Literal>include</Literal>s the main boilerplate file
1732 <filename>mk/boilerplate.mk</filename>.
1740 <filename>ghc/mk/target.mk</filename> is <Literal>include</Literal>d at the bottom of
1741 <filename>ghc/Makefile</filename>, and of all the leaf <filename>Makefile</filename>s in the
1742 sub-directories. It in turn <Literal>include</Literal>s the file <filename>mk/target.mk</filename>.
1752 So these two files are the place to look for GHC-wide customisation
1753 of the standard boilerplate.
1758 <Sect2 id="sec-boiler-arch">
1759 <Title>Boilerplate architecture
1760 <IndexTerm><Primary>boilerplate architecture</Primary></IndexTerm>
1764 Every <filename>Makefile</filename> includes a <filename>boilerplate.mk</filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm> file
1765 at the top, and <filename>target.mk</filename><IndexTerm><Primary>target.mk</Primary></IndexTerm> file at the bottom. In
1766 this section we discuss what is in these files, and why there have to
1767 be two of them. In general:
1776 <filename>boilerplate.mk</filename> consists of:
1782 <Emphasis>Definitions of millions of <Command>make</Command> variables</Emphasis> that
1783 collectively specify the build configuration. Examples:
1784 <Constant>HC_OPTS</Constant><IndexTerm><Primary>HC_OPTS</Primary></IndexTerm>, the options to feed to the Haskell compiler;
1785 <Constant>NoFibSubDirs</Constant><IndexTerm><Primary>NoFibSubDirs</Primary></IndexTerm>, the sub-directories to enable within the
1786 <Literal>nofib</Literal> project; <Constant>GhcWithHc</Constant><IndexTerm><Primary>GhcWithHc</Primary></IndexTerm>, the name of the Haskell
1787 compiler to use when compiling GHC in the <Literal>ghc</Literal> project.
1793 <Emphasis>Standard pattern rules</Emphasis> that tell <Command>gmake</Command> how to construct one
1801 <filename>boilerplate.mk</filename> needs to be <Literal>include</Literal>d at the <Emphasis>top</Emphasis>
1802 of each <filename>Makefile</filename>, so that the user can replace the
1803 boilerplate definitions or pattern rules by simply giving a new
1804 definition or pattern rule in the <filename>Makefile</filename>. <Command>gmake</Command>
1805 simply takes the last definition as the definitive one.
1807 Instead of <Emphasis>replacing</Emphasis> boilerplate definitions, it is also quite
1808 common to <Emphasis>augment</Emphasis> them. For example, a <filename>Makefile</filename> might say:
1816 thereby adding ``<Option>-O</Option>'' to the end of <Constant>SRC_HC_OPTS</Constant><IndexTerm><Primary>SRC_HC_OPTS</Primary></IndexTerm>.
1823 <filename>target.mk</filename> contains <Command>make</Command> rules for the standard
1824 targets described in <Xref LinkEnd="sec-standard-targets">. These rules are selectively included,
1825 depending on the setting of certain <Command>make</Command> variables. These
1826 variables are usually set in the middle section of the
1827 <filename>Makefile</filename> between the two <Literal>include</Literal>s.
1829 <filename>target.mk</filename> must be included at the end (rather than being part of
1830 <filename>boilerplate.mk</filename>) for several tiresome reasons:
1837 <Command>gmake</Command> commits target and dependency lists earlier than
1838 it should. For example, <FIlename>target.mk</FIlename> has a rule that looks like
1843 $(HS_PROG) : $(OBJS)
1844 $(HC) $(LD_OPTS) $< -o $@
1848 If this rule was in <filename>boilerplate.mk</filename> then <Constant>$(HS_PROG)</Constant><IndexTerm><Primary>HS_PROG</Primary></IndexTerm>
1849 and <Constant>$(OBJS)</Constant><IndexTerm><Primary>OBJS</Primary></IndexTerm> would not have their final values at the
1850 moment <Command>gmake</Command> encountered the rule. Alas, <Command>gmake</Command> takes a snapshot
1851 of their current values, and wires that snapshot into the rule. (In
1852 contrast, the commands executed when the rule ``fires'' are only
1853 substituted at the moment of firing.) So, the rule must follow the
1854 definitions given in the <filename>Makefile</filename> itself.
1861 Unlike pattern rules, ordinary rules cannot be overriden or
1862 replaced by subsequent rules for the same target (at least, not without an
1863 error message). Including ordinary rules in <filename>boilerplate.mk</filename> would
1864 prevent the user from writing rules for specific targets in specific cases.
1871 There are a couple of other reasons I've forgotten, but it doesn't
1887 <Sect2 id="sec-boiler">
1888 <Title>The main <filename>mk/boilerplate.mk</filename> file
1890 <IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm></Title>
1893 If you look at <filename><Constant>$(FPTOOLS_TOP)</Constant>/mk/boilerplate.mk</filename> you will find
1894 that it consists of the following sections, each held in a separate
1902 <Term><filename>config.mk</filename><IndexTerm><Primary>config.mk</Primary></IndexTerm></Term>
1905 is the build configuration file we
1906 discussed at length in <Xref LinkEnd="sec-build-config">.
1908 </ListItem></VarListEntry>
1910 <Term><filename>paths.mk</filename><IndexTerm><Primary>paths.mk</Primary></IndexTerm></Term>
1913 defines <Command>make</Command> variables for
1914 pathnames and file lists. In particular, it gives definitions for:
1921 <Term><Constant>SRCS</Constant><IndexTerm><Primary>SRCS</Primary></IndexTerm>:</Term>
1924 all source files in the current directory.
1926 </ListItem></VarListEntry>
1928 <Term><Constant>HS_SRCS</Constant><IndexTerm><Primary>HS_SRCS</Primary></IndexTerm>:</Term>
1931 all Haskell source files in the current directory.
1932 It is derived from <Constant>$(SRCS)</Constant>, so if you override <Constant>SRCS</Constant> with a new value
1933 <Constant>HS_SRCS</Constant> will follow suit.
1935 </ListItem></VarListEntry>
1937 <Term><Constant>C_SRCS</Constant><IndexTerm><Primary>C_SRCS</Primary></IndexTerm>:</Term>
1940 similarly for C source files.
1942 </ListItem></VarListEntry>
1944 <Term><Constant>HS_OBJS</Constant><IndexTerm><Primary>HS_OBJS</Primary></IndexTerm>:</Term>
1947 the <filename>.o</filename> files derived from <Constant>$(HS_SRCS)</Constant>.
1949 </ListItem></VarListEntry>
1951 <Term><Constant>C_OBJS</Constant><IndexTerm><Primary>C_OBJS</Primary></IndexTerm>:</Term>
1954 similarly for <Constant>$(C_SRCS)</Constant>.
1956 </ListItem></VarListEntry>
1958 <Term><Constant>OBJS</Constant><IndexTerm><Primary>OBJS</Primary></IndexTerm>:</Term>
1961 the concatenation of <Constant>$(HS_OBJS)</Constant> and <Constant>$(C_OBJS)</Constant>.
1963 </ListItem></VarListEntry>
1968 Any or all of these definitions can easily be overriden by giving new
1969 definitions in your <filename>Makefile</filename>. For example, if there are things in
1970 the current directory that look like source files but aren't, then
1971 you'll need to set <Constant>SRCS</Constant> manually in your <filename>Makefile</filename>. The other
1972 definitions will then work from this new definition.
1976 What, exactly, does <filename>paths.mk</filename> consider a ``source file'' to be? It's
1977 based on the file's suffix (e.g. <filename>.hs</filename>, <filename>.lhs</filename>, <filename>.c</filename>, <filename>.lc</filename>, etc), but
1978 this is the kind of detail that changes, so rather than
1979 enumerate the source suffices here the best thing to do is to look in
1980 <filename>paths.mk</filename>.
1982 </ListItem></VarListEntry>
1984 <Term><filename>opts.mk</filename><IndexTerm><Primary>opts.mk</Primary></IndexTerm></Term>
1987 defines <Command>make</Command> variables for option
1988 strings to pass to each program. For example, it defines
1989 <Constant>HC_OPTS</Constant><IndexTerm><Primary>HC_OPTS</Primary></IndexTerm>, the option strings to pass to the Haskell
1990 compiler. See <Xref LinkEnd="sec-suffix">.
1992 </ListItem></VarListEntry>
1994 <Term><filename>suffix.mk</filename><IndexTerm><Primary>suffix.mk</Primary></IndexTerm></Term>
1997 defines standard pattern rules—see <Xref LinkEnd="sec-suffix">.
1999 </ListItem></VarListEntry>
2004 Any of the variables and pattern rules defined by the boilerplate file
2005 can easily be overridden in any particular <filename>Makefile</filename>, because the
2006 boilerplate <Literal>include</Literal> comes first. Definitions after this <Literal>include</Literal>
2007 directive simply override the default ones in <filename>boilerplate.mk</filename>.
2012 <Sect2 id="sec-suffix">
2013 <Title>Pattern rules and options
2015 <IndexTerm><Primary>Pattern rules</Primary></IndexTerm></Title>
2018 The file <filename>suffix.mk</filename><IndexTerm><Primary>suffix.mk</Primary></IndexTerm> defines standard <Emphasis>pattern
2019 rules</Emphasis> that say how to build one kind of file from another, for
2020 example, how to build a <filename>.o</filename> file from a <filename>.c</filename> file. (GNU <Command>make</Command>'s
2021 <Emphasis>pattern rules</Emphasis> are more powerful and easier to use than Unix
2022 <Command>make</Command>'s <Emphasis>suffix rules</Emphasis>.)
2026 Almost all the rules look something like this:
2034 $(CC) $(CC_OPTS) -c $< -o $@
2040 Here's how to understand the rule. It says that
2041 <Emphasis>something</Emphasis><filename>.o</filename> (say <filename>Foo.o</filename>) can be built from
2042 <Emphasis>something</Emphasis><filename>.c</filename> (<filename>Foo.c</filename>), by invoking the C compiler
2043 (path name held in <Constant>$(CC)</Constant>), passing to it the options
2044 <Constant>$(CC_OPTS)</Constant> and the rule's dependent file of the rule
2045 <Literal>$<</Literal> (<filename>Foo.c</filename> in this case), and putting the result in
2046 the rule's target <Literal>$@</Literal> (<filename>Foo.o</filename> in this case).
2050 Every program is held in a <Command>make</Command> variable defined in
2051 <filename>mk/config.mk</filename>—look in <filename>mk/config.mk</filename> for the
2052 complete list. One important one is the Haskell compiler, which is
2053 called <Constant>$(HC)</Constant>.
2057 Every program's options are are held in a <Command>make</Command> variables called
2058 <Constant><prog>_OPTS</Constant>. the <Constant><prog>_OPTS</Constant> variables are defined in
2059 <filename>mk/opts.mk</filename>. Almost all of them are defined like this:
2065 CC_OPTS = $(SRC_CC_OPTS) $(WAY$(_way)_CC_OPTS) $($*_CC_OPTS) $(EXTRA_CC_OPTS)
2071 The four variables from which <Constant>CC_OPTS</Constant> is built have the following meaning:
2078 <Term><Constant>SRC_CC_OPTS</Constant><IndexTerm><Primary>SRC_CC_OPTS</Primary></IndexTerm>:</Term>
2081 options passed to all C
2084 </ListItem></VarListEntry>
2086 <Term><Constant>WAY_<way>_CC_OPTS</Constant>:</Term>
2090 compilations for way <Literal><way></Literal>. For example,
2091 <Constant>WAY_mp_CC_OPTS</Constant> gives options to pass to the C compiler when
2092 compiling way <Literal>mp</Literal>. The variable <Constant>WAY_CC_OPTS</Constant> holds
2093 options to pass to the C compiler when compiling the standard way.
2094 (<Xref LinkEnd="sec-ways"> dicusses multi-way
2097 </ListItem></VarListEntry>
2099 <Term><Constant><module>_CC_OPTS</Constant>:</Term>
2103 pass to the C compiler that are specific to module <Literal><module></Literal>. For example, <Constant>SMap_CC_OPTS</Constant> gives the specific options
2104 to pass to the C compiler when compiling <filename>SMap.c</filename>.
2106 </ListItem></VarListEntry>
2108 <Term><Constant>EXTRA_CC_OPTS</Constant><IndexTerm><Primary>EXTRA_CC_OPTS</Primary></IndexTerm>:</Term>
2111 extra options to pass to all
2112 C compilations. This is intended for command line use, thus:
2118 gmake libHS.a EXTRA_CC_OPTS="-v"
2122 </ListItem></VarListEntry>
2128 <Sect2 id="sec-targets">
2129 <Title>The main <filename>mk/target.mk</filename> file
2131 <IndexTerm><Primary>target.mk</Primary></IndexTerm></Title>
2134 <filename>target.mk</filename> contains canned rules for all the standard targets
2135 described in <Xref LinkEnd="sec-standard-targets">. It is complicated by the fact that you don't want all of
2136 these rules to be active in every <filename>Makefile</filename>. Rather than have a
2137 plethora of tiny files which you can include selectively, there is a
2138 single file, <filename>target.mk</filename>, which selectively includes rules based on
2139 whether you have defined certain variables in your <filename>Makefile</filename>. This
2140 section explains what rules you get, what variables control them, and
2141 what the rules do. Hopefully, you will also get enough of an idea of
2142 what is supposed to happen that you can read and understand any weird
2143 special cases yourself.
2150 <Term><Constant>HS_PROG</Constant><IndexTerm><Primary>HS_PROG</Primary></IndexTerm>.</Term>
2153 If <Constant>HS_PROG</Constant> is defined, you get
2154 rules with the following targets:
2158 <Term><filename>HS_PROG</filename><IndexTerm><Primary>HS_PROG</Primary></IndexTerm></Term>
2161 itself. This rule links <Constant>$(OBJS)</Constant>
2162 with the Haskell runtime system to get an executable called
2163 <Constant>$(HS_PROG)</Constant>.
2165 </ListItem></VarListEntry>
2167 <Term><Literal>install</Literal><IndexTerm><Primary>install</Primary></IndexTerm></Term>
2170 installs <Constant>$(HS_PROG)</Constant>
2171 in <Constant>$(bindir)</Constant>.
2173 </ListItem></VarListEntry>
2176 </ListItem></VarListEntry>
2178 <Term><Constant>C_PROG</Constant><IndexTerm><Primary>C_PROG</Primary></IndexTerm></Term>
2181 is similar to <Constant>HS_PROG</Constant>, except that
2182 the link step links <Constant>$(C_OBJS)</Constant> with the C runtime system.
2184 </ListItem></VarListEntry>
2186 <Term><Constant>LIBRARY</Constant><IndexTerm><Primary>LIBRARY</Primary></IndexTerm></Term>
2189 is similar to <Constant>HS_PROG</Constant>, except that
2190 it links <Constant>$(LIB_OBJS)</Constant> to make the library archive <Constant>$(LIBRARY)</Constant>, and
2191 <Literal>install</Literal> installs it in <Constant>$(libdir)</Constant>.
2193 </ListItem></VarListEntry>
2195 <Term><Constant>LIB_DATA</Constant><IndexTerm><Primary>LIB_DATA</Primary></IndexTerm></Term>
2200 </ListItem></VarListEntry>
2202 <Term><Constant>LIB_EXEC</Constant><IndexTerm><Primary>LIB_EXEC</Primary></IndexTerm></Term>
2207 </ListItem></VarListEntry>
2209 <Term><Constant>HS_SRCS</Constant><IndexTerm><Primary>HS_SRCS</Primary></IndexTerm>, <Constant>C_SRCS</Constant><IndexTerm><Primary>C_SRCS</Primary></IndexTerm>.</Term>
2212 If <Constant>HS_SRCS</Constant>
2213 is defined and non-empty, a rule for the target <Literal>depend</Literal> is included,
2214 which generates dependency information for Haskell programs.
2215 Similarly for <Constant>C_SRCS</Constant>.
2217 </ListItem></VarListEntry>
2222 All of these rules are ``double-colon'' rules, thus
2228 install :: $(HS_PROG)
2229 ...how to install it...
2235 GNU <Command>make</Command> treats double-colon rules as separate entities. If there
2236 are several double-colon rules for the same target it takes each in
2237 turn and fires it if its dependencies say to do so. This means that
2238 you can, for example, define both <Constant>HS_PROG</Constant> and <Constant>LIBRARY</Constant>, which will
2239 generate two rules for <Literal>install</Literal>. When you type <Command>gmake install</Command> both
2240 rules will be fired, and both the program and the library will be
2241 installed, just as you wanted.
2246 <Sect2 id="sec-subdirs">
2249 <IndexTerm><Primary>recursion, in makefiles</Primary></IndexTerm>
2250 <IndexTerm><Primary>Makefile, recursing into subdirectories</Primary></IndexTerm></Title>
2253 In leaf <filename>Makefile</filename>s the variable <Constant>SUBDIRS</Constant><IndexTerm><Primary>SUBDIRS</Primary></IndexTerm> is undefined.
2254 In non-leaf <filename>Makefile</filename>s, <Constant>SUBDIRS</Constant> is set to the list of
2255 sub-directories that contain subordinate <filename>Makefile</filename>s. <Emphasis>It is up to
2256 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.
2260 When <Constant>SUBDIRS</Constant> is defined, <filename>target.mk</filename> includes a rather
2261 neat rule for the standard targets (<Xref LinkEnd="sec-standard-targets"> that simply invokes
2262 <Command>make</Command> recursively in each of the sub-directories.
2266 <Emphasis>These recursive invocations are guaranteed to occur in the order
2267 in which the list of directories is specified in <Constant>SUBDIRS</Constant>. </Emphasis>This
2268 guarantee can be important. For example, when you say <Command>gmake boot</Command> it
2269 can be important that the recursive invocation of <Command>make boot</Command> is done
2270 in one sub-directory (the include files, say) before another (the
2271 source files). Generally, put the most independent sub-directory
2272 first, and the most dependent last.
2277 <Sect2 id="sec-ways">
2278 <Title>Way management
2280 <IndexTerm><Primary>way management</Primary></IndexTerm></Title>
2283 We sometimes want to build essentially the same system in several
2284 different ``ways''. For example, we want to build GHC's <Literal>Prelude</Literal>
2285 libraries with and without profiling, with and without concurrency,
2286 and so on, so that there is an appropriately-built library archive to
2287 link with when the user compiles his program. It would be possible to
2288 have a completely separate build tree for each such ``way'', but it
2289 would be horribly bureaucratic, especially since often only parts of
2290 the build tree need to be constructed in multiple ways.
2294 Instead, the <filename>target.mk</filename><IndexTerm><Primary>target.mk</Primary></IndexTerm> contains some clever magic to
2295 allow you to build several versions of a system; and to control
2296 locally how many versions are built and how they differ. This section
2301 The files for a particular way are distinguished by munging the
2302 suffix. The ``normal way'' is always built, and its files have the
2303 standard suffices <filename>.o</filename>, <filename>.hi</filename>, and so on. In addition, you can build
2304 one or more extra ways, each distinguished by a <Emphasis>way tag</Emphasis>. The
2305 object files and interface files for one of these extra ways are
2306 distinguished by their suffix. For example, way <Literal>mp</Literal> has files
2307 <filename>.mp_o</filename> and <filename>.mp_hi</filename>. Library archives have their way tag the other
2308 side of the dot, for boring reasons; thus, <filename>libHS_mp.a</filename>.
2312 A <Command>make</Command> variable called <Constant>way</Constant> holds the current way tag. <Emphasis><Constant>way</Constant>
2313 is only ever set on the command line of a recursive invocation of
2314 <Command>gmake</Command>.</Emphasis> It is never set inside a <filename>Makefile</filename>. So it is a global
2315 constant for any one invocation of <Command>gmake</Command>. Two other <Command>make</Command>
2316 variables, <Constant>way_</Constant> and <Constant>_way</Constant> are immediately derived from <Constant>$(way)</Constant> and
2317 never altered. If <Constant>way</Constant> is not set, then neither are <Constant>way_</Constant> and
2318 <Constant>_way</Constant>, and the invocation of <Command>make</Command> will build the ``normal way''.
2319 If <Constant>way</Constant> is set, then the other two variables are set in sympathy.
2320 For example, if <Constant>$(way)</Constant> is ``<Literal>mp</Literal>'', then <Constant>way_</Constant> is set to ``<Literal>mp_</Literal>''
2321 and <Constant>_way</Constant> is set to ``<Literal>_mp</Literal>''. These three variables are then used
2322 when constructing file names.
2326 So how does <Command>make</Command> ever get recursively invoked with <Constant>way</Constant> set? There
2327 are two ways in which this happens:
2336 For some (but not all) of the standard targets, when in a leaf
2337 sub-directory, <Command>make</Command> is recursively invoked for each way tag in
2338 <Constant>$(WAYS)</Constant>. You set <Constant>WAYS</Constant> to the list of way tags you want these
2339 targets built for. The mechanism here is very much like the recursive
2340 invocation of <Command>make</Command> in sub-directories (<Xref LinkEnd="sec-subdirs">).
2342 It is up to you to set <Constant>WAYS</Constant> in your <filename>Makefile</filename>; this is how you
2343 control what ways will get built.
2349 For a useful collection of
2350 targets (such as <filename>libHS_mp.a</filename>, <filename>Foo.mp_o</filename>) there is a rule which
2351 recursively invokes <Command>make</Command> to make the specified target, setting the
2352 <Constant>way</Constant> variable. So if you say <Command>gmake Foo.mp_o</Command> you should see a
2353 recursive invocation <Command>gmake Foo.mp_o way=mp</Command>, and <Emphasis>in this
2354 recursive invocation the pattern rule for compiling a Haskell file
2355 into a <filename>.o</filename> file will match</Emphasis>. The key pattern rules (in <filename>suffix.mk</filename>)
2361 $(HC) $(HC_OPTS) $< -o $@
2376 <Title>When the canned rule isn't right</Title>
2379 Sometimes the canned rule just doesn't do the right thing. For
2380 example, in the <Literal>nofib</Literal> suite we want the link step to print out
2381 timing information. The thing to do here is <Emphasis>not</Emphasis> to define
2382 <Constant>HS_PROG</Constant> or <Constant>C_PROG</Constant>, and instead define a special purpose rule in
2383 your own <filename>Makefile</filename>. By using different variable names you will avoid
2384 the canned rules being included, and conflicting with yours.
2391 <Sect1 id="sec-booting-from-C">
2392 <Title>Booting/porting from C (<filename>.hc</filename>) files
2394 <IndexTerm><Primary>building GHC from .hc files</Primary></IndexTerm>
2395 <IndexTerm><Primary>booting GHC from .hc files</Primary></IndexTerm>
2396 <IndexTerm><Primary>porting GHC</Primary></IndexTerm></Title>
2399 This section is for people trying to get GHC going by using the supplied
2400 intermediate C (<filename>.hc</filename>) files. This would probably be
2401 because no binaries have been provided, or because the machine is not ``fully
2406 The intermediate C files are normally made available together with a source
2407 release, please check the announce message for exact directions of where to
2408 find them. If we haven't made them available or you can't find them, please
2413 Assuming you've got them, unpack them on top of a fresh source tree. This
2414 will place matching <filename>.hc</filename> files next to the corresponding
2415 Haskell source in the compiler subdirectory <filename>ghc</filename> and in
2416 the language package of hslibs (i.e., in <filename>hslibs/lang</filename>).
2417 Then follow the `normal' instructions in <Xref
2418 LinkEnd="sec-building-from-source"> for setting up a build tree.
2422 The actual build process is fully automated by the
2423 <filename>hc-build</filename> script located in the
2424 <filename>distrib</filename> directory. If you eventually want to install GHC
2425 into the directory <filename>INSTALL_DIRECTORY</filename>, the following
2426 command will execute the whole build process (it won't install yet):
2429 foo% distrib/hc-build --prefix=INSTALL_DIRECTORY
2431 <IndexTerm><Primary>--hc-build</Primary></IndexTerm>
2433 By default, the installation directory is <filename>/usr/local</filename>. If
2434 that is what you want, you may omit the argument to
2435 <filename>hc-build</filename>. Generally, any option given to
2436 <filename>hc-build</filename> is passed through to the configuration script
2437 <filename>configure</filename>. If <filename>hc-build</filename>
2438 successfully completes the build process, you can install the resulting
2439 system, as normal, with
2446 That's the mechanics of the boot process, but, of course, if you're
2447 trying to boot on a platform that is not supported and significantly
2448 `different' from any of the supported ones, this is only the start of
2449 the adventure…(ToDo: porting tips—stuff to look out for, etc.)
2454 <Sect1 id="sec-build-pitfalls">
2455 <Title>Known pitfalls in building Glasgow Haskell
2457 <IndexTerm><Primary>problems, building</Primary></IndexTerm>
2458 <IndexTerm><Primary>pitfalls, in building</Primary></IndexTerm>
2459 <IndexTerm><Primary>building pitfalls</Primary></IndexTerm></Title>
2462 WARNINGS about pitfalls and known ``problems'':
2471 One difficulty that comes up from time to time is running out of space
2472 in <literal>TMPDIR</literal>. (It is impossible for the configuration stuff to
2473 compensate for the vagaries of different sysadmin approaches to temp
2475 <IndexTerm><Primary>tmp, running out of space in</Primary></IndexTerm>
2477 The quickest way around it is <Command>setenv TMPDIR /usr/tmp</Command><IndexTerm><Primary>TMPDIR</Primary></IndexTerm> or
2478 even <Command>setenv TMPDIR .</Command> (or the equivalent incantation with your shell
2481 The best way around it is to say
2484 export TMPDIR=<dir>
2487 in your <filename>build.mk</filename> file.
2488 Then GHC and the other <Literal>fptools</Literal> programs will use the appropriate directory
2497 In compiling some support-code bits, e.g., in <filename>ghc/rts/gmp</filename> and even
2498 in <filename>ghc/lib</filename>, you may get a few C-compiler warnings. We think these
2506 When compiling via C, you'll sometimes get ``warning: assignment from
2507 incompatible pointer type'' out of GCC. Harmless.
2514 Similarly, <Command>ar</Command>chiving warning messages like the following are not
2518 ar: filename GlaIOMonad__1_2s.o truncated to GlaIOMonad_
2519 ar: filename GlaIOMonad__2_2s.o truncated to GlaIOMonad_
2529 In compiling the compiler proper (in <filename>compiler/</filename>), you <Emphasis>may</Emphasis>
2530 get an ``Out of heap space'' error message. These can vary with the
2531 vagaries of different systems, it seems. The solution is simple:
2538 If you're compiling with GHC 4.00 or later, then the
2539 <Emphasis>maximum</Emphasis> heap size must have been reached. This
2540 is somewhat unlikely, since the maximum is set to 64M by default.
2541 Anyway, you can raise it with the
2542 <Option>-optCrts-M<size></Option> flag (add this flag to
2543 <Constant><module>_HC_OPTS</Constant>
2544 <Command>make</Command> variable in the appropriate
2545 <filename>Makefile</filename>).
2552 For GHC < 4.00, add a suitable <Option>-H</Option> flag to the <filename>Makefile</filename>, as
2561 and try again: <Command>gmake</Command>. (see <Xref LinkEnd="sec-suffix"> for information about
2562 <Constant><module>_HC_OPTS</Constant>.)
2564 Alternatively, just cut to the chase:
2568 % make EXTRA_HC_OPTS=-optCrts-M128M
2577 If you try to compile some Haskell, and you get errors from GCC about
2578 lots of things from <filename>/usr/include/math.h</filename>, then your GCC was
2579 mis-installed. <Command>fixincludes</Command> wasn't run when it should've been.
2581 As <Command>fixincludes</Command> is now automagically run as part of GCC installation,
2582 this bug also suggests that you have an old GCC.
2590 You <Emphasis>may</Emphasis> need to re-<Command>ranlib</Command><IndexTerm><Primary>ranlib</Primary></IndexTerm> your libraries (on Sun4s).
2594 % cd $(libdir)/ghc-x.xx/sparc-sun-sunos4
2595 % foreach i ( `find . -name '*.a' -print` ) # or other-shell equiv...
2597 ? # or, on some machines: ar s $i
2602 We'd be interested to know if this is still necessary.
2610 GHC's sources go through <Command>cpp</Command> before being compiled, and <Command>cpp</Command> varies
2611 a bit from one Unix to another. One particular gotcha is macro calls
2616 SLIT("Hello, world")
2620 Some <Command>cpp</Command>s treat the comma inside the string as separating two macro
2621 arguments, so you get
2625 :731: macro `SLIT' used with too many (2) args
2629 Alas, <Command>cpp</Command> doesn't tell you the offending file!
2631 Workaround: don't put weird things in string args to <Command>cpp</Command> macros.
2642 <Sect1 id="winbuild"><Title>Notes for building under Windows</Title>
2645 This section summarises how to get the utilities you need on your
2646 Win95/98/NT/2000 machine to use CVS and build GHC. Similar notes for
2647 installing and running GHC may be found in the user guide. In general,
2648 Win95/Win98 behave the same, and WinNT/Win2k behave the same.
2649 You should read the GHC installation guide sections on Windows (in the user
2650 guide) before continuing to read these notes.
2654 Because of various hard-wired infelicities, you need to copy
2655 <Filename>bash.exe</Filename> (from GHC's <Filename>extra-bin</Filename>
2656 directory) and <Filename>perl.exe</Filename> (from GHC's
2657 <Filename>bin</Filename> directory) to <Filename>/bin</Filename> (discover
2658 where your Cygwin root directory is by typign <Command>mount</Command>). If
2659 you want to use bash as the shell in Emacs, you need to set the
2660 <Constant>SHELL</Constant> environment variable to point to
2661 <Filename>bash.exe</Filename>; similarly, if you want to use CVS, then
2662 <Constant>CVS_RSH</Constant> must point to <Filename>ssh.exe</Filename>,
2663 which is also in GHC's <Filename>extra-bin</Filename> directory.
2667 Before you start, you need to make sure that the user environment variable
2668 <Constant>MAKE_MODE</Constant> is set to <Literal>UNIX</Literal>. If you
2669 don't do this you get very weird messages when you type
2670 <Command>make</Command>, such as:
2673 /c: /c: No such file or directory</Screen>
2675 <Sect2><Title>Configuring ssh</Title>
2681 Generate a key, by running <filename>c:/user/local/bin/ssh-keygen1</filename>.
2682 This generates a public key in <filename>.ssh/identity.pub</filename>, and a
2683 private key in <filename>.ssh/identity</filename>
2687 In response to the 'Enter passphrase' question, just hit
2688 return (i.e. use an empty passphrase). The passphrase is
2689 a password that protects your private key. But it's a pain
2690 to type this passphrase everytime you use <Command>ssh</Command>, so the best
2691 thing to do is simply to protect your <filename>.ssh</filename> directory, and
2692 <filename>.ssh/identity</filename> from access by anyone else. To do this
2693 right-click your <filename>.ssh</filename> directory, and select Properties.
2694 If you are not on the access control list, add yourself, and
2695 give yourself full permissions (the second panel).
2696 Remove everyone else from the access control list. (Don't
2697 leave them there but deny them access, because 'they' may be
2698 a list that includes you!)
2702 If you have problems running <Command>ssh-keygen1</Command>
2703 from within <Command>bash</Command>, start up <filename>cmd.exe</filename> and run it as follows:
2707 c:\tmp> set CYGWIN32=tty
2708 c:\tmp> c:/user/local/bin/ssh-keygen1
2714 If you don't have an account on <Literal>cvs.haskell.org</Literal>, send
2715 your <filename>.ssh/identity.pub</filename> to the CVS repository administrator
2716 (currently Jeff Lewis <Email>jlewis@cse.ogi.edu</Email>). He will set up
2721 If you do have an account on <Literal>cvs.haskell.org</Literal>, use TeraTerm
2722 to logon to it. Once in, copy the
2723 key that <Command>ssh-keygen1</Command> deposited in <filename>/.ssh/identity.pub</filename> into
2724 your <filename>~/.ssh/authorized_keys</filename>. Make sure that the new version
2725 of <filename>authorized_keys</filename> still has 600 file permission.
2734 <Sect2><Title>Configuring CVS</Title>
2740 From the System control panel,
2741 set the following <Emphasis>user</Emphasis> environment variables (see the GHC user guide)
2747 <Constant>HOME</Constant>: points to your home directory. This is where CVS
2748 will look for its <filename>.cvsrc</filename> file.
2754 <Constant>CVS_RSH</Constant>: <filename>c:/path_to_Cygwin/bin/ssh</filename>
2760 <Constant>CVSROOT</Constant>: <Literal>:ext:username@cvs.haskell.org:/home/cvs/root</Literal>,
2761 where <Literal>username</Literal> is your userid
2767 <Constant>CVSEDITOR</Constant>: <filename>bin/gnuclient.exe</filename> if you want to use an Emacs buffer for typing in those long commit messages.
2775 Put the following in <filename>$HOME/.cvsrc</filename>:
2786 These are the default options for the specified CVS commands,
2787 and represent better defaults than the usual ones. (Feel
2788 free to change them.)
2792 Filenames starting with <filename>.</filename> were illegal in
2793 the 8.3 DOS filesystem, but that restriction should have
2794 been lifted by now (i.e., you're using VFAT or later filesystems.) If
2795 you're still having problems creating it, don't worry; <filename>.cvsrc</filename> is entirely
2802 Try doing <Command>cvs co fpconfig</Command>. All being well, bytes should
2803 start to trickle through, leaving a directory <filename>fptools</filename>
2804 in your current directory. (You can <Command>rm</Command> it if you don't
2805 want to keep it.) The following messages appear to be harmless:
2809 setsockopt IPTOS_LOWDELAY: Invalid argument
2810 setsockopt IPTOS_THROUGHPUT: Invalid argument
2814 At this point I found that CVS tried to invoke a little dialogue with
2815 me (along the lines of `do you want to talk to this host?'), but
2816 for some reason bombed out. This was from a bash shell running in Emacs.
2817 I solved this by invoking a Cygnus shell, and running CVS from there.
2818 Once things are dialogue free, it seems to work OK from within Emacs.
2824 If you want to check out part of large tree, proceed as follows:
2828 cvs -f checkout -l papers
2834 This sequence checks out the <Literal>papers</Literal> module, but none
2835 of its sub-directories.
2836 The "<Option>-l</Option>" flag says not to check out sub-directories.
2837 The "<Option>-f</Option>" flag says not to read the <filename>.cvsrc</filename> file
2838 whose <Option>-P</Option> default (don't check out empty directories) is
2843 The <Command>cvs update</Command> command sucks in a named sub-directory.
2850 There is a very nice graphical front-end to CVS for Win32 platforms,
2851 with a UI that people will be familiar with, at
2852 <ULink URL="http://www.wincvs.org/">wincvs.org</ULink>.
2853 I have not tried it yet.
2859 <Sect2><Title>Building GHC</Title>
2865 In the <filename>./configure</filename> output, ignore
2867 checking whether #! works in shell scripts...
2868 ./configure: ./conftest: No such file or directory</Literal>",
2869 and "<Literal>not updating unwritable cache ./config.cache</Literal>".
2870 Nobody knows why these happen, but they seem to be harmless.
2876 You have to run <Command>autoconf</Command> both in <filename>fptools</filename>
2877 and in <filename>fptools/ghc</filename>. If you omit the latter step you'll
2878 get an error when you run <filename>./configure</filename>:
2883 creating mk/config.h
2884 mk/config.h is unchanged
2886 running /bin/sh ./configure --cache-file=.././config.cache --srcdir=.
2887 ./configure: ./configure: No such file or directory
2888 configure: error: ./configure failed for ghc
2894 You need <filename>ghc</filename> to be in your <Constant>PATH</Constant> before you run
2895 <Command>configure</Command>. The default GHC InstallShield creates only
2896 <filename>ghc-4.08</filename>, so you may need to duplicate this file as <filename>ghc</filename>
2897 in the same directory, in order that <Command>configure</Command> will see it (or
2898 just rename <filename>ghc-4.08</filename> to <filename>ghc</filename>.
2899 And make sure that the directory is in your path.