Newer
Older
<!DOCTYPE Article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
<Title>Building the Glasgow Functional Programming Tools Suite</Title>
<Author><OtherName>The GHC Team</OtherName></Author>
<Address><Email>glasgow-haskell-{users,bugs}@haskell.org</Email></Address>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<PubDate>January 2000</PubDate>
<Abstract>
<Para>
This guide is intended for people who want to build or modify
programs from the Glasgow <Literal>fptools</Literal> suite (as distinct from those
who merely want to <Emphasis>run</Emphasis> them). Installation instructions are now provided in the user guide.
</Para>
<Para>
The bulk of this guide applies to building on Unix systems; see <XRef LinkEnd="winbuild"> for Windows notes.
</Para>
</Abstract>
</ArtHeader>
<Sect1 id="sec-getting">
<Title>Getting the Glasgow <Literal>fptools</Literal> suite
</Title>
<Para>
Building the Glasgow tools <Emphasis>can</Emphasis> be complicated, mostly because
there are so many permutations of what/why/how, e.g., ``Build Happy
with HBC, everything else with GHC, leave out profiling, and test it
all on the `real' NoFib programs.'' Yeeps!
</Para>
<Para>
Happily, such complications don't apply to most people. A few common
``strategies'' serve most purposes. Pick one and proceed
as suggested:
</Para>
<Para>
<VariableList>
<VarListEntry>
<Term><IndexTerm><Primary>Binary distribution</Primary></IndexTerm>Binary distribution.</Term>
<ListItem>
<Para>
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
binary distribution everything is pre-compiled for your particular
machine architecture and operating system, so all you should have to
do is install the binaries and libraries in suitable places. The user guide
describes how to do this.
</Para>
<Para>
A binary distribution may not work for you for two reasons. First, we
may not have built the suite for the particular architecture/OS
platform you want. That may be due to lack of time and energy (in
which case you can get a source distribution and build from it; see
below). Alternatively, it may be because we haven't yet ported the
suite to your architecture, in which case you are considerably worse
off.
</Para>
<Para>
The second reason a binary distribution may not be what you want is
if you want to read or modify the souce code.
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term><IndexTerm><Primary>Source distribution</Primary></IndexTerm>Source distribution.</Term>
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<ListItem>
<Para>
You have a supported
platform, but (a) you like the warm fuzzy feeling of compiling things
yourself; (b) you want to build something ``extra''—e.g., a set of
libraries with strictness-analysis turned off; or (c) you want to hack
on GHC yourself.
</Para>
<Para>
A source distribution contains complete sources for one or more
projects in the <Literal>fptools</Literal> suite. Not only that, but the more awkward
machine-independent steps are done for you. For example, if you don't
have <Command>flex</Command><IndexTerm><Primary>flex</Primary></IndexTerm> you'll find it convenient that the source
distribution contains the result of running <Command>flex</Command> on the lexical
analyser specification. If you don't want to alter the lexical
analyser then this saves you having to find and install <Command>flex</Command>. You
will still need a working version of GHC on your machine in order to
compile (most of) the sources, however.
</Para>
<Para>
We make source distributions more frequently than binary
distributions; a release that comes with pre-compiled binaries
is considered a major release, i.e., a release that we have some
confidence will work well by having tested it (more) thoroughly.
</Para>
<Para>
Source-only distributions are either bugfix releases or snapshots of
current state of development. The release has undergone some testing.
Source releases of GHC 4.xx can be compiled up using GHC 2.10 or
later.
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term>Build GHC from intermediate C <Filename>.hc</Filename> files<IndexTerm><Primary>hc files</Primary></IndexTerm>:</Term>
<ListItem>
<Para>
You
need a working GHC to use a source distribution. What if you don't
have a working GHC? Then you have no choice but to ``bootstrap'' up
from the intermediate C (<Filename>.hc</Filename>) files that we provide. Building GHC
on an unsupported platform falls into this category. Please see
<Xref LinkEnd="sec-booting-from-C">.
</Para>
<Para>
Once you have built GHC, you can build the other Glasgow tools with
it.
</Para>
<Para>
In theory, you can (could?) build GHC with another Haskell compiler
(e.g., HBC). We haven't tried to do this for ages and it almost
certainly doesn't work any more (for tedious reasons).
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term>The CVS repository.</Term>
<ListItem>
<Para>
We make source distributions slightly more often than binary
distributions; but still infrequently. If you want more up-to-the
minute (but less tested) source code then you need to get access to
our CVS repository.
</Para>
<Para>
All the <Literal>fptools</Literal> source code is held in a CVS repository. CVS is a
pretty good source-code control system, and best of all it works over
the network.
</Para>
<Para>
The repository holds source code only. It holds no mechanically
generated files at all. So if you check out a source tree from CVS
you will need to install every utility so that you can build all the
derived files from scratch.
</Para>
<Para>
More information about our CVS repository is available in the <ULink
URL="http://www.haskell.org/ghc/cvs-cheat-sheet.html" >FPTools CVS
Cheat Sheet</ULink >.
</Para>
</ListItem></VarListEntry>
</VariableList>
</Para>
<Para>
If you are going to do any building from sources (either from a source
distribution or the CVS repository) then you need to read all of this
manual in detail.
</Para>
</Sect1>
<Title>Things to check before you start typing</Title>
<Para>
Here's a list of things to check before you get started.
<OrderedList>
<ListItem>
<Para>
<IndexTerm><Primary>Disk space needed</Primary></IndexTerm>
Disk space needed: About 40MB (one tenth of one hamburger's worth) of disk
space for the most basic binary distribution of GHC; more for some
platforms, e.g., Alphas. An extra ``bundle'' (e.g., concurrent Haskell
libraries) might take you to up to one fifth of a hamburger. You'll need
over 100MB (say, one fifth a hamburger's worth) if you need to build the
basic stuff from scratch. All of the above are
<Emphasis>estimates</Emphasis> of disk-space needs. (Note: our benchmark hamburger is a standard Double Whopper with Cheese, with an RRP of UKP2.99.)
</Para>
</ListItem>
<ListItem>
<Para>
Use an appropriate machine, compilers, and things.
SPARC boxes, and PCs running Linux, FreeBSD, NetBSD, or Solaris are
all fully supported. Win32 and HP boxes are in pretty good shape.
DEC Alphas running OSF/1, Linux or some BSD variant, MIPS and AIX
boxes will need some minimal porting effort before they work (as of
4.06). <Xref LinkEnd="sec-port-info"> gives the full run-down on
ports or lack thereof.
</Para>
</ListItem>
<ListItem>
<Para>
Be sure that the ``pre-supposed'' utilities are installed.
<Xref LinkEnd="sec-pre-supposed"> elaborates.
</Para>
</ListItem>
<ListItem>
<Para>
If you have any problem when building or installing the Glasgow
tools, please check the ``known pitfalls'' (<Xref
LinkEnd="sec-build-pitfalls">). Also check the FAQ for the version
you're building, which should be available from the relevant download
page on the <ULink URL="http://www.haskell.org/ghc/" >GHC web
site</ULink>.
<IndexTerm><Primary>known bugs</Primary></IndexTerm>
<IndexTerm><Primary>bugs, known</Primary></IndexTerm>
If you feel there is still some shortcoming in our procedure or
instructions, please report it.
For GHC, please see the bug-reporting section of the GHC Users' Guide
(separate document), to maximise the usefulness of your report.
<IndexTerm><Primary>bugs, reporting</Primary></IndexTerm>
If in doubt, please send a message to
<Email>glasgow-haskell-bugs@haskell.org</Email>.
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<IndexTerm><Primary>bugs, mailing list</Primary></IndexTerm>
</Para>
</ListItem>
</OrderedList>
</Para>
</Sect1>
<Sect1 id="sec-port-info">
<Title>What machines the Glasgow tools run on
</Title>
<Para>
<IndexTerm><Primary>ports, GHC</Primary></IndexTerm>
<IndexTerm><Primary>GHC ports</Primary></IndexTerm>
<IndexTerm><Primary>supported platforms</Primary></IndexTerm>
<IndexTerm><Primary>platforms, supported</Primary></IndexTerm>
The main question is whether or not the Haskell compiler (GHC) runs on
your platform.
</Para>
<Para>
A ``platform'' is a architecture/manufacturer/operating-system
combination, such as <Literal>sparc-sun-solaris2</Literal>. Other common ones are
<Literal>alpha-dec-osf2</Literal>, <Literal>hppa1.1-hp-hpux9</Literal>, <Literal>i386-unknown-linux</Literal>,
<Literal>i386-unknown-solaris2</Literal>, <Literal>i386-unknown-freebsd</Literal>,
<Literal>i386-unknown-cygwin32</Literal>, <Literal>m68k-sun-sunos4</Literal>, <Literal>mips-sgi-irix5</Literal>,
<Literal>sparc-sun-sunos4</Literal>, <Literal>sparc-sun-solaris2</Literal>, <Literal>powerpc-ibm-aix</Literal>.
</Para>
<Para>
Bear in mind that certain ``bundles'', e.g. parallel Haskell, may not
work on all machines for which basic Haskell compiling is supported.
</Para>
<Para>
Some libraries may only work on a limited number of platforms; for
example, a sockets library is of no use unless the operating system
supports the underlying BSDisms.
</Para>
<Sect2>
<Title>What platforms the Haskell compiler (GHC) runs on</Title>
<Para>
<IndexTerm><Primary>fully-supported platforms</Primary></IndexTerm>
<IndexTerm><Primary>native-code generator</Primary></IndexTerm>
<IndexTerm><Primary>registerised ports</Primary></IndexTerm>
<IndexTerm><Primary>unregisterised ports</Primary></IndexTerm>
The GHC hierarchy of Porting Goodness: (a) Best is a native-code
generator; (b) next best is a ``registerised''
port; (c) the bare minimum is an ``unregisterised'' port.
(``Unregisterised'' is so terrible that we won't say more about it).
</Para>
<Para>
The native code generator is currently non-functional (as of GHC
version 4.06), but we're actively working on getting it going again.
We use Sparcs running Solaris 2.7 and x86 boxes running FreeBSD and
Linux, so those are the best supported platforms, unsurprisingly.
Here's everything that's known about GHC ports. We identify platforms
by their ``canonical'' CPU/Manufacturer/OS triple.
</Para>
<Para>
<VariableList>
<VarListEntry>
<Term>alpha-dec-{osf,linux,freebsd,openbsd,netbsd}:</Term>
<IndexTerm><Primary>alpha-dec-osf</Primary></IndexTerm>
<IndexTerm><Primary>alpha-dec-linux</Primary></IndexTerm>
<IndexTerm><Primary>alpha-dec-freebsd</Primary></IndexTerm>
<IndexTerm><Primary>alpha-dec-openbsd</Primary></IndexTerm>
<IndexTerm><Primary>alpha-dec-netbsd</Primary></IndexTerm>
Currently non-working. The last working version (osf[1-3]) is GHC
3.02. A small amount of porting effort will be required to get Alpha
support into GHC 4.xx, but we don't have easy access to machines right
now, and there hasn't been a massive demand for support, so Alphas
remain unsupported for the time being. Please get in touch if you
either need Alpha support and/or can provide access to boxes.
</ListItem></VarListEntry>
<VarListEntry>
<Term>sparc-sun-sunos4:</Term>
<IndexTerm><Primary>sparc-sun-sunos4</Primary></IndexTerm>
Probably works with minor tweaks, hasn't been tested for a while.
</ListItem></VarListEntry>
<VarListEntry>
<Term>sparc-sun-solaris2:</Term>
<IndexTerm><Primary>sparc-sun-solaris2</Primary></IndexTerm>
Fully supported, including native-code generator.
</ListItem></VarListEntry>
<VarListEntry>
<Term>hppa1.1-hp-hpux (HP-PA boxes running HPUX 9.x)</Term>
<IndexTerm><Primary>hppa1.1-hp-hpux</Primary></IndexTerm>
Works registerised. No native-code generator.
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term>i386-unknown-linux (PCs running Linux—ELF binary format):</Term>
<IndexTerm><Primary>i386-*-linux</Primary></IndexTerm>
GHC works registerised. You <Emphasis>must</Emphasis> have GCC 2.7.x
or later. NOTE about <literal>glibc</literal> versions: GHC binaries
built on a system running <literal>glibc 2.0</literal> won't work on a
system running <literal>glibc 2.1</literal>, and vice version. In
general, don't expect compatibility between <literal>glibc</literal>
versions, even if the shared library version hasn't changed.
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term>i386-unknown-{freebsd,netbsd,openbsd) (PCs running FreeBSD 2.2
or higher, NetBSD, and possibly OpenBSD):</Term>
<IndexTerm><Primary>i386-unknown-freebsd</Primary></IndexTerm>
<IndexTerm><Primary>i386-unknown-netbsd</Primary></IndexTerm>
<IndexTerm><Primary>i386-unknown-openbsd</Primary></IndexTerm>
GHC works registerised. These systems provide ready-built packages of
GHC, so if you just need binaries you're better off just installing
the package.
</ListItem></VarListEntry>
<VarListEntry>
<Term>i386-unknown-cygwin32:</Term>
<IndexTerm><Primary>i386-unknown-cygwin32</Primary></IndexTerm>
Fully supported under Win9x/NT, including a native code
generator. Requires the <Literal>cygwin32</Literal> compatibility
library and a healthy collection of GNU tools (i.e., gcc, GNU ld, bash
etc.).
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term>mips-sgi-irix5:</Term>
<IndexTerm><Primary>mips-sgi-irix[5-6]</Primary></IndexTerm>
Port currently doesn't work, needs some minimal porting effort. As
usual, we don't have access to machines and there hasn't been an
overwhelming demand for this port, but feel free to get in touch.
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term>powerpc-ibm-aix:</Term>
<IndexTerm><Primary>powerpc-ibm-aix</Primary></IndexTerm>
Port currently doesn't work, needs some minimal porting effort. As
usual, we don't have access to machines and there hasn't been an
overwhelming demand for this port, but feel free to get in touch.
</Para>
</ListItem></VarListEntry>
<para>
Various other systems have had GHC ported to them in the distant past,
including various Motorola 68k boxes. The 68k support still remains,
but porting to one of these systems will certainly be a non-trivial
task.
</para>
</Sect2>
<Sect2>
<Title>What machines the other tools run on</Title>
<Para>
Unless you hear otherwise, the other tools work if GHC works.
</Para>
</Sect2>
</Sect1>
<Sect1 id="sec-pre-supposed">
<Title>Installing pre-supposed utilities
<IndexTerm><Primary>pre-supposed utilities</Primary></IndexTerm>
<IndexTerm><Primary>utilities, pre-supposed</Primary></IndexTerm></Title>
<Para>
Here are the gory details about some utility programs you may need;
<Command>perl</Command>, <Command>gcc</Command> and
<command>happy</command> are the only important
ones. (PVM<IndexTerm><Primary>PVM</Primary></IndexTerm> is important
if you're going for Parallel Haskell.) The
<Command>configure</Command><IndexTerm><Primary>configure</Primary></IndexTerm>
script will tell you if you are missing something.
</Para>
<Para>
<VariableList>
<VarListEntry>
<Term>Perl:</Term>
<IndexTerm><Primary>pre-supposed: Perl</Primary></IndexTerm>
<IndexTerm><Primary>Perl, pre-supposed</Primary></IndexTerm>
<ListItem>
<Para>
<Emphasis>You have to have Perl to proceed!</Emphasis> Perl is a
language quite good for doing shell-scripty tasks that involve lots of
text processing. It is pretty easy to install.
Perl 5 is required. For Win32 platforms, we strongly suggest you
pick up a port of Perl 5 for <Literal>cygwin32</Literal>, as the
common Hip/ActiveWare port of Perl is Not Cool Enough for our
purposes.
Perl should be put somewhere so that it can be invoked by the
<Literal>#!</Literal> script-invoking mechanism. (I believe
<Filename>/usr/bin/perl</Filename> is preferred; we use
<Filename>/usr/local/bin/perl</Filename> at Glasgow.) The full
pathname should may need to be less than 32 characters long on some
systems.
</ListItem></VarListEntry>
<VarListEntry>
<Term>GNU C (<Command>gcc</Command>):</Term>
<IndexTerm><Primary>pre-supposed: GCC (GNU C compiler)</Primary></IndexTerm>
<IndexTerm><Primary>GCC (GNU C compiler), pre-supposed</Primary></IndexTerm>
We recommend using GCC version 2.95.2 on all platforms. Failing that,
version 2.7.2 is stable on most platforms. Earlier versions of GCC
can be assumed not to work, and versions in between 2.7.2 and 2.95.2
(including <command>egcs</command>) have varying degrees of stability
depending on the platform.
</Para>
<Para>
If your GCC dies with ``internal error'' on some GHC source file,
please let us know, so we can report it and get things improved.
(Exception: on iX86 boxes—you may need to fiddle with GHC's
<Option>-monly-N-regs</Option> option; see the User's Guide)
</Para>
</ListItem></VarListEntry>
<varlistentry>
<term>Happy:</term>
<indexterm><primary>Happy</primary></indexterm>
<listitem>
<para>Happy is a parser generator tool for Haskell, and is used to
generate GHC's parsers. Happy is written in Haskell, and is a project
in the CVS repository (<literal>fptools/happy</literal>). It can be
built from source, but bear in mind that you'll need GHC installed in
order to build it. To avoid the chicken/egg problem, install a binary
distribtion of either Happy or GHC to get started. Happy
distributions are available from <ulink
url="http://www.haskell.org/happy/">Happy's Web Page</ulink>.
</para>
</listitem>
</varlistentry>
<VarListEntry>
<Term>Autoconf:</Term>
<IndexTerm><Primary>pre-supposed: Autoconf</Primary></IndexTerm>
<IndexTerm><Primary>Autoconf, pre-supposed</Primary></IndexTerm>
<Para>
GNU Autoconf is needed if you intend to build from the CVS sources, it
is <Emphasis>not</Emphasis> needed if you just intend to build a
standard source distribution.
Autoconf builds the <Command>configure</Command> script from
<Filename>configure.in</Filename> and <Filename>aclocal.m4</Filename>.
If you modify either of these files, you'll need Autoconf to rebuild
<Filename>configure</Filename>.
</ListItem></VarListEntry>
<VarListEntry>
<Term><Command>sed</Command></Term>
<IndexTerm><Primary>pre-supposed: sed</Primary></IndexTerm>
<IndexTerm><Primary>sed, pre-supposed</Primary></IndexTerm>
You need a working <Command>sed</Command> if you are going to build
from sources. The build-configuration stuff needs it. GNU sed
version 2.0.4 is no good! It has a bug in it that is tickled by the
build-configuration. 2.0.5 is OK. Others are probably OK too
(assuming we don't create too elaborate configure scripts.)
</Para>
</ListItem></VarListEntry>
</VariableList>
</Para>
<Para>
One <Literal>fptools</Literal> project is worth a quick note at this
point, because it is useful for all the others:
<Literal>glafp-utils</Literal> contains several utilities which aren't
particularly Glasgow-ish, but Occasionally Indispensable. Like
<Command>lndir</Command> for creating symbolic link trees.
</Para>
<Sect2 id="pre-supposed-gph-tools">
<Title>Tools for building parallel GHC (GPH)
</Title>
<Para>
<VariableList>
<VarListEntry>
<Term>PVM version 3:</Term>
<IndexTerm><Primary>pre-supposed: PVM3 (Parallel Virtual Machine)</Primary></IndexTerm>
<IndexTerm><Primary>PVM3 (Parallel Virtual Machine), pre-supposed</Primary></IndexTerm>
<Para>
PVM is the Parallel Virtual Machine on which Parallel Haskell programs
run. (You only need this if you plan to run Parallel Haskell.
Concurent Haskell, which runs concurrent threads on a uniprocessor
doesn't need it.) Underneath PVM, you can have (for example) a
network of workstations (slow) or a multiprocessor box (faster).
</Para>
<Para>
The current version of PVM is 3.3.11; we use 3.3.7. It is readily
available on the net; I think I got it from
<Literal>research.att.com</Literal>, in <Filename>netlib</Filename>.
</Para>
<Para>
A PVM installation is slightly quirky, but easy to do. Just follow
the <Filename>Readme</Filename> instructions.
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term><Command>bash</Command>:</Term>
<IndexTerm><Primary>bash, presupposed (Parallel Haskell only)</Primary></IndexTerm>
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
<ListItem>
<Para>
Sadly, the <Command>gr2ps</Command> script, used to convert ``parallelism profiles''
to PostScript, is written in Bash (GNU's Bourne Again shell).
This bug will be fixed (someday).
</Para>
</ListItem></VarListEntry>
</VariableList>
</Para>
</Sect2>
<Sect2 id="pre-supposed-doc-tools">
<Title>Tools for building the Documentation
</Title>
<Para>
The following additional tools are required if you want to format the
documentation that comes with the <Literal>fptools</Literal> projects:
</Para>
<Para>
<VariableList>
<VarListEntry>
<Term>DocBook:</Term>
<IndexTerm><Primary>pre-supposed: DocBook</Primary></IndexTerm>
<IndexTerm><Primary>DocBook, pre-supposed</Primary></IndexTerm>
All our documentation is written in SGML, using the DocBook DTD.
Instructions on installing and configuring the DocBook tools are in the
installation guide (in the GHC user guide).
</ListItem></VarListEntry>
<VarListEntry>
<Term>TeX:</Term>
<IndexTerm><Primary>pre-supposed: TeX</Primary></IndexTerm>
<IndexTerm><Primary>TeX, pre-supposed</Primary></IndexTerm>
A decent TeX distribution is required if you want to produce printable
documentation. We recomment teTeX, which includes just about
everything you need.
</Para>
</ListItem></VarListEntry>
</VariableList>
</Para>
</Sect2>
<Sect2 id="pre-supposed-other-tools">
<Title>Other useful tools
</Title>
<VariableList>
<VarListEntry>
<Term>Flex:</Term>
<IndexTerm><Primary>pre-supposed: flex</Primary></IndexTerm>
<IndexTerm><Primary>flex, pre-supposed</Primary></IndexTerm>
<Para>
This is a quite-a-bit-better-than-Lex lexer. Used to build a couple
of utilities in <Literal>glafp-utils</Literal>. Depending on your
operating system, the supplied <Command>lex</Command> may or may not
work; you should get the GNU version.
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
</Para>
</ListItem></VarListEntry>
</VariableList>
</Sect2>
</Sect1>
<Sect1 id="sec-building-from-source">
<Title>Building from source
<IndexTerm><Primary>Building from source</Primary></IndexTerm>
<IndexTerm><Primary>Source, building from</Primary></IndexTerm></Title>
<Para>
You've been rash enough to want to build some of
the Glasgow Functional Programming tools (GHC, Happy,
nofib, etc.) from source. You've slurped the source,
from the CVS repository or from a source distribution, and
now you're sitting looking at a huge mound of bits, wondering
what to do next.
</Para>
<Para>
Gingerly, you type <Command>make</Command>. Wrong already!
</Para>
<Para>
This rest of this guide is intended for duffers like me, who aren't
really interested in Makefiles and systems configurations, but who
need a mental model of the interlocking pieces so that they can make
them work, extend them consistently when adding new software, and lay
hands on them gently when they don't work.
</Para>
<Sect2 id="sec-source-tree">
<Title>Your source tree
</Title>
<Para>
The source code is held in your <Emphasis>source tree</Emphasis>.
The root directory of your source tree <Emphasis>must</Emphasis>
contain the following directories and files:
</Para>
<Para>
<ItemizedList>
<ListItem>
<Para>
<Filename>Makefile</Filename>: the root Makefile.
</Para>
</ListItem>
<ListItem>
<Para>
<Filename>mk/</Filename>: the directory that contains the
main Makefile code, shared by all the
<Literal>fptools</Literal> software.
</Para>
</ListItem>
<ListItem>
<Para>
<Filename>configure.in</Filename>, <Filename>config.sub</Filename>, <Filename>config.guess</Filename>:
these files support the configuration process.
</Para>
</ListItem>
<ListItem>
<Para>
<Filename>install-sh</Filename>.
</Para>
</ListItem>
</ItemizedList>
</Para>
<Para>
All the other directories are individual <Emphasis>projects</Emphasis> of the
<Literal>fptools</Literal> system—for example, the Glasgow Haskell Compiler
(<Literal>ghc</Literal>), the Happy parser generator (<Literal>happy</Literal>), the <Literal>nofib</Literal> benchmark
suite, and so on. You can have zero or more of these. Needless to
say, some of them are needed to build others.
</Para>
<Para>
The important thing to remember is that even if you want only one
project (<Literal>happy</Literal>, say), you must have a source tree whose root
directory contains <Filename>Makefile</Filename>, <Filename>mk/</Filename>, <Filename>configure.in</Filename>, and the
project(s) you want (<Filename>happy/</Filename> in this case). You cannot get by with
just the <Filename>happy/</Filename> directory.
</Para>
</Sect2>
<Sect2>
<Title>Build trees
<IndexTerm><Primary>build trees</Primary></IndexTerm>
<IndexTerm><Primary>link trees, for building</Primary></IndexTerm></Title>
<Para>
While you can build a system in the source tree, we don't recommend it.
We often want to build multiple versions of our software
for different architectures, or with different options (e.g. profiling).
It's very desirable to share a single copy of the source code among
all these builds.
</Para>
<Para>
So for every source tree we have zero or more <Emphasis>build trees</Emphasis>. Each
build tree is initially an exact copy of the source tree, except that
each file is a symbolic link to the source file, rather than being a
copy of the source file. There are ``standard'' Unix utilities that
make such copies, so standard that they go by different names:
<Command>lndir</Command><IndexTerm><Primary>lndir</Primary></IndexTerm>, <Command>mkshadowdir</Command><IndexTerm><Primary>mkshadowdir</Primary></IndexTerm> are two (If you
don't have either, the source distribution includes sources for the
X11 <Command>lndir</Command>—check out <Filename>fptools/glafp-utils/lndir</Filename>). See <Xref LinkEnd="sec-storysofar"> for a typical invocation.
</Para>
<Para>
The build tree does not need to be anywhere near the source tree in
the file system. Indeed, one advantage of separating the build tree
from the source is that the build tree can be placed in a
non-backed-up partition, saving your systems support people from
backing up untold megabytes of easily-regenerated, and
rapidly-changing, gubbins. The golden rule is that (with a single
exception—<XRef LinkEnd="sec-build-config">)
<Emphasis>absolutely everything in the build tree is either a symbolic
link to the source tree, or else is mechanically generated</Emphasis>.
It should be perfectly OK for your build tree to vanish overnight; an
hour or two compiling and you're on the road again.
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
</Para>
<Para>
You need to be a bit careful, though, that any new files you create
(if you do any development work) are in the source tree, not a build tree!
</Para>
<Para>
Remember, that the source files in the build tree are <Emphasis>symbolic
links</Emphasis> to the files in the source tree. (The build tree soon
accumulates lots of built files like <Filename>Foo.o</Filename>, as well.) You
can <Emphasis>delete</Emphasis> a source file from the build tree without affecting
the source tree (though it's an odd thing to do). On the other hand,
if you <Emphasis>edit</Emphasis> a source file from the build tree, you'll edit the
source-tree file directly. (You can set up Emacs so that if you edit
a source file from the build tree, Emacs will silently create an
edited copy of the source file in the build tree, leaving the source
file unchanged; but the danger is that you think you've edited the
source file whereas actually all you've done is edit the build-tree
copy. More commonly you do want to edit the source file.)
</Para>
<Para>
Like the source tree, the top level of your build tree must be (a
linked copy of) the root directory of the <Literal>fptools</Literal> suite. Inside
Makefiles, the root of your build tree is called
<Constant>$(FPTOOLS_TOP)</Constant><IndexTerm><Primary>FPTOOLS_TOP</Primary></IndexTerm>. In the rest of this document path
names are relative to <Constant>$(FPTOOLS_TOP)</Constant> unless otherwise stated. For
example, the file <Filename>ghc/mk/target.mk</Filename> is actually
<Filename><Constant>$(FPTOOLS_TOP)</Constant>/ghc/mk/target.mk</Filename>.
</Para>
</Sect2>
<Sect2 id="sec-build-config">
<Title>Getting the build you want
</Title>
<Para>
When you build <Literal>fptools</Literal> you will be compiling code on a particular
<Emphasis>host platform</Emphasis>, to run on a particular <Emphasis>target platform</Emphasis>
(usually the same as the host platform)<IndexTerm><Primary>platform</Primary></IndexTerm>. The
difficulty is that there are minor differences between different
platforms; minor, but enough that the code needs to be a bit different
for each. There are some big differences too: for a different
architecture we need to build GHC with a different native-code
generator.
</Para>
<Para>
There are also knobs you can turn to control how the <Literal>fptools</Literal>
software is built. For example, you might want to build GHC optimised
(so that it runs fast) or unoptimised (so that you can compile it fast
after you've modified it. Or, you might want to compile it with
debugging on (so that extra consistency-checking code gets included)
or off. And so on.
</Para>
<Para>
All of this stuff is called the <Emphasis>configuration</Emphasis> of your build.
You set the configuration using a three-step process.
<VariableList>
<VarListEntry>
<Term>Step 1: get ready for configuration.</Term>
<ListItem>
<Para>
Change directory to
<Constant>$(FPTOOLS_TOP)</Constant> and issue the command <Command>autoconf</Command><IndexTerm><Primary>autoconf</Primary></IndexTerm> (with
no arguments). This GNU program converts <Filename><Constant>$(FPTOOLS_TOP)</Constant>/configure.in</Filename>
to a shell script called <Filename><Constant>$(FPTOOLS_TOP)</Constant>/configure</Filename>.
</Para>
<para>
Some projects, including GHC, have their own configure script. If
there's an
<Constant>$(FPTOOLS_TOP)/<project>/configure.in</Constant>,
then you need to run <command>autoconf</command> in that directory too.
</para>
<Para>
Both these steps are completely platform-independent; they just mean
that the human-written file (<Filename>configure.in</Filename>) can be short, although
the resulting shell script, <Command>configure</Command>, and <Filename>mk/config.h.in</Filename>, are
long.
</Para>
<Para>
In case you don't have <Command>autoconf</Command> we distribute the results,
<Command>configure</Command>, and <Filename>mk/config.h.in</Filename>, with the source distribution. They
aren't kept in the repository, though.
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term>Step 2: system configuration.</Term>
<ListItem>
<Para>
Runs the newly-created <Command>configure</Command> script, thus:
<ProgramListing>
./configure
</ProgramListing>
<Command>configure</Command>'s mission is to scurry round your
computer working out what architecture it has, what operating system,
whether it has the <Function>vfork</Function> system call, where
<Command>yacc</Command> is kept, whether <Command>gcc</Command> is
available, where various obscure <Literal>#include</Literal> files
are, whether it's a leap year, and what the systems manager had for
lunch. It communicates these snippets of information in two ways:
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
</Para>
<Para>
<ItemizedList>
<ListItem>
<Para>
It translates <Filename>mk/config.mk.in</Filename><IndexTerm><Primary>config.mk.in</Primary></IndexTerm> to
<Filename>mk/config.mk</Filename><IndexTerm><Primary>config.mk</Primary></IndexTerm>, substituting for things between
``<Literal>@</Literal>'' brackets. So, ``<Literal>@HaveGcc@</Literal>'' will be replaced by
``<Literal>YES</Literal>'' or ``<Literal>NO</Literal>'' depending on what <Command>configure</Command> finds.
<Filename>mk/config.mk</Filename> is included by every Makefile (directly or indirectly),
so the configuration information is thereby communicated to all
Makefiles.
</Para>
</ListItem>
<ListItem>
<Para>
It translates <Filename>mk/config.h.in</Filename><IndexTerm><Primary>config.h.in</Primary></IndexTerm> to
<Filename>mk/config.h</Filename><IndexTerm><Primary>config.h</Primary></IndexTerm>. The latter is <Literal>#include</Literal>d by various C
programs, which can thereby make use of configuration information.
</Para>
</ListItem>
</ItemizedList>
</Para>
<Para>
<Command>configure</Command> caches the results of its run in <Filename>config.cache</Filename>. Quite
often you don't want that; you're running <Command>configure</Command> a second time
because something has changed. In that case, simply delete
<Filename>config.cache</Filename>.
</Para>
</ListItem></VarListEntry>
<VarListEntry>
<Term>Step 3: build configuration.</Term>
<ListItem>
<Para>
Next, you say how this build of <Literal>fptools</Literal> is to differ from the
standard defaults by creating a new file <Filename>mk/build.mk</Filename><IndexTerm><Primary>build.mk</Primary></IndexTerm>
<Emphasis>in the build tree</Emphasis>. This file is the one and only file you edit
in the build tree, precisely because it says how this build differs
from the source. (Just in case your build tree does die, you might
want to keep a private directory of <Filename>build.mk</Filename> files, and use a
symbolic link in each build tree to point to the appropriate one.) So
<Filename>mk/build.mk</Filename> never exists in the source tree—you create one in
each build tree from the template. We'll discuss what to put in it
shortly.
</Para>
</ListItem></VarListEntry>
</VariableList>
</Para>
<Para>
And that's it for configuration. Simple, eh?
</Para>
<Para>
What do you put in your build-specific configuration file
<Filename>mk/build.mk</Filename>? <Emphasis>For almost all purposes all you will do is put
make variable definitions that override those in</Emphasis> <Filename>mk/config.mk.in</Filename>.
The whole point of <Filename>mk/config.mk.in</Filename>—and its derived counterpart
<Filename>mk/config.mk</Filename>—is to define the build configuration. It is heavily
commented, as you will see if you look at it. So generally, what you
do is look at <Filename>mk/config.mk.in</Filename>, and add definitions in <Filename>mk/build.mk</Filename>
that override any of the <Filename>config.mk</Filename> definitions that you want to
change. (The override occurs because the main boilerplate file,
<Filename>mk/boilerplate.mk</Filename><IndexTerm><Primary>boilerplate.mk</Primary></IndexTerm>, includes <Filename>build.mk</Filename> after
<Filename>config.mk</Filename>.)
</Para>