[project @ 1998-01-12 14:44:37 by simonm]
[ghc-hetmet.git] / docs / installing.lit
1 %       Building and installing the Glasgow Functional Programming Tools Suite
2 %
3 %                               Version 3.00
4 %                               July 1997
5                         
6
7 \begin{onlystandalone}
8 \documentstyle[11pt,literate]{article}
9 \begin{document}
10 \title{Building and installing the Glasgow Functional Programming Tools Suite\\
11 Version~3.00}
12 \author{The GHC Team\\
13 Department of Computing Science\\
14 University of Glasgow\\
15 Glasgow, Scotland\\
16 G12 8QQ\\
17 \\
18 Email: glasgow-haskell-\{users,bugs\}\@dcs.gla.ac.uk}
19 \maketitle
20 \begin{rawlatex}
21 \tableofcontents
22 \end{rawlatex}
23 \clearpage
24 \end{onlystandalone}
25
26 This guide is intended for people who want to install or modify
27 programs from the Glasgow @fptools@ suite (as distinct from those
28 who merely want to {\em run} them).
29
30 The whole install-and-make system was completely re-done between GHC
31 2.01 and 2.02, so it will be worth your while to re-read this guide
32 even if you have read earlier versions.
33
34 \section{Getting the Glasgow @fptools@ suite}
35
36 Building the Glasgow tools {\em can} be complicated, mostly because
37 there are so many permutations of what/why/how, e.g., ``Build Happy
38 with HBC, everything else with GHC, leave out profiling, and test it
39 all on the `real' NoFib programs.''  Yeeps!
40
41 Happily, such complications don't apply to most people.  A few common
42 ``strategies'' serve most purposes.  Pick one and proceed
43 as suggested:
44
45 \begin{description}
46
47 \item[Binary distribution.]  If your only purpose is to install some
48 of the @fptools@ suite then the easiest thing to do is to get a binary
49 distribution. In the binary distribution everything is pre-compiled
50 for your particular machine architecture and operating system, so all
51 you should have to do is install the binaries and libraries in
52 suitable places.  Section~\ref{installing-bin-distrib} describes
53 how to do this.
54
55 A binary distribution may not work for you for two reasons.  First, we
56 may not have built the suite for the particular architecture/OS
57 platform you want. That may be due to lack of time and energy (in
58 which case you can get a source distribution and build from it; see
59 below).  Alternatively, it may be because we haven't yet ported the
60 suite to your architecture, in which case you are considerably worse
61 off.
62
63 The second reason a binary distribution may not be what you want is
64 if you want to read or modify the souce code.
65
66 \item[Source distribution.]
67 You have a supported platform, but (a)~you like the warm fuzzy feeling
68 of compiling things yourself; (b)~you want to build something
69 ``extra''---e.g., a set of libraries with strictness-analysis turned
70 off; or (c)~you want to hack on GHC yourself.
71
72 A source distribution contains complete sources for the @fptools@ suite.
73 Not only that, but the more awkward machine-independent steps are done
74 for you.  For example, if you don't have @flex@ you'll find it
75 convenient that the source distribution contains the result of running
76 @flex@ on the lexical analyser specification.  If you don't want to
77 alter the lexical analyser then this saves you having to find and
78 install @flex@. You will still need a working version of GHC on your
79 machine in order to compile (most of) the sources, however.
80
81 We make source distributions more frequently than binary
82 distributions; a release that comes with pre-compiled binaries
83 is considered a major release, i.e., a release that we have some
84 confidence will work well by having tested it (more) thoroughly.
85
86 Source-only distributions are either bugfix releases or snapshots of
87 current state of development. The release has undergone some testing.
88 Source releases of 2.0x can be compiled up using 2.07 (or subsequent
89 bugfix releases) or the Good Old Compiler, GHC~0.29. Compiling with
90 0.29 is recommended if you're a performance junkie, as 0.29 (still)
91 generates zippier code, but GHC~2.0x is catching up.
92
93 \item[Build GHC from intermediate C \tr{.hc} files:] 
94 You need a working GHC to use a source distribution. What if you don't
95 have a working GHC? Then you have no choice but to ``bootstrap'' up
96 from the intermediate C (\tr{.hc}) files that we provide.
97 Building GHC on an unsupported platform falls into this category.
98 Please see \sectionref{booting-from-C}.
99
100 Once you have built GHC, you can build the other Glasgow tools with
101 it.
102
103 In theory, you can (could?) build GHC with another Haskell compiler
104 (e.g., HBC). We haven't tried to do this for ages and it almost
105 certainly doesn't work any more (for tedious reasons).
106
107 \item[The CVS repository.]
108
109 We make source distributions slightly more often than binary
110 distributions; but still infrequently.  If you want more up-to-the
111 minute (but less tested) source code then you need to get access to
112 our CVS repository.
113
114 All the @fptools@ source code is held in a CVS repository. CVS is a
115 pretty good source-code control system, and best of all it works over
116 the network.
117
118 The repository holds source code only. It holds no mechanically
119 generated files at all.  So if you check out a source tree from CVS
120 you will need to install every utility so that you can build all the
121 derived files from scratch.
122
123 Giving you access to the repository entails some systems administration
124 at our end; and we are a bit nervous about being submerged in bug reports
125 about our current working copy (which is, by definition, in flux).  So
126 we are a bit cautious about offering CVS access.  Feel free to ask though!
127 \end{description}
128
129 If you are going to do any building from sources (either from a source
130 distribution or the CVS repository) then you need to read all of this
131 manual in detail.
132
133 %************************************************************************
134 %*                                                                      *
135 \section{Things to check before you start typing}
136 %*                                                                      *
137 %************************************************************************
138
139 Here's a list of things to check before you get started.
140 \begin{enumerate}
141 \item
142 \index{disk space needed}
143 Disk space needed: About 30MB (five hamburgers' worth) of disk space
144 for the most basic binary distribution of GHC; more for some
145 platforms, e.g., Alphas.  An extra ``bundle'' (e.g., concurrent
146 Haskell libraries) might take you to 8--10 hamburgers.
147
148 You'll need over 100MB (say, 20 hamburgers' worth) if you need to
149 build the basic stuff from scratch.
150
151
152 All of the above are {\em estimates} of disk-space needs.(I don't yet
153 know the disk requirements for the non-GHC tools).
154
155 \item
156 Use an appropriate machine, compilers, and things.
157
158 SPARC boxes, DEC Alphas running OSF/1, and PCs running Linux, FreeBSD,
159 or Solaris are all fully supported.  MIPS, AIX, Win32 and HP boxes are
160 in pretty good shape.  \Sectionref{port-info} gives the full run-down
161 on ports or lack thereof.
162
163 \item
164 Be sure that the ``pre-supposed'' utilities are installed.
165 Section~\ref{sect_std-utils} elaborates.
166
167 \item If you have any problem when building or installing the Glasgow
168 tools, please check the ``known pitfalls''
169 (\sectionref{build-pitfalls}).  Also check the ``known bugs'' web page
170 for GHC: 
171
172 \begin{center}
173 @http://www.dcs.gla.ac.uk/fp/software/ghc/ghc-bugs.html@
174 \end{center}
175
176 If you feel there is still some shortcoming in our procedure or
177 instructions, please report it.
178
179 For GHC, please see the bug-reporting section of the User's guide
180 (separate document), to maximise the usefulness of your report.
181
182 If in doubt, please send a message to @glasgow-haskell-bugs@@dcs.gla.ac.uk@.
183 \end{enumerate}
184
185
186 %************************************************************************
187 %*                                                                      *
188 \section[port-info]{What machines the Glasgow tools run on}
189 \index{ports, GHC}
190 \index{GHC ports}
191 \index{supported platforms}
192 \index{platforms, supported}
193 %*                                                                      *
194 %************************************************************************
195
196 The main question is whether or not the Haskell compiler (GHC) runs on
197 your platform.
198
199 A ``platform'' is a architecture/manufacturer/operating-system
200 combination, such as @sparc-sun-solaris2@.  Other common ones are
201 @alpha-dec-osf2@, @hppa1.1-hp-hpux9@, @i386-unknown-linux@,
202 @i386-unknown-solaris2@, @i386-unknown-freebsd@,
203 @i386-unknown-cygwin32@, @m68k-sun-sunos4@, @mips-sgi-irix5@,
204 @sparc-sun-sunos4@, @sparc-sun-solaris2@, @powerpc-ibm-aix@.
205
206 Bear in mind that certain ``bundles'', e.g. parallel Haskell, may not
207 work on all machines for which basic Haskell compiling is supported.
208
209 Some libraries may only work on a limited number of platforms; for
210 example, a sockets library is of no use unless the operating system
211 supports the underlying BSDisms.
212
213 %************************************************************************
214 %*                                                                      *
215 \subsection{What platforms the Haskell compiler (GHC) runs on}
216 %*                                                                      *
217 %************************************************************************
218 \index{fully-supported platforms}
219 \index{native-code generator}
220 \index{registerised ports}
221 \index{unregisterised ports}
222
223 The GHC hierarchy of Porting Goodness: (a)~Best is a native-code
224 generator; (b)~next best is a ``registerised''
225 port; (c)~the bare minimum is an ``unregisterised'' port.
226 (``Unregisterised'' is so terrible that we won't say more about it).
227
228 We use Sun4s running SunOS~4.1.3 and Solaris 2.5, and DEC~Alphas
229 running OSF/1~V2.0, so those are the ``fully-supported'' platforms,
230 unsurprisingly.  Both have native-code generators, for quicker
231 compilations.  The native-code generator for iX86 platforms (e.g.,
232 Linux ELF) is {\em nearly} working; but is not turned on by default.
233
234 Here's everything that's known about GHC ports.  We identify platforms
235 by their ``canonical'' CPU/Manufacturer/OS triple.
236
237 Note that some ports are fussy about which GCC version you use; or
238 require GAS; or ...
239
240 \begin{description}
241 %-------------------------------------------------------------------
242 \item[\tr{alpha-dec-osf1}:]
243 \index{alpha-dec-osf1: fully supported}
244 (We have OSF/1 V2.0.) Fully supported, including native-code generator.
245 We recommend GCC 2.6.x or later.
246
247 %-------------------------------------------------------------------
248 \item[\tr{sparc-sun-sunos4}:]
249 \index{sparc-sun-sunos4: fully supported}
250 Fully supported, including native-code generator.
251
252 %-------------------------------------------------------------------
253 \item[\tr{sparc-sun-solaris2}:]
254 \index{sparc-sun-solaris2: fully supported}
255 Fully supported, including native-code generator.  A couple of quirks,
256 though: (a)~the profiling libraries are bizarrely huge; (b)~the
257 default \tr{xargs} program is atrociously bad for building GHC
258 libraries (see \sectionref{Pre-supposed} for details).
259
260 %-------------------------------------------------------------------
261 \item[HP-PA box running HP/UX 9.x:]
262 \index{hppa1.1-hp-hpux: registerised port}
263 Works registerised.  No native-code generator.
264 For GCC, you're best off with one of the Utah releases of
265 GCC~2.6.3 (`u3' or later), from \tr{jaguar.cs.utah.edu}.
266 We think a straight GCC 2.7.x works, too.
267
268 Concurrent/Parallel Haskell probably don't work (yet).
269 \index{hppa1.1-hp-hpux: concurrent---no}
270 \index{hppa1.1-hp-hpux: parallel---no}
271
272 %-------------------------------------------------------------------
273 \item[\tr{i386-*-linux} (PCs running Linux---ELF format):]
274 \index{i386-*-linux: registerised port}
275 GHC works registerised.
276 You {\em must} have GCC 2.7.x or later.
277 The iX86 native-code generator is {\em nearly} there, but it
278 isn't turned on by default.
279
280 Profiling works, and Concurrent Haskell works.
281 \index{i386-*-linux: profiling---yes}
282 \index{i386-*-linux: concurrent---yes}
283 Parallel Haskell probably works.
284 \index{i386-*-linux: parallel---maybe}
285
286 On old Linux a.out systems: should be the same.
287 \index{i386-*-linuxaout: registerised port}
288
289 %-------------------------------------------------------------------
290 \item[\tr{i386-*-freebsd} (PCs running FreeBSD 2.2 or higher, and
291 NetBSD/OpenBSD using FreeBSD emulation):] 
292 \index{i386-*-freebsd:registerised port} 
293 GHC works registerised. Supports same set of bundles as the above.
294
295 \index{i386-*-freebsd: profiling---yes}
296 \index{i386-*-freebsd: concurrent---yes}
297 \index{i386-*-freebsd: parallel---maybe}
298
299 %-------------------------------------------------------------------
300 \item[\tr{i386-unknown-cygwin32}:]
301 \index{i386-unknown-cygwin32: fully supported}
302 Fully supported under Win95/NT, including a native
303 code generator. Requires the @cygwin32@ compatibility library and
304 a healthy collection of GNU tools (i.e., gcc, GNU ld, bash etc.)
305 Profiling works, so does Concurrent Haskell. 
306 \index{i386-*-cygwin32: profiling---yes}
307 \index{i386-*-cygwin32: concurrent---yes}
308
309 % ToDo: more documentation on this is reqd here.
310
311 %-------------------------------------------------------------------
312 \item[\tr{mips-sgi-irix5}:]
313 \index{mips-sgi-irix5: registerised port}
314 GHC works registerised (no native-code generator).
315 I suspect any GCC~2.6.x (or later) is OK.  The GCC that I used
316 was built with \tr{--with-gnu-as}; turns out that is important!
317
318 Concurrent/Parallel Haskell probably don't work (yet).
319 Profiling might work, but it is untested.
320 \index{mips-sgi-irix5: concurrent---no}
321 \index{mips-sgi-irix5: parallel---no}
322 \index{mips-sgi-irix5: profiling---maybe}
323
324 %-------------------------------------------------------------------
325 \item[\tr{mips-sgi-irix6}:]
326 \index{mips-sgi-irix6: registerised port}
327 Thanks to the fine efforts of Tomasz Cholewo
328 \tr{<tjchol01@mecca.spd.louisville.edu>}, GHC works registerised
329 (no native code generator) under IRIX 6.2 and 6.3. Depends on having
330 specially tweaked version of gcc-2.7.2 around, which can be downloaded
331 from
332
333 \begin{verbatim}
334   http://mecca.spd.louisville.edu/~tjchol01/software/
335 \end{verbatim}
336
337 Profiling works, Concurrent/Parallel Haskell might work (AFAIK, untested).
338 \index{mips-sgi-irix6: concurrent---maybe}
339 \index{mips-sgi-irix6: parallel---maybe}
340 \index{mips-sgi-irix6: profiling---yes}
341
342 %-------------------------------------------------------------------
343 \item[\tr{powerpc-ibm-aix}:]
344 \index{powerpc-ibm-aix: registerised port}
345 GHC works registerised (no native-code generator..yet).
346 I suspect 2.7.x is what you need together with this.
347
348 Concurrent/Parallel Haskell probably don't work (yet).
349 Profiling might work, but it is untested.
350 \index{mips-sgi-irix5: concurrent---no}
351 \index{mips-sgi-irix5: parallel---no}
352 \index{mips-sgi-irix5: profiling---maybe}
353
354 %-------------------------------------------------------------------
355 \item[\tr{m68k-apple-macos7} (Mac, using MPW):]
356 \index{m68k-apple-macos7: historically ported}
357 Once upon a time, David Wright in Tasmania has actually
358 gotten GHC to run on a Macintosh.  Ditto James Thomson here at Glasgow.
359 You may be able to get Thomson's from here.  (Not sure that it will
360 excite you to death, but...)
361
362 No particularly recent GHC is known to work on a Mac.
363
364 %-------------------------------------------------------------------
365 \item[\tr{m68k-next-nextstep3}:]
366 \index{m68k-next-nextstep3: historically ported}
367 Carsten Schultz succeeded with a ``registerised'' port of GHC~0.29.
368 There's probably a little bit-rot since then, but otherwise it should
369 still be fine.
370
371 Concurrent/Parallel Haskell probably won't work (yet).
372 \index{m68k-next-nextstep3: concurrent---no}
373 \index{m68k-next-nextstep3: parallel---no}
374
375 %-------------------------------------------------------------------
376 \item[\tr{m68k-sun-sunos4} (Sun3):]
377 \index{m68k-sun-sunos4: registerised port}
378 GHC 2.0x hasn't been tried on a Sun3.  GHC~0.26 worked registerised.
379 No native-code generator.
380
381 Concurrent/Parallel Haskell probably don't work (yet).
382 \index{m68k-sun-sunos4: concurrent---no}
383 \index{m68k-sun-sunos4: parallel---no}
384 \end{description}
385
386 %************************************************************************
387 %*                                                                      *
388 \subsection{What machines the other tools run on}
389 %*                                                                      *
390 %************************************************************************
391
392 Unless you hear otherwise, the other tools work if GHC works.
393
394 Haggis requires Concurrent Haskell to work.
395 \index{Haggis, Concurrent Haskell}
396
397
398 %************************************************************************
399 %*                                                                      *
400 \section[installing-bin-distrib]{Installing from binary distributions}
401 \index{binary installations}
402 \index{installation, of binaries}
403 %*                                                                      *
404 %************************************************************************
405
406 Installing from binary distributions is easiest, and recommended!
407 (Why binaries?  Because GHC is a Haskell compiler written in Haskell,
408 so you've got to ``bootstrap'' it, somehow.  We provide
409 machine-generated C-files-from-Haskell for this purpose, but it's
410 really quite a pain to use them.  If you must build GHC from its
411 sources, using a binary-distributed GHC to do so is a sensible way to
412 proceed. For the other @fptools@ programs, many are written in Haskell,
413 so binary distributions allow you to install them without having a Haskell compiler.)
414
415
416 \subsection{Bundle structure}
417
418 Binary distributions come in ``bundles,''\index{bundles of binary stuff}
419 one bundle per file called \tr{<bundle>-<platform>.tar.gz}.
420 (See Section~\ref{port-info} for what a platform is.)
421 Suppose that you untar a binary-distribution bundle, thus:
422 \begin{verbatim}
423   % cd /your/scratch/space
424   % gunzip < ghc-x.xx-sun-sparc-solaris2.tar.gz | tar xvf -
425 \end{verbatim}
426 Then you should find a single directory, @fptools@, with the following
427 structure:
428 \begin{description}
429 \item[@Makefile.in@] the raw material from which the @Makefile@ will be made (\sectionref{sect_install}).
430 \item[@configure@] the configuration script (\sectionref{sect_install}).
431 \item[@README@] Contains this file summary.
432 \item[@INSTALL@] Contains this description of how to install the bundle.
433 \item[@ANNOUNCE@] The announcement message for the bundle.
434 \item[@NEWS@] release notes for the bundle -- a longer version of
435 @ANNOUNCE@.  For GHC, the release notes are contained in the User
436 Guide and this file isn't present.
437 \item[@bin/<platform>@] contains platform-specific executable files to be invoked
438 directly by the user.  These are the files that must end up in your path.
439 \item[@lib/<platform>@] contains platform-specific support files for the installation.
440 Typically there is a subdirectory for each @fptools@ project, whose name is
441 the name of the project with its version number.  For example, for GHC 
442 there would be a sub-directory @ghc-x.xx/@ where @x.xx@ is the version 
443 number of GHC in the bundle.
444
445 These sub-directories have the following general structure:
446 \begin{description}
447 \item[@libHS.a@ etc:] supporting library archives.
448 \item[@ghc-iface.prl@ etc:] support scripts.
449 \item[@import/@] Interface files (@.hi@) for the prelude.
450 \item[@include/@] A few C @#include@ files.
451 \end{description}
452
453 \item[@share/@] contains platform-independent support files for the installation.
454 Again, there is a sub-directory for each @fptools@ project.
455
456 \item[@info/@] contains Emacs info documentation files (one sub-directory per project).
457 \item[@html/@] contains HTML documentation files (one sub-directory per project).
458 \item[@man/@] contains Unix manual pages.
459 \end{description}
460 This structure is designed so that you can unpack multiple bundles (including
461 ones from different releases or platforms) into a single @fptools@ directory:
462 \begin{verbatim}
463   % cd /your/scratch/space
464   % gunzip < ghc-x.xx-sun-sparc-solaris2.tar.gz | tar xvf -
465   % gunzip < happy-x.xx-sun-sparc-sunos4.tar.gz | tar xvf -
466 \end{verbatim}
467 When you do multiple unpacks like this, the top level @Makefile@, @README@,
468 and @INSTALL@ get overwritten each time.  That's fine -- they should be the same.
469 Likewise, the @ANNOUNCE-<bundle>@ and @NEWS-<bundle>@ files will be duplicated
470 across multiple platforms, so they will be harmlessly overwritten when you do 
471 multiple unpacks.
472 Finally, the @share/@ stuff will get harmlessly overwritten when you do multiple
473 unpacks for one bundle on different platforms.
474
475 \subsection[sect_install]{Installing}
476
477 OK, so let's assume that you have unpacked your chosen bundles into a
478 scratch directory @fptools@. What next? Well, you will at least need
479 to run the @configure@ script by changing your directory to @fptools@
480 and typing @./configure@.  That should convert @Makefile.in@ to
481 @Makefile@.
482
483 You can now either start using the tools {\em in-situ} without going
484 through any installation process, just type @make in-place@ to set the
485 tools up for this (where @make@ is GNU make - you might have to type
486 @gmake@ to get it). You'll also want to add the path which @make@ will
487 now echo to your @PATH@ environment variable. This option is useful if
488 you simply want to try out the package and/or you don't have the
489 necessary priviledges (or inclination) to properly install the tools
490 locally. Note that if you do decide to install the package `properly'
491 at a later date, you have to go through the installation steps that
492 follows.
493
494 To install an @fptools@ package, you'll have to do the following:
495
496 \begin{enumerate}
497 \item Edit the @Makefile@ and check the settings of the following variables:
498 \begin{description}
499 \item[@platform@] the platform you are going to install for.
500 \item[@bindir@] the directory in which to install user-invokable binaries.
501 \item[@libdir@] the directory in which to install platform-dependent support files.
502 \item[@datadir@] the directory in which to install platform-independent support files. 
503 \item[@infodir@] the directory in which to install Emacs info files.
504 \item[@htmldir@] the directory in which to install HTML documentation.
505 \item[@dvidir@] the directory in which to install DVI documentation.
506 \end{description}
507 The values for these variables can be set through invocation of the
508 @configure@ script that comes with the distribution, but doing an optical
509 diff to see if the values match your expectations is always a Good Idea. 
510
511 {\em Instead of running @configure@, it is perfectly OK to copy
512 @Makefile.in@ to @Makefile@ and set all these variables directly
513 yourself.  But do it right!}
514
515 \item Run @make install@.  This {\em  should} work with ordinary Unix
516 @make@ -- no need for fancy stuff like GNU @make@. 
517
518 \item \tr{rehash} (t?csh users), so your shell will see the new stuff
519 in your bin directory.
520
521 \item
522 Once done, test your ``installation'' as suggested in
523 \sectionref{GHC_test}.  Be sure to use a \tr{-v} option, so you
524 can see exactly what pathnames it's using.
525
526 If things don't work as expected, check the list of know pitfalls
527 \sectionref{build-pitfalls}. 
528 \end{enumerate}
529
530 When installing the user-invokable binaries, this installation
531 procedure will install GHC as @ghc-x.xx@ where @x.xx@ is the version
532 number of GHC.  It will also make a link (in the binary installation
533 directory) from @ghc@ to @ghc-x.xx@.  If you install multiple versions
534 of GHC then the last one ``wins'', and ``@ghc@'' will invoke the last
535 one installed.  You can change this manually if you want.  But
536 regardless, @ghc-x.xx@ should always invoke GHC version @x.xx@.
537
538 \subsection{What bundles there are}
539
540 There are plenty of ``non-basic'' GHC bundles.  The files for them are
541 called \tr{ghc-x.xx-<bundle>-<platform>.tar.gz}, where the
542 \tr{<platform>} is as above, and \tr{<bundle>} is one of these:
543 \begin{description}
544 \item[\tr{prof}:]  Profiling with cost-centres.  You probably want this.
545
546 \item[\tr{conc}:] Concurrent Haskell features.  You may want this.
547
548 \item[\tr{par}:] Parallel Haskell features (sits on top of PVM).
549 You'll want this if you're into that kind of thing.
550
551 \item[\tr{gran}:] The ``GranSim'' parallel-Haskell simulator
552 (hmm... mainly for implementors).
553
554 \item[\tr{ticky}:] ``Ticky-ticky'' profiling; very detailed
555 information about ``what happened when I ran this program''---really
556 for implementors.
557
558 \item[\tr{prof-conc}:] Cost-centre profiling for Concurrent Haskell.
559
560 \item[\tr{prof-ticky}:]  Ticky-ticky profiling for Concurrent Haskell.
561 \end{description}
562
563 One likely scenario is that you will grab {\em three} binary
564 bundles---basic, profiling, and concurrent. 
565
566
567
568 %************************************************************************
569 %*                                                                      *
570 \subsection[GHC_test]{Test that GHC seems to be working}
571 \index{testing a new GHC}
572 %*                                                                      *
573 %************************************************************************
574
575 The way to do this is, of course, to compile and run {\em this} program
576 (in a file \tr{Main.hs}):
577 \begin{verbatim}
578 main = putStr "Hello, world!\n"
579 \end{verbatim}
580
581 First, give yourself a convenient way to execute the driver script
582 \tr{ghc/driver/ghc}, perhaps something like...
583 \begin{verbatim}
584 % ln -s /local/src/ghc-x.xx/ghc/driver/ghc ~/bin/alpha/ghc
585 % rehash
586 \end{verbatim}
587
588 Compile the program, using the \tr{-v} (verbose) flag to verify that
589 libraries, etc., are being found properly:
590 \begin{verbatim}
591 % ghc -v -o hello Main.hs
592 \end{verbatim}
593
594 Now run it:
595 \begin{verbatim}
596 % ./hello
597 Hello, world!
598 \end{verbatim}
599
600 Some simple-but-profitable tests are to compile and run the
601 notorious \tr{nfib} program, using different numeric types.  Start
602 with \tr{nfib :: Int -> Int}, and then try \tr{Integer}, \tr{Float},
603 \tr{Double}, \tr{Rational} and maybe \tr{Complex Float}.  Code
604 for this is distributed in \tr{ghc/misc/examples/nfib/}.
605
606 For more information on how to ``drive'' GHC,
607 either do \tr{ghc -help} or consult the User's Guide (distributed in
608 \tr{ghc/docs/users_guide}).
609
610
611 %************************************************************************
612 %*                                                                      *
613 \section[Pre-supposed]{Installing pre-supposed utilities}
614 \index{pre-supposed utilities}
615 \index{utilities, pre-supposed}
616 %*                                                                      *
617 %************************************************************************
618
619 \label{sect_std-utils}
620
621 Here are the gory details about some utility programs you may need;
622 \tr{perl} and \tr{gcc} are the only important ones. (PVM is important
623 if you're going for Parallel Haskell.) The \tr{configure} script will
624 tell you if you are missing something.
625
626 \begin{description}
627 \item[Perl:]
628 \index{pre-supposed: Perl}
629 \index{Perl, pre-supposed}
630 {\em You have to have Perl to proceed!} Perl is a language quite good
631 for doing shell-scripty tasks that involve lots of text processing.
632 It is pretty easy to install.
633
634 Perl~5 is the current version; GHC should be Perl~4 friendly though.
635 For Win32 platforms, Perl~5 is recommended, we even strongly suggest
636 you pick up a port of Perl~5 for \tr{cygwin32}, as the common
637 Hip/ActiveWare port of Perl is not Cool Enough for our purposes.
638
639 Perl should be put somewhere so that it can be invoked by the \tr{#!}
640 script-invoking mechanism. (I believe \tr{/usr/bin/perl} is preferred;
641 we use \tr{/usr/local/bin/perl} at Glasgow.)  The full pathname should
642 be less than 32 characters long.
643
644 \item[GNU C (\tr{gcc}):]
645 \index{pre-supposed: GCC (GNU C compiler)}
646 \index{GCC (GNU C compiler), pre-supposed}
647 The current version is 2.7.2.
648
649 If your GCC dies with ``internal error'' on some GHC source file,
650 please let us know, so we can report it and get things improved.
651 (Exception: on \tr{iX86} boxes---you may need to fiddle with GHC's
652 \tr{-monly-N-regs} option; ask if confused...)
653
654 \item[PVM version 3:]
655 \index{pre-supposed: PVM3 (Parallel Virtual Machine)}
656 \index{PVM3 (Parallel Virtual Machine), pre-supposed}
657 PVM is the Parallel Virtual Machine on which Parallel Haskell programs
658 run.  (You only need this if you plan to run Parallel Haskell.  
659 Concurent Haskell, which runs concurrent threads on a uniprocessor
660 doesn't need it.)
661 Underneath PVM, you can have (for example) a network of
662 workstations (slow) or a multiprocessor box (faster).
663
664 The current version of PVM is 3.3.11; we use 3.3.7.  It is readily
665 available on the net; I think I got it from \tr{research.att.com}, in
666 \tr{netlib}.
667
668 A PVM installation is slightly quirky, but easy to do.  Just follow
669 the \tr{Readme} instructions.
670
671 \item[\tr{xargs} on Solaris2:]
672 \index{xargs, presupposed (Solaris only)}
673 \index{Solaris: alternative xargs}
674 The GHC libraries are put together with something like:
675 \begin{verbatim}
676 find bunch-of-dirs -name '*.o' -print | xargs ar q ...
677 \end{verbatim}
678 Unfortunately the Solaris \tr{xargs} (the shell-script equivalent
679 of \tr{map}) only ``bites off'' the \tr{.o} files a few at a
680 time---with near-infinite rebuilding of the symbol table in
681 the \tr{.a} file.
682
683 The best solution is to install a sane \tr{xargs} from the GNU
684 findutils distribution.  You can unpack, build, and install the GNU
685 version in the time the Solaris \tr{xargs} mangles just one GHC
686 library.
687
688 \item[\tr{bash} (Parallel Haskell only):]
689 \index{bash, presupposed (Parallel Haskell only)}
690 Sadly, the \tr{gr2ps} script, used to convert ``parallelism profiles''
691 to PostScript, is written in Bash (GNU's Bourne Again shell).
692 This bug will be fixed (someday).
693
694 \item[Makeindex:]
695 \index{pre-supposed: makeindex}
696 \index{makeindex, pre-supposed}
697 You won't need this unless you are re-making our documents.  Makeindex
698 normally comes with a \TeX{} distribution, but if not, we can provide
699 the latest and greatest.
700
701 \item[Tgrind:]
702 \index{pre-supposed: tgrind}
703 \index{tgrind, pre-supposed}
704 This is required only if you remake lots of our documents {\em and}
705 you use the \tr{-t tgrind} option with \tr{lit2latex} (also literate
706 programming), to do ``fancy'' typesetting of your code.  {\em
707 Unlikely.}
708
709 \item[Flex:]
710 \index{pre-supposed: flex}
711 \index{flex, pre-supposed}
712 This is a quite-a-bit-better-than-Lex lexer.  Used in the
713 literate-programming stuff.  You won't need it unless you're hacking
714 on some of our more obscure stuff.
715 On our machines, the version in @/bin@ doesn't work; you need the
716 GNU version.  Find out by saying @flex --version@ (our current version
717 is 2.5.3, but maybe earlier ones will work).  If it doesn't know about
718 the @--version@ flag, it ain't the right @flex@.
719
720 \item[Yacc:]
721 \index{pre-supposed: non-worthless Yacc}
722 \index{Yacc, pre-supposed}
723 If you mess with the Haskell parser, you'll need a Yacc that can cope.
724 The unbundled \tr{/usr/lang/yacc} is OK; the GNU \tr{bison} is OK;
725 Berkeley yacc, \tr{byacc}, is not OK.
726
727 \item[@sed@]
728 \index{pre-supposed: sed}
729 \index{sed, pre-supposed}
730 You need a working @sed@ if you are going to build from sources.
731 The build-configuration stuff needs it.
732 GNU sed version 2.0.4 is no good! It has a bug in it that is tickled
733 by the build-configuration.  2.0.5 is ok. Others are probably ok too
734 (assuming we don't create too elaborate configure scripts..)
735 \end{description}
736
737 Two @fptools@ projects are worth a quick note at this point, because
738 they are useful for all the others:
739 \begin{itemize}
740 \item @glafp-utils@ contains several utilities which aren't
741 particularly Glasgow-ish, but Occasionally Indispensable. Like
742 @lndir@ for creating symbolic link trees.
743
744 \item @literate@ contains the Glasgow-built tools for generating
745 documentation.  (The unoriginal idea is to be able to generate @latex@, @info@,
746 and program code from a single source file.) To get anywhere you'll
747 need at least @lit2pgm@, either from the @literate@ project, or
748 because it's already installed on your system. 
749 \end{itemize}
750
751
752
753 %************************************************************************
754 %*                                                                      *
755 \section[building-from-source]{Building from source}
756 \index{Building from source}
757 %*                                                                      *
758 %************************************************************************
759
760 You've been rash enough to want to build some of
761 the Glasgow Functional Programming tools (GHC, Happy,
762 nofib, etc) from source.  You've slurped the source,
763 from the CVS repository or from a source distribution, and
764 now you're sitting looking at a huge mound of bits, wondering
765 what to do next.
766
767 Gingerly, you type @make all@.  Wrong already!
768
769 This rest of this guide is intended for duffers like me, who aren't really
770 interested in Makefiles and systems configurations, but who need
771 a mental model of the interlocking pieces so that they can 
772 make them work, extend them consistently when adding new
773 software, and lay hands on them gently when they don't work.
774
775 \subsection{Your source tree}
776 \label{source-tree}
777
778 The source code is held in your {\em source tree}.
779 The root directory of your source tree {\em must}
780 contain the following directories and files:
781 \begin{itemize}
782 \item @Makefile@: the root Makefile.
783 \item @mk/@: the directory that contains the
784 main Makefile code, shared by all the
785 @fptools@ software.
786 \item @configure.in@, @config.sub@, @config.guess@:
787 these files support the configuration process.
788 \item @install-sh@.
789 \end{itemize}
790 All the other directories are individual {\em projects} of the
791 @fptools@ system --- for example, the Glasgow Haskell Compiler (@ghc@),
792 the Happy parser generator (@happy@), the @nofib@ benchmark suite, 
793 and so on.
794 You can have zero or more of these.  Needless to say, some of them
795 are needed to build others.  For example, you need @happy@ to build
796 @ghc@.  You can either grab @happy@ too, or else you can use
797 a version of @happy@ that's already installed on your system, or 
798 grab a binary distribution of @happy@ and install it.
799
800 The important thing to remember is that even if you want only one
801 project (@happy@, say), you must have a source tree whose root
802 directory contains @Makefile@, @mk/@, @configure.in@, and the
803 project(s) you want (@happy/@ in this case).  You cannot get by with
804 just the @happy/@ directory.
805
806 \subsection{Build trees}
807
808 While you can build a system in the source tree, we don't recommend it.
809 We often want to build multiple versions of our software
810 for different architectures, or with different options (e.g. profiling).
811 It's very desirable to share a single copy of the source code among
812 all these builds.
813
814 So for every source tree we have zero or more {\em build trees}.  Each
815 build tree is initially an exact copy of the source tree, except that
816 each file is a symbolic link to the source file, rather than being a
817 copy of the source file.  There are ``standard'' Unix utilities that
818 make such copies, so standard that they go by different names:
819 @lndir@, @mkshadowdir@ are two (If you don't have either, the source
820 distribution includes sources for the \tr{X11} \tr{lndir} --- check
821 out \tr{fptools/glafp-utils/lndir} ).
822
823 The build tree does not need to be anywhere near the source tree in
824 the file system.  Indeed, one advantage of separating the build tree
825 from the source is that the build tree can be placed in a
826 non-backed-up partition, saving your systems support people from
827 backing up untold megabytes of easily-regenerated, and
828 rapidly-changing, gubbins.  The golden rule is that (with a single
829 exception -- Section~\ref{sect_build-config}) {\em absolutely
830 everything in the build tree is either a symbolic link to the source
831 tree, or else is mechanically generated}.  It should be perfectly OK
832 for your build tree to vanish overnight; an hour or two compiling and
833 you're on the road again.
834
835 You need to be a bit careful, though, that any new files you create
836 (if you do any development work) are in the source tree, not a build tree!
837
838 Remember, that the source files in the build tree are {\em symbolic
839 links} to the files in the source tree.  (The build tree soon
840 accumulates lots of built files like @Foo.o@, as well.)  You can {\em
841 delete} a source file from the build tree without affecting the source
842 tree (though it's an odd thing to do).  On the other hand, if you {\em
843 edit} a source file from the build tree, you'll edit the source-tree
844 file directly.  (You can set up Emacs so that if you edit a source
845 file from the build tree, Emacs will silently create an edited copy of
846 the source file in the build tree, leaving the source file unchanged;
847 but the danger is that you think you've edited the source file whereas
848 actually all you've done is edit the build-tree copy.  More commonly
849 you do want to edit the source file.)
850
851 Like the source tree, the top level of your build tree must (a linked
852 copy of) the root directory of the @fptools@ suite.  Inside Makefiles,
853 the root of your build tree is called @$(FPTOOLS_TOP)@.  In the rest
854 of this document path names are relative to @$(FPTOOLS_TOP)@ unless
855 otherwise stated.  For example, the file @ghc/mk/target.mk@ is
856 actually @$(FPTOOLS_TOP)/ghc/mk/target.mk@.
857
858
859 \subsection{Getting the build you want}
860 \label{sect_build-config}
861
862 When you build @fptools@ you will be compiling code on a particular
863 {\em host platform}, to run on a particular {\em target platform}
864 (usually the same as the host platform)\index{platform}.  The
865 difficulty is that there are minor differences between different
866 platforms; minor, but enough that the code needs to be a bit different
867 for each.  There are some big differences too: for a different
868 architecture we need to build GHC with a different native-code
869 generator.
870
871 There are also knobs you can turn to control how the @fptools@
872 software is built.  For example, you might want to build GHC optimised
873 (so that it runs fast) or unoptimised (so that you can compile it fast
874 after you've modified it.  Or, you might want to compile it with
875 debugging on (so that extra consistency-checking code gets included)
876 or off.  And so on.
877
878 All of this stuff is called the {\em configuration} of your build.
879 You set the configuration using an exciting three-step process.
880 \begin{description}
881
882 \item[Step 1: get ready for configuration.]  Change directory to
883 @$(FPTOOLS)@ and issue the command @autoconf@ (with no
884 arguments). This GNU program converts @$(FPTOOLS)/configure.in@ to a
885 shell script called @$(FPTOOLS)/configure@.
886
887 Both these steps are completely platform-independent; they just mean
888 that the human-written file (@configure.in@) can be short, although
889 the resulting shell script, @configure@, and @mk/config.h.in@, are
890 long.
891
892 In case you don't have @autoconf@ we distribute the results,
893 @configure@, and @mk/config.h.in@, with the source distribution.  They
894 aren't kept in the repository, though.
895
896 \item[Step 2: system configuration.]
897 Runs the newly-created @configure@ script, thus:
898 \begin{verbatim}
899   ./configure
900 \end{verbatim}
901 @configure@'s mission
902 is to scurry round your computer working out what architecture it has,
903 what operating system, whether it has the @vfork@ system call,
904 where @yacc@ is kept, whether @gcc@ is available, where various
905 obscure @#include@ files are, whether it's a leap year, and
906 what the systems manager had for lunch.
907 It communicates these snippets of information in two ways:
908 \begin{itemize}
909 \item It translates @mk/config.mk.in@ to @mk/config.mk@,
910 substituting for things between ``{\tt @@@@}'' brackets.  So,
911 ``{\tt @@HaveGcc@@}'' will be replaced by ``@YES@'' or ``@NO@''
912 depending on what @configure@ finds.
913 @mk/config.mk@ is included by every Makefile (directly or indirectly),
914 so the configuration information is thereby communicated to
915 all Makefiles.
916
917 \item It translates @mk/config.h.in@ to @mk/config.h@.
918 The latter is @#include@d by various C programs, which
919 can thereby make use of configuration information.
920 \end{itemize}
921 @configure@ caches the results of its run in @config.cache@.
922 Quite often you don't want that; you're running @configure@ a second time
923 because something has changed.  In that case, simply delete @config.cache@.
924
925 \item[Step 3: build configuration.] Next, you say how this build
926 of @fptools@ is to differ from the standard defaults by creating a new 
927 file @mk/build.mk@
928 {\em in the build tree}.  This file is the one and only
929 file you edit in the build tree, precisely because it says how
930 this build differs from the source.  (Just in case your build tree
931 does die, you might want to keep a private directory of @build.mk@ files,
932 and use a symbolic link in each build tree to point to the appropriate one.)
933 So @mk/build.mk@ never
934 exists in the source tree --- you create one in each build tree
935 from the template.  We'll discuss what to put in it shortly.
936 \end{description}
937 And that's it for configuration. Simple, eh?
938
939 What do you put in your build-specific configuration
940 file @mk/build.mk@?  {\em For almost all purposes all you will do is
941 put make variable definitions that override those in @mk/config.mk.in@}.
942 The whole point of @mk/config.mk.in@ --- and its derived 
943 counterpart @mk/config.mk@ --- is to define the build configuration. It is heavily
944 commented, as you will see if you look at it.
945 So generally, what you do is edit @mk/config.mk.in@ (read-only), and add definitions
946 in @mk/build.mk@ that override any of the @config.mk@ definitions that you
947 want to change.  (The override occurs because the main boilerplate file,
948 @mk/boilerplate.mk@, includes @build.mk@ after @config.mk@.)
949
950 For example, @config.mk.in@ contains the definition:
951 \begin{verbatim}
952   ProjectsToBuild = glafp-utils literate happy ghc hslibs
953 \end{verbatim}
954 The accompanying comment explains that this is the list of enabled
955 projects; that is, if (after configuring) you type @gmake all@
956 in @FPTOOLS_TOP@ three specified projects will be made.
957 If you want to add @green-card@, you can add this line to @build.mk@:
958 \begin{verbatim}
959   ProjectsToBuild += green-card
960 \end{verbatim}
961 or, if you prefer,
962 \begin{verbatim}
963   ProjectsToBuild = glafp-utils literate happy ghc hslibs green-card
964 \end{verbatim}
965 (GNU @make@ allows existing definitions to have new text appended using
966 the ``@+=@'' operator, which is quite a convenient feature.)
967
968 When reading @config.mk.in@, remember that anything between ``{\tt @@...@@}'' signs
969 is going to be substituted by @configure@ later.  You {\em can} override
970 the resulting definition if you want, 
971 but you need to be a bit surer what you are doing.
972 For example, there's a line that says:
973 \begin{verbatim}
974   YACC = @Yacc@
975 \end{verbatim}
976 This defines the Make variables @YACC@ to the pathname for a Yacc that
977 @configure@ finds somewhere.  If you have your own pet Yacc you want
978 to use instead, that's fine. Just add this line to @mk/build.mk@:
979 \begin{verbatim}
980   YACC = myyacc
981 \end{verbatim}
982 You do not {\em have} to have a @mk/build.mk@ file at all; if you don't,
983 you'll get all the default settings from @mk/config.mk.in@.
984
985 You can also use @build.mk@ to override anything that @configure@ got
986 wrong.  One place where this happens often is with the definition of
987 @FPTOOLS_TOP_ABS@: this variable is supposed to be the canonical path
988 to the top of your source tree, but if your system uses an automounter
989 then the correct directory is hard to find automatically.  If you find
990 that @configure@ has got it wrong, just put the correct definition in
991 @build.mk@.
992
993 \subsection{The story so far}
994
995 Let's summarise the steps you need to carry to get yourself
996 a fully-configured build tree from scratch.
997
998 \begin{enumerate}
999 \item Get your source tree from somewhere (CVS repository or
1000 source distribution).  Say you call the root directory
1001 @myfptools@ (it does not have to be called @fptools@).
1002 Make sure that you have the essential files (see Section~\ref{source-tree}).
1003
1004 \item Use @lndir@ or @mkshadowdir@ to create a build tree.
1005 \begin{verbatim}
1006     cd myfptools
1007     mkshadowdir . /scratch/joe-bloggs/myfptools-sun4
1008 \end{verbatim}
1009 You probably want to give the build tree a name that
1010 suggests its main defining characteristic (in your mind at least),
1011 in case you later add others.
1012
1013 \item Change directory to the build tree.  Everything is going
1014 to happen there now.
1015 \begin{verbatim}
1016     cd /scratch/joe-bloggs/myfptools-sun4
1017 \end{verbatim}
1018 \item Prepare for system configuration:
1019 \begin{verbatim}
1020     autoconf
1021 \end{verbatim}
1022 (You can skip this step if you are starting from a source distribution,
1023 and you already have @configure@ and @mk/config.h.in@.)
1024
1025 \item Do system configuration:
1026 \begin{verbatim}
1027     ./configure
1028 \end{verbatim}
1029
1030 \item Create the file @mk/build.mk@, 
1031 adding definitions for your desired configuration options.
1032 \begin{verbatim}
1033     emacs mk/build.mk
1034 \end{verbatim}
1035 \end{enumerate}
1036 You can make subsequent changes to @mk/build.mk@ as often 
1037 as you like.  You do not have to run any further configuration 
1038 programs to make these changes take effect.
1039 In theory you should, however, say @gmake clean@, @gmake all@,
1040 because configuration option changes could affect anything --- but in practice you are likely to know what's affected.
1041
1042 \subsection{Making things}
1043
1044 At this point you have made yourself a fully-configured build tree,
1045 so you are ready to start building real things.
1046
1047 The first thing you need to know is that 
1048 {\em you must use GNU @make@, usually called @gmake@, not standard Unix @make@}.
1049 If you use standard Unix @make@ you will get all sorts of error messages
1050 (but no damage) because the @fptools@ @Makefiles@ use GNU @make@'s facilities
1051 extensively.
1052
1053 \subsection[sect_standard-targets]{Standard targets}
1054
1055 In any directory you should be able to make the following:
1056 \begin{description}
1057 \item[@boot@:] does the one-off preparation required to get ready
1058 for the real work.  Notably, it does @gmake depend@ in all directories
1059 that contain programs.  But @boot@ does more.  For example, you can't
1060 do @gmake depend@ in a directory of C program until you have converted
1061 the literate @.lh@ header files into standard @.h@ header files.
1062 Similarly, you convert a literate file to illiterate form until you
1063 have built the @literate@ tools.  @boot@ takes care of these
1064 inter-directory dependencies.
1065
1066 You should say @gmake boot@ right after configuring your build tree,
1067 but note that this is a one-off, i.e., there's no need to re-do
1068 @gmake boot@ if you should re-configure your build tree at a later
1069 stage (no harm caused if you do though).
1070
1071 \item[@all@:] makes all the final target(s) for this Makefile.
1072 Depending on which directory you are in a ``final target''
1073 may be an executable program, a library archive, a shell script,
1074 or a Postscript file.
1075 Typing @gmake@ alone is generally the same as typing @gmake all@.
1076
1077 \item[@install@:] installs the things built by @all@.  Where does it
1078 install them?  That is specified by @mk/config.mk.in@; you can 
1079 override it in @mk/build.mk@.
1080
1081 \item[@uninstall@:] reverses the effect of @install@.
1082
1083 \item[@clean@:] remove all easily-rebuilt files.
1084
1085 \item[@veryclean@:] remove all files that can be rebuilt at all.
1086 There's a danger here that you may remove a file that needs a more
1087 obscure 
1088 utility to rebuild it (especially if you started from a source
1089 distribution).
1090
1091 \item[@check@:] run the test suite.
1092 \end{description}
1093 All of these standard targets
1094 automatically recurse into sub-directories.
1095 Certain other standard targets do not:
1096 \begin{description}
1097 \item[@configure@:] is only available in the root directory @$(FPTOOLS)@;
1098 it has been discussed in Section~\ref{sect_build-config}.
1099
1100 \item[@depend@:] make a @.depend@ file in each directory that needs
1101 it. This @.depend@ file contains mechanically-generated dependency
1102 information; for example, suppose a directory contains a Haskell 
1103 source module @Foo.lhs@ which imports another module @Baz@.
1104 Then the generated @.depend@ file will contain the dependency:
1105 \begin{verbatim}
1106   Foo.o : Baz.hi
1107 \end{verbatim}
1108 which says that the object file @Foo.o@ depends on the interface
1109 file @Baz.hi@ generated by compiling module @Baz@.
1110 The @.depend@ file is automatically included by every Makefile.
1111
1112 \item[@binary-dist@:] make a binary distribution.
1113
1114 \item[@dist@:] make a source distribution.
1115 \end{description}
1116
1117 \subsection{Other targets}
1118
1119 Most @Makefiles@ have targets other than these.  You can find
1120 this out by looking in the @Makefile@ itself.
1121
1122
1123
1124
1125 %************************************************************************
1126 %*                                                                      *
1127 \section{The @Makefile@ architecture}
1128 %*                                                                      *
1129 %************************************************************************
1130
1131
1132 @make@ is great if everything works --- you type @gmake install@ and, lo,
1133 the right things get compiled and installed in the right places.
1134 Our goal is to make this happen often, but somehow it often doesn't;
1135 instead
1136 some wierd error message eventually emerges from the bowels of a directory
1137 you didn't know existed.
1138
1139 The purpose of this section is to give you a road-map to help you figure
1140 out what is going right and what is going wrong.
1141
1142 \subsection{A small project}
1143
1144 To get started, let us look at the @Makefile@ for an imaginary small
1145 @fptools@ project, @small@.  Each project in @fptools@ has its own
1146 directory in @FPTOOLS_TOP@, so the @small@ project will have its own
1147 directory @FPOOLS_TOP/small/@.  Inside the @small/@ directory there
1148 will be a @Makefile@, looking something like this:
1149 \begin{verbatim}
1150   #     Makefile for fptools project "small"
1151
1152   TOP = ..
1153   include $(TOP)/mk/boilerplate.mk
1154
1155   SRCS = $(wildcard *.lhs) $(wildcard *.c)
1156   HS_PROG = small
1157
1158   include $(TOP)/target.mk
1159 \end{verbatim}
1160 This @Makefile@ has three sections:
1161 \begin{enumerate}
1162 \item The first section includes\footnote{One of the
1163 most important features of GNU @make@ that we use is the ability
1164 for a @Makefile@ to include another named file, very like @cpp@'s @#include@ directive.}
1165 a file of ``boilerplate'' code from the
1166 level above (which in this case will be @FPTOOLS_TOP/mk/boilerplate.mk@).
1167 As its name suggests, @boilerplate.mk@ consists of a large quantity of standard
1168 @Makefile@ code.  We discuss this boilerplate in more detail in Section~\ref{sect_boiler}.
1169
1170 Before the @include@ statement, you must define the @make@ variable
1171 @TOP@ to be the directory containing the @mk@ directory in which
1172 the @boilerplate.mk@ file is.
1173 It is {\em not} OK to simply say
1174 \begin{verbatim}
1175   include ../mk/boilerplate.mk  # NO NO NO
1176 \end{verbatim}
1177 Why?  Because the @boilerplate.mk@ file needs to know where it is,
1178 so that it can, in turn, @include@ other files.
1179 (Unfortunately, when an @include@d file does an
1180 @include@, the filename is treated
1181 relative to the directory in which @gmake@ is being run, not
1182 the directory in which the @included@ sits.) 
1183 In general,
1184 {\em every file @foo.mk@ 
1185 assumes that @$(TOP)/mk/foo.mk@ refers to itself.}  
1186 It is up to the @Makefile@ doing the @include@ to ensure this
1187 is the case.
1188
1189 Files intended for inclusion in other @Makefile@s are written to have
1190 the following property:
1191 {\em after @foo.mk@ is @include@d, it leaves @TOP@ containing the same
1192 value as it had just before the @include@ statement}.
1193 In our example, this invariant guarantees that the @include@
1194 for @target.mk@ will look in the same directory as that for
1195 @boilerplate.mk@.
1196
1197 \item The second section 
1198 defines the following standard @make@ variables: @SRCS@ (the source files from
1199 which is to be built), and @HS_PROG@ (the
1200 executable binary to be built).  
1201 We will discuss in more detail what the ``standard variables'' are,
1202 and how they affect what happens, in Section~\ref{sect_targets}.
1203
1204 The definition for @SRCS@ uses the useful GNU @make@
1205 construct @$(wildcard@~$pat$@)@, which expands to a list of all the
1206 files matching the pattern $pat$ in the current directory.
1207 In this example, @SRCS@ is set to the list of all the @.lhs@ and @.c@ files
1208 in the directory.  (Let's suppose there is one of each, @Foo.lhs@
1209 and @Baz.c@.)
1210
1211 \item The last section includes a second file of standard code,
1212 called @target.mk@.  It contains the rules that tell @gmake@
1213 how to make the standard targets
1214 (Section~\ref{sect_standard-targets}).
1215 Why, you ask, can't this standard code
1216 be part of @boilerplate.mk@?  Good question.
1217 We discuss the reason later, in Section~\ref{sect_boiler-arch}.
1218
1219 You do not {\em have} to @include@ the @target.mk@ file.  Instead,
1220 you can write rules of your own for all the standard targets.
1221 Usually, though, you will find quite a big payoff from using
1222 the canned rules in
1223 @target.mk@; the price tag is that you have to understand
1224 what canned rules get enabled, and what they do (Section~\ref{sect_targets}).
1225 \end{enumerate}
1226
1227 In our example @Makefile@, most of the work is done 
1228 by the two @include@d files.  When you say @gmake all@,
1229 the following things happen:
1230 \begin{itemize}
1231 \item @gmake@ figures out that the object files are @Foo.o@ and @Baz.o@.
1232 \item It uses a boilerplate pattern rule to compile 
1233 @Foo.lhs@ to @Foo.o@ using
1234 a Haskell compiler.  (Which one?  That is set in the build configuration.)
1235 \item It uses another standard pattern rule to compile @Baz.c@ to @Baz.o@,
1236 using a C compiler.  (Ditto.)
1237 \item It links the resulting @.o@ files together to make @small@,
1238 using the Haskell compiler to do the link step.  (Why not use @ld@?  Because
1239 the Haskell compiler knows what standard librarise to link in.  How did @gmake@
1240 know to use the Haskell compiler to do the link, rather than the C compiler?
1241 Because we set the variable @HS_PROG@ rather than @C_PROG@.)
1242 \end{itemize}
1243 All @Makefile@s should follow the above three-section format.
1244
1245 \subsection{A larger project}
1246
1247 Larger projects are usually structured into a nummber of sub-directories,
1248 each of which has its own @Makefile@.  (In very large projects, this
1249 sub-structure might be iterated recursively, though that is rare.)
1250 To give you the idea, here's part of the directory structure for
1251 the (rather large) @ghc@ project:
1252 \begin{verbatim}
1253   $(FPTOOLS_TOP)/ghc/
1254     Makefile
1255
1256     mk/
1257       boilerplate.mk
1258       rules.mk
1259
1260     docs/
1261       Makefile
1262       ...source files for documentation...
1263
1264     driver/
1265       Makefile
1266       ...source files for driver...
1267
1268     compiler/
1269       Makefile
1270       parser/...source files for parser...
1271       renamer/...source files for renamer...
1272       ...etc...
1273 \end{verbatim}
1274 The sub-directories @docs@, @driver@, @compiler@, and so on, each contains
1275 a sub-component of @ghc@, and each has its own @Makefile@.
1276 There must also be a @Makefile@ in @$(FPTOOLS_TOP)/ghc@.
1277 It does most of its work by recursively invoking @gmake@
1278 on the @Makefile@s in the sub-directories.
1279 We say that @ghc/Makefile@ is a {\em non-leaf @Makefile@},
1280 because it does little except organise its children, while the @Makefile@s
1281 in the sub-directories are all {\em leaf @Makefile@s}.  (In principle
1282 the sub-directories might themselves contain a non-leaf @Makefile@ and
1283 several sub-sub-directories, but that does not happen in @ghc@.)
1284
1285 The @Makefile@ in @ghc/compiler@ is considered a leaf @Makefile@ even
1286 though the @ghc/compiler@ has sub-directories, because these sub-directories
1287 do not themselves have @Makefile@ in them.  They are just used to structure
1288 the collection of modules that make up @ghc@, but all are managed by the
1289 single @Makefile@ in @ghc/compiler@.
1290
1291 You will notice that @ghc/@ also contains a directory @ghc/mk/@.
1292 It contains @ghc@-specific @Makefile@ boilerplate code.
1293 More precisely:
1294 \begin{itemize}
1295 \item @ghc/mk/boilerplate.mk@ is included at the top of @ghc/Makefile@,
1296 and of all the leaf @Makefile@s in the sub-directories.
1297 It in turn @include@s the main boilerplate file @mk/boilerplate.mk@.
1298
1299 \item @ghc/mk/target.mk@ is @include@d at the bottom of @ghc/Makefile@,
1300 and of all the leaf @Makefiles@ in the sub-directories.
1301 It in turn @include@s the file @mk/target.mk@.
1302 \end{itemize}
1303 So these two files are the place to look for @ghc@-wide customisation
1304 of the standard boilerplate.
1305
1306
1307
1308 \subsection{Boilerplate architecture}
1309 \label{sect_boiler-arch}
1310
1311 Every @Makefile@ includes a @boilerplate.mk@ file at the top,
1312 and @target.mk@ file at the bottom.  In this section we discuss
1313 what is in these files, and why there have to be two of them.
1314 In general:
1315 \begin{itemize}
1316 \item @boilerplate.mk@ consists of:
1317 \begin{itemize}
1318 \item {\em Definitions of millions of @make@ variables} that collectively
1319 specify the build configuration.  Examples: @HC_OPTS@, the options to
1320 feed to the Haskell compiler; @NoFibSubDirs@, the sub-directories to
1321 enable within the @nofib@ project; @GhcWithHc@, the name of the
1322 Haskell compiler to use when compiling @GHC@ in the @ghc@ project.
1323 \item {\em Standard pattern rules} that tell @gmake@ how to construct
1324 one file from another.  
1325 \end{itemize}
1326 @boilerplate.mk@ needs to be @include@d at the {\em top} of each 
1327 @Makefile@, so that the 
1328 user can replace the boilerplate definitions or pattern rules by simply 
1329 giving a new definition or pattern rule in the @Makefile@.  @gmake@ simply
1330 takes the last definition as the definitive one.
1331
1332 Instead of {\em replacing} boilerplate definitions, it is also quite
1333 common to {\em augment} them. For example, a @Makefile@ might say:
1334 \begin{verbatim}
1335   SRC_HC_OPTS += -O
1336 \end{verbatim}
1337 thereby adding ``@-O@'' to the end of @SRC_HC_OPTS@. 
1338
1339 \item @target.mk@ contains @make@ rules for the standard targets described
1340 in Section~\ref{sect_standard-targets}.
1341 These rules are selectively included, depending on the setting of
1342 certain @make@ variables.  These variables are usually set in the middle
1343 section of the @Makefile@ between the two @include@s.
1344
1345 @target.mk@ must be included at the end (rather than being part of @boilerplate.mk@)
1346 for several tiresome reasons:
1347 \begin{itemize}
1348 \item @gmake@ commits target and dependency lists earlier than it should.
1349 For example, @target.mk@ has a rule that looks like this:
1350 \begin{verbatim}
1351   $(HS_PROG) : $(OBJS)
1352         $(HC) $(LD_OPTS) $< -o $@
1353 \end{verbatim}
1354 If this rule was in @boilerplate.mk@ then @$(HS_PROG)@ and @$(OBJS)@
1355 would not have their final values at the moment @gmake@ encountered the
1356 rule.  Alas, @gmake@ takes a snapshot of their current values, and 
1357 wires that snapshot into the rule.
1358 (In contrast, the commands executed when the rule ``fires'' are
1359 only substituted at the moment of firing.)
1360 So, the rule must follow the definitions given in the @Makefile@ itself.
1361
1362 \item Unlike pattern rules, ordinary rules cannot be overriden or
1363 replaced by subsequent rules for the same target (at least not without an
1364 error message).  Including ordinary rules in @boilerplate.mk@ would
1365 prevent the user from writing rules for specific targets in specific cases.
1366
1367 \item There are a couple of other reasons I've forgotten, but it doesn't
1368 matter too much.
1369 \end{itemize}
1370 \end{itemize}
1371
1372 \subsection{The main @mk/boilerplate.mk@ file}
1373 \label{sect_boiler}
1374
1375 If you look at @$(FPTOOLS_TOP)/mk/boilerplate.mk@ you will find that
1376 it consists of the following sections, each held in a separate file:
1377 \begin{description}
1378 \item[@config.mk@] is the build configuration file we discussed at length
1379 in Section~\ref{sect_build-config}.
1380
1381 \item[@paths.mk@] defines @make@ variables for pathnames and file
1382 lists.  In particular, it gives definitions for:
1383 \begin{description}
1384 \item[@SRCS@:] all source files in the current directory.
1385 \item[@HS_SRCS@:] all Haskell source files in the current directory.
1386 It is derived from @$(SRCS)@, so if you override @SRCS@ with a new value
1387 @HS_SRCS@ will follow suit.
1388 \item[@C_SRCS@:] similarly for C source files.
1389 \item[@HS_OBJS@:] the @.o@ files derived from @$(HS_SRCS)@.
1390 \item[@C_OBJS@:] similarly for @$(C_SRCS)@.
1391 \item[@OBJS@:] the concatenation of @$(HS_OBJS)@ and @$(C_OBJS)@.
1392 \end{description}
1393 Any or all of these definitions can easily be overriden by giving new
1394 definitions in your @Makefile@.  For example, 
1395 if there are things in the current directory that look like source files
1396 but aren't, then you'll need to set @SRCS@ manually in your @Makefile@.
1397 The other definitions will then work from this new definition.
1398
1399 What, exactly, does @paths.mk@ consider a ``source file'' to be.
1400 It's based the file's suffix (e.g. @.hs@, @.lhs@, @.c@, @.lc@, etc), 
1401 but this is the kind of detail that changes
1402 more rapidly, so rather than enumerate the source suffices here the best thing
1403 to do is to look in @paths.mk@.
1404
1405 \item[@opts.mk@] defines @make@ variables for option strings to
1406 pass to each program. For example, it defines @HC_OPTS@, the
1407 option strings to pass to the Haskell compiler.  See  \sectionref{sect_suffix}.
1408
1409 \item[@suffix.mk@] defines standard pattern rules -- see \sectionref{sect_suffix}
1410 \end{description}
1411 Any of the variables and pattern rules defined by the boilerplate file
1412 can easily be overridden in any particular @Makefile@, because
1413 the boilerplace @include@ comes first.  Definitions after this
1414 @include@ directive simply override the default ones in @boilerplate.mk@.
1415
1416 \subsection[sect_suffix]{Pattern rules and options}
1417
1418 The file @suffix.mk@ defines standard {\em pattern rules} that say how to build one kind
1419 of file from another, for example, how to build a @.o@ file from a @.c@ file.
1420 (GNU @make@'s {\em pattern rules} are more powerful and easier to use than
1421 Unix @make@'s {\em suffix rules}.)
1422
1423 Almost all the rules look something like this:
1424 \begin{verbatim}
1425 %.o : %.c
1426         @$(RM) $@
1427         $(CC) $(CC_OPTS) -c $< -o $@
1428 \end{verbatim}
1429 Here's how to understand the rule.  It says that $something@.o@$ (say @Foo.o@)
1430 can be built from $something@.c@$ (@Foo.c@), by invoking the C compiler
1431 (path name held in @$(CC)@), passing to it the options @$(CC_OPTS)@ and the rule's 
1432 dependent
1433 file of the rule @$<@ (@Foo.c@ in this case), and putting the result in
1434 the rule's target @$@@@ (@Foo.o@ in this case).
1435
1436 Every program is held in a @make@ variable defined in @mk/config.mk@ --- look in @mk/config.mk@ for
1437 the complete list.  One important one is the Haskell compiler, which is called @$(HC)@.
1438
1439 Every programs options are are held in a @make@ variables called @<prog>_OPTS@.
1440 the @<prog>_OPTS@ variables are defined in @mk/opts.mk@.  Almost all of them are defined
1441 like this:
1442 \begin{verbatim}
1443   CC_OPTS = $(SRC_CC_OPTS) $(WAY$(_way)_CC_OPTS) $($*_CC_OPTS) $(EXTRA_CC_OPTS)
1444 \end{verbatim}
1445 The four variables from which @CC_OPTS@ is built have the following meaning:
1446 \begin{description}
1447 \item[@SRC_CC_OPTS@:] options passed to all C compilations.
1448 \item[@WAY_<way>_CC_OPTS@:] options passed to C compilations for way @<way>@. For example,
1449 @WAY_mp_CC_OPTS@ gives options to pass to the C compiler when compiling way @mp@.
1450 The variable @WAY_CC_OPTS@ holds options to pass to the C compiler when compiling the standard way.
1451 (Section~\ref{sect_ways} dicusses multi-way compilation.)
1452 \item[@<module>_CC_OPTS@:] options to pass to the C compiler that are specific to module @<module>@.
1453 For example, @SMap_CC_OPTS@ gives the specific options to pass to the C compiler when compiling
1454 @SMap.c@.
1455 \item[@EXTRA_CC_OPTS@:] extra options to pass to all C compilations.  This is intended for command
1456 line use, thus;
1457 \begin{verbatim}
1458   gmake libHS.a EXTRA_CC_OPTS="-v"
1459 \end{verbatim}
1460 \end{description}
1461
1462
1463 \subsection{The main @mk/target.mk@ file}
1464 \label{sect_targets}
1465
1466 @target.mk@ contains canned rules for all the standard targets described in
1467 Section~\ref{sect_standard-targets}.  It is complicated by the fact
1468 that you don't want all of these rules to be active in every @Makefile@.
1469 Rather than have a plethora of tiny files which you can include selectively,
1470 there is a single file, @target.mk@, which selectively includes rules 
1471 based on whether you have defined certain variables in your @Makefile@.
1472 This section explains what rules you get, what variables control them, and 
1473 what the rules do.  Hopefully, you will also get enough of an idea of what is supposed
1474 to happen that you can read and understand any wierd special cases yourself.
1475
1476 \begin{description}
1477 \item[@HS_PROG@.]  If @HS_PROG@ is defined, you get rules with the
1478 following targets:
1479 \begin{description}
1480 \item[@HS_PROG@] itself.  This rule links @$(OBJS)@ with the Haskell
1481 runtime system to get an executable called @$(HS_PROG)@.
1482 \item[@install@] installs @$(HS_PROG)@ in @$(bindir)@ with the execute bit set.
1483 \end{description}
1484
1485 \item[@C_PROG@] is similar to @HS_PROG@, except that the link step
1486 links @$(C_OBJS)@ with the C runtime system.
1487
1488 \item[@LIBRARY@] is similar to @HS_PROG@, except
1489 that it links @$(LIB_OBJS)@ to make the library archive @$(LIBRARY)@,
1490 and @install@ installs it in @$(libdir)@, with the execute bit not set.
1491
1492 \item[@LIB_DATA@] ...
1493 \item[@LIB_EXEC@] ...
1494
1495 \item[@HS_SRCS@, @C_SRCS@.] If @HS_SRCS@ is defined and non-empty, a rule for
1496 the target @depend@ is included, which generates dependency information for
1497 Haskell programs.  Similarly for @C_SRCS@.
1498 \end{description}
1499
1500 All of these rules are ``double-colon'' rules, thus
1501 \begin{verbatim}
1502   install :: $(HS_PROG)
1503         ...how to install it...
1504 \end{verbatim}
1505 GNU @make@ treats double-colon rules as separate entities.  If there
1506 are several double-colon rules for the same target it takes each in turn
1507 and fires it if its dependencies say to do so.  This means that you can,
1508 for example, define both @HS_PROG@ and @LIBRARY@, which will generate two
1509 rules for @install@.  When you type @gmake install@ both rules will be fired,
1510 and both the program and the library will be installed, just as you wanted.
1511
1512 \subsection{Recursion}
1513 \label{sect_subdirs}
1514
1515 In leaf @Makefiles@ the variable @SUBDIRS@ is undefined.  In non-leaf
1516 @Makefiles@, @SUBDIRS@ is set to the list of sub-directories that contain subordinate
1517 @Makefile@s.  {\em It is up to you to set @SUBDIRS@ in the @Makefile@.}
1518 There is no automation here --- @SUBDIRS@ is too important automate.
1519
1520 When @SUBDIRS@ is defined, @target.mk@ includes a rather neat rule for
1521 the standard targets (Section~\ref{sect_standard-targets}) that 
1522 simply invokes @make@ recursively in each of the sub-directories.
1523
1524 {\em These recursive invocations are guaranteed to occur in the order in 
1525 which the list of directories is specified in @SUBDIRS@.}  This guarantee can
1526 be important.  For example, when you say @gmake boot@ it can be important
1527 that the recursive invocation of @make boot@ is done in one sub-directory (the include
1528 files, say) before another (the source files).
1529 Generally, put the most independent sub-directory first, and the most dependent
1530 last.
1531
1532 \subsection{Way management}
1533 \label{sect_ways}
1534
1535 We sometimes want to build essentially the same system in several different
1536 ``ways''.  For example, we want to build @ghc@'s @Prelude@ libraries with
1537 and without profiling, with and without concurrency, and so on, so that
1538 there is an appropriately-built library archive to link with when the user compiles
1539 his program.
1540 It would be possible to have a completely separate build tree for each such ``way'',
1541 but it would be horribly bureaucratic, especially since often only parts of the
1542 build tree need to be constructed in multiple ways.
1543
1544 Instead, the @template.mk@ contains some clever magic to allow you to build
1545 several versions of a system; and to control locally how many versions are built
1546 and how they differ.  This section explains the magic.
1547
1548 The files for a particular way are distinguished by munging the suffix.
1549 The ``normal way'' is always built, and its files have the standard suffices
1550 @.o@, @.hi@, and so on.  In addition, you can build one or more extra ways,
1551 each distinguished by a {\em way tag}.  The object files and interface files
1552 for one of these extra ways are distinguished by their suffix.  For example,
1553 way @mp@ has files @.mp_o@ and @.mp_hi@.  Library archives have their way
1554 tag the other side of the dot, for boring reasons; thus, @libHS_mp.a@.
1555
1556 A @make@ variable called @way@ holds the current way tag.  {\em @way@ is only ever
1557 set on the command line of a recursive invocation of @gmake@.}  It is
1558 never set inside a @Makefile@.  So it is a global constant for any one invocation
1559 of @gmake@.  Two other @make@ variables, @way_@ and @_way@ are immediately derived
1560 from @$(way)@ and never altered.  If @way@ is not set, then neither are @way_@
1561 and @_way@, and the invocation of @make@ will build the ``normal way''.
1562 If @way@ is set, then the other two variables are set in sympathy. 
1563 For example, if @$(way)@ is ``@mp@'', then @way_@ is set to ``@mp_@''
1564 and @_way@ is set to ``@_mp@''.   These three variables are then used
1565 when constructing file names.
1566
1567 So how does @make@ ever get recursively invoked with @way@ set?  There
1568 are two ways in which this happens:
1569 \begin{itemize}
1570 \item For some (but not all) of the standard targets, when in a leaf sub-directory,
1571 @make@ is recursively invoked for each way tag in @$(WAYS)@.  You set @WAYS@ to
1572 the list of way tags you want these targets built for.  The mechanism here is
1573 very much like the recursive invocation of @make@ in sub-directories
1574 (Section~\ref{sect_subdirs}).
1575
1576 It is up to you to set @WAYS@ in your @Makefile@; this is how you control
1577 what ways will get built.
1578 \item For a useful collection of targets (such as @libHS_mp.a@, @Foo.mp_o@)
1579 there is a rule which recursively invokes @make@ to make the specified
1580 target, setting the @way@ variable.  So if you say @gmake Foo.mp_o@
1581 you should see a recursive invocation @gmake Foo.mp_o way=mp@,
1582 and {\em in this recursive invocation the pattern rule for compiling a Haskell
1583 file into a @.o@ file will match}.  The key pattern rules (in @suffix.mk@)
1584 look like this:
1585 \begin{verbatim}
1586   %.$(way_)o : %.lhs
1587         $(HC) $(HC_OPTS) $< -o $@
1588 \end{verbatim}
1589 Neat, eh?
1590 \end{itemize}
1591
1592
1593 \subsection{When the canned rule isn't right}
1594
1595 Sometimes the canned rule just doesn't do the right thing.  For example, in 
1596 the @nofib@ suite we want the link step to print out timing information.
1597 The thing to do here is {\em not} to define @HS_PROG@ or @C_PROG@, and instead
1598 define a special purpose rule in your own @Makefile@.
1599 By using different variable names you will avoid the canned rules being included,
1600 and conflicting with yours.
1601
1602
1603 %************************************************************************
1604 %*                                                                      *
1605 \section[booting-from-C]{Booting/porting from C (\tr{.hc}) files}
1606 \index{building GHC from .hc files}
1607 \index{booting GHC from .hc files}
1608 %*                                                                      *
1609 %************************************************************************
1610
1611 This section is for people trying to get GHC going by using the
1612 supplied intermediate C (\tr{.hc}) files.  This would probably be
1613 because no binaries have been provided, or because the machine
1614 is not ``fully supported.''
1615
1616 The intermediate C files are normally made available together with a
1617 source release, please check the announce message for exact directions
1618 of where to find them. If we've haven't made them available or you
1619 can't find them, please ask.
1620
1621 Assuming you've got them, unpack them on top of a fresh source tree.
1622 Then follow the `normal' instructions in
1623 \sectionref{building-from-source} for setting up a build tree and
1624 configuring it. The only extra thing to remember when booting from
1625 \tr{.hc} files is to add the following line to the \tr{build.mk}
1626 file:
1627
1628 \begin{verbatim}
1629 GhcWithHscBuiltViaC=YES
1630 \end{verbatim}
1631
1632 and proceed with doing a \tr{make boot} followed by a \tr{make all}.
1633
1634 That's the mechanics of the boot process, but, of course, if you're
1635 trying to boot on a platform that is not supported and significantly
1636 `different' from any of the supported ones, this is only the start
1637 of the adventure...(ToDo: porting tips - stuff to look out for, etc.)
1638
1639
1640 %************************************************************************
1641 %*                                                                      *
1642 \section[build-pitfalls]{Known pitfalls in building Glasgow Haskell}
1643 \index{problems, building}
1644 \index{pitfalls, in building}
1645 \index{building pitfalls}
1646 %*                                                                      *
1647 %************************************************************************
1648
1649 WARNINGS about pitfalls and known ``problems'':
1650
1651 \begin{enumerate}
1652 %------------------------------------------------------------------------
1653 \item
1654 One difficulty that comes up from time to time is running out of space
1655 in \tr{/tmp}.  (It is impossible for the configuration stuff to
1656 compensate for the vagaries of different sysadmin approaches re temp
1657 space.)
1658
1659 The quickest way around it is \tr{setenv TMPDIR /usr/tmp} or
1660 even \tr{setenv TMPDIR .} (or the equivalent incantation with the
1661 shell of your choice).
1662
1663 The best way around it is to say
1664 \begin{verbatim}
1665 export TMPDIR=<dir>
1666 \end{verbatim}
1667 in your @build.mk@ file.
1668 Then GHC and the other @fptools@ programs will use the appropriate directory
1669 in all cases.
1670
1671 %------------------------------------------------------------------------
1672 \item
1673 In compiling some support-code bits, e.g., in \tr{ghc/runtime/gmp} and
1674 even in \tr{ghc/lib}, you may get a few C-compiler warnings.  We think
1675 these are OK.
1676
1677 %------------------------------------------------------------------------
1678 \item
1679 When compiling via C, you'll sometimes get ``warning:
1680 assignment from incompatible pointer type'' out of GCC.  Harmless.
1681
1682 %------------------------------------------------------------------------
1683 \item
1684 Similarly, \tr{ar}chiving warning messages like the following are not
1685 a problem:
1686 \begin{verbatim}
1687 ar: filename GlaIOMonad__1_2s.o truncated to GlaIOMonad_
1688 ar: filename GlaIOMonad__2_2s.o truncated to GlaIOMonad_
1689 ...
1690 \end{verbatim}
1691
1692 %------------------------------------------------------------------------
1693 \item
1694 Also harmless are some specialisation messages that you may see when
1695 compiling GHC; e.g.:
1696 \begin{verbatim}
1697 SPECIALISATION MESSAGES (Desirable):
1698 *** INSTANCES
1699 {-# SPECIALIZE instance Eq [Class] #-}
1700 {-# SPECIALIZE instance Eq (Class, [Class]) #-}
1701 {-# SPECIALIZE instance Outputable [ClassOp] #-}
1702 {-# SPECIALIZE instance Outputable [Id] #-}
1703 \end{verbatim}
1704
1705 %------------------------------------------------------------------------
1706 \item
1707 In compiling the compiler proper (in \tr{compiler/}), you {\em may} get an
1708 ``Out of heap space'' error message.  These
1709 can vary with the vagaries of different systems, it seems.  The
1710 solution is simple: (1)~add a suitable \tr{-H} flag to the @<module>_HC_OPTS@
1711 @make@ variable in the appropriate @Makefile@;
1712 (2)~try again: \tr{gmake}.
1713 (Section~\ref{sect_suffix}.)
1714
1715 Alternatively, just cut to the chase scene:
1716 \begin{verbatim}
1717 % cd ghc/compiler
1718 % make EXTRA_HC_OPTS=-H32m  # or some nice big number
1719 \end{verbatim}
1720
1721 %------------------------------------------------------------------------
1722 \item
1723 Not too long into the build process, you may get a huge complaint
1724 of the form:
1725 \begin{verbatim}
1726 Giant error 'do'ing getopts.pl:  at ./lit2pgm.BOOT line 27.
1727 \end{verbatim}
1728 This indicates that your \tr{perl} was mis-installed; the binary is
1729 unable to find the files for its ``built-in'' library.  Speak to your
1730 perl installer, then re-try.
1731
1732 %------------------------------------------------------------------------
1733 \item
1734 If you try to compile some Haskell, and you get errors from GCC
1735 about lots of things from \tr{/usr/include/math.h}, then your GCC
1736 was mis-installed.  \tr{fixincludes} wasn't run when it should've
1737 been.
1738
1739 As \tr{fixincludes} is now automagically run as part of GCC
1740 installation, this bug also suggests that you have an old GCC.
1741
1742
1743 %------------------------------------------------------------------------
1744 \item
1745 You {\em may} need to re-\tr{ranlib} your libraries (on Sun4s).
1746 \begin{verbatim}
1747 % cd $(libdir)/ghc-x.xx/sparc-sun-sunos4
1748 % foreach i ( `find . -name '*.a' -print` ) # or other-shell equiv...
1749 ?    ranlib $i
1750 ?    # or, on some machines: ar s $i
1751 ? end
1752 \end{verbatim}
1753 We'd be interested to know if this is still necessary.
1754
1755 %------------------------------------------------------------------------
1756 \item
1757 If you end up making documents that involve (La)TeX and/or \tr{tib}
1758 (Simon's favourite), the odds are that something about your/our setup
1759 will reach out and bite you.  Yes, please complain; meanwhile,
1760 you can do \tr{make -n whatever.dvi} to see the intended commands,
1761 then try to muddle through, doing them by hand.
1762
1763 %------------------------------------------------------------------------
1764 \item
1765 GHC's sources go through \tr{cpp}
1766 before being compiled, and \tr{cpp} varies a bit from one Unix to another.
1767 One particular gotcha is macro calls like this:
1768 \begin{verbatim}
1769   SLIT("Hello, world")
1770 \end{verbatim}
1771 Some \tr{cpp}s treat the comma inside the string as separating two macro arguments,
1772 so you get
1773 \begin{verbatim}
1774   :731: macro `SLIT' used with too many (2) args
1775 \end{verbatim}
1776 Alas, \tr{cpp} doesn't tell you the offending file!
1777
1778 Workaround: don't put wierd things in string args to \tr{cpp} macros.
1779 \end{enumerate}
1780
1781 \begin{onlystandalone}
1782 \printindex
1783 \end{document}
1784 \end{onlystandalone}
1785