ef02fcd9bff4e8edded9fb9322d70d22f99801a1
[ghc-hetmet.git] / ghc / docs / users_guide / installing.sgml
1 <Chapter id="sec-installing-bin-distrib">
2 <Title>Installing from binary distributions</Title>
3 <IndexTerm><Primary>binary installations</Primary></IndexTerm>
4 <IndexTerm><Primary>installation, of binaries</Primary></IndexTerm>
5
6 <Para>
7 Installing from binary distributions is easiest, and recommended!
8 (Why binaries?  Because GHC is a Haskell compiler written in Haskell,
9 so you've got to ``bootstrap'' it, somehow.  We provide
10 machine-generated C-files-from-Haskell for this purpose, but it's
11 really quite a pain to use them.  If you must build GHC from its
12 sources, using a binary-distributed GHC to do so is a sensible way to
13 proceed. For the other <Literal>fptools</Literal> programs, many are written in Haskell,
14 so binary distributions allow you to install them without having a Haskell compiler.)
15 </Para>
16
17 <Para>This guide is in two parts: installing on Unix-a-likes, and installing on Windows.</Para>
18
19
20 <Sect1><Title>Installing on Unix-a-likes</Title>
21
22 <Sect2>
23 <Title>Bundle structure</Title>
24
25 <Para>
26 <IndexTerm><Primary>bundles of binary stuff</Primary></IndexTerm>
27 </Para>
28
29 <Para>
30 Binary distributions come in ``bundles,'' one bundle per file called
31 <Literal>&lt;bundle&gt;-&lt;platform&gt;.tar.gz</Literal>.  (See the building guide for the definition of a platform.)  Suppose that you untar a binary-distribution bundle, thus:
32 </Para>
33
34 <Para>
35
36 <Screen>
37 % cd /your/scratch/space
38 % gunzip &#60; ghc-x.xx-sun-sparc-solaris2.tar.gz | tar xvf -
39 </Screen>
40
41 </Para>
42
43 <Para>
44 Then you should find a single directory, <Literal>fptools</Literal>, with the following
45 structure:
46 </Para>
47
48 <Para>
49 <IndexTerm><Primary>binary distribution, layout</Primary></IndexTerm>
50 <IndexTerm><Primary>directory layout (binary distributions)</Primary></IndexTerm>
51 <VariableList>
52
53 <VarListEntry>
54 <Term><Literal>Makefile.in</Literal></Term>
55 <ListItem>
56 <Para>
57 the raw material from which the <Literal>Makefile</Literal>
58 will be made (<Xref LinkEnd="sec-install">).
59 </Para>
60 </ListItem></VarListEntry>
61 <VarListEntry>
62 <Term><Literal>configure</Literal></Term>
63 <ListItem>
64 <Para>
65 the configuration script (<Xref LinkEnd="sec-install">).
66 </Para>
67 </ListItem></VarListEntry>
68 <VarListEntry>
69 <Term><Literal>README</Literal></Term>
70 <ListItem>
71 <Para>
72 Contains this file summary.
73 </Para>
74 </ListItem></VarListEntry>
75 <VarListEntry>
76 <Term><Literal>INSTALL</Literal></Term>
77 <ListItem>
78 <Para>
79 Contains this description of how to install
80 the bundle.
81 </Para>
82 </ListItem></VarListEntry>
83 <VarListEntry>
84 <Term><Literal>ANNOUNCE</Literal></Term>
85 <ListItem>
86 <Para>
87 The announcement message for the bundle.
88 </Para>
89 </ListItem></VarListEntry>
90 <VarListEntry>
91 <Term><Literal>NEWS</Literal></Term>
92 <ListItem>
93 <Para>
94 release notes for the bundle&mdash;a longer version
95 of <Literal>ANNOUNCE</Literal>.  For GHC, the release notes are contained in the User
96 Guide and this file isn't present.
97 </Para>
98 </ListItem></VarListEntry>
99 <VarListEntry>
100 <Term><Literal>bin/&lt;platform&gt;</Literal></Term>
101 <ListItem>
102 <Para>
103 contains platform-specific executable
104 files to be invoked directly by the user.  These are the files that
105 must end up in your path.
106 </Para>
107 </ListItem></VarListEntry>
108 <VarListEntry>
109 <Term><Literal>lib/&lt;platform&gt;/</Literal></Term>
110 <ListItem>
111 <Para>
112 contains platform-specific support
113 files for the installation.  Typically there is a subdirectory for
114 each <Literal>fptools</Literal> project, whose name is the name of the project with its
115 version number.  For example, for GHC there would be a sub-directory
116 <Literal>ghc-x.xx</Literal>/ where <Literal>x.xx</Literal> is the version number of GHC in the bundle.
117 </Para>
118
119 <Para>
120 These sub-directories have the following general structure:
121 </Para>
122
123 <Para>
124 <VariableList>
125
126 <VarListEntry>
127 <Term><Literal>libHS.a</Literal> etc:</Term>
128 <ListItem>
129 <Para>
130 supporting library archives.
131 </Para>
132 </ListItem></VarListEntry>
133 <VarListEntry>
134 <Term><Literal>ghc-iface.prl</Literal> etc:</Term>
135 <ListItem>
136 <Para>
137 support scripts.
138 </Para>
139 </ListItem></VarListEntry>
140 <VarListEntry>
141 <Term><Literal>import/</Literal></Term>
142 <ListItem>
143 <Para>
144 <IndexTerm><Primary>Interface files</Primary></IndexTerm> (<Literal>.hi</Literal>) for the prelude.
145 </Para>
146 </ListItem></VarListEntry>
147 <VarListEntry>
148 <Term><Literal>include/</Literal></Term>
149 <ListItem>
150 <Para>
151 A few C <Literal>&num;include</Literal> files.
152 </Para>
153 </ListItem></VarListEntry>
154 </VariableList>
155 </Para>
156 </ListItem></VarListEntry>
157 <VarListEntry>
158 <Term><Literal>share/</Literal></Term>
159 <ListItem>
160 <Para>
161 contains platform-independent support files
162 for the installation.  Again, there is a sub-directory for each
163 <Literal>fptools</Literal> project.
164 </Para>
165 </ListItem></VarListEntry>
166 <VarListEntry>
167 <Term><Literal>info/</Literal></Term>
168 <ListItem>
169 <Para>
170 contains Emacs info documentation files (one
171 sub-directory per project).
172 </Para>
173 </ListItem></VarListEntry>
174 <VarListEntry>
175 <Term><Literal>html/</Literal></Term>
176 <ListItem>
177 <Para>
178 contains HTML documentation files (one
179 sub-directory per project).
180 </Para>
181 </ListItem></VarListEntry>
182 <VarListEntry>
183 <Term><Literal>man/</Literal></Term>
184 <ListItem>
185 <Para>
186 contains Unix manual pages.
187 </Para>
188 </ListItem></VarListEntry>
189 </VariableList>
190 </Para>
191
192 <Para>
193 This structure is designed so that you can unpack multiple bundles
194 (including ones from different releases or platforms) into a single
195 <Literal>fptools</Literal> directory
196 <FOOTNOTE>
197
198 <Para>
199 this doesn't work at the
200 moment
201 </Para>
202
203 </FOOTNOTE>
204 :
205 </Para>
206
207 <Para>
208
209 <Screen>
210 % cd /your/scratch/space
211 % gunzip &#60; ghc-x.xx-sun-sparc-solaris2.tar.gz | tar xvf -
212 % gunzip &#60; happy-x.xx-sun-sparc-sunos4.tar.gz | tar xvf -
213 </Screen>
214
215 </Para>
216
217 <Para>
218 When you do multiple unpacks like this, the top level <Literal>Makefile</Literal>,
219 <Literal>README</Literal>, and <Literal>INSTALL</Literal> get overwritten each time.
220 That's fine&mdash;they should be the same.  Likewise, the
221 <Literal>ANNOUNCE-&lt;bundle&gt;</Literal> and <Literal>NEWS-&lt;bundle&gt;</Literal>
222 files will be duplicated across multiple platforms, so they will be
223 harmlessly overwritten when you do multiple unpacks.  Finally, the
224 <Literal>share/</Literal> stuff will get harmlessly overwritten when you do
225 multiple unpacks for one bundle on different platforms.
226 </Para>
227
228 <Sect3 id="sec-install">
229 <Title>Installing</Title>
230
231 <Para>
232 OK, so let's assume that you have unpacked your chosen bundles into a
233 scratch directory <Literal>fptools</Literal>. What next? Well, you will at least need
234 to run the <Literal>configure</Literal><IndexTerm><Primary>configure</Primary></IndexTerm> script by changing your
235 directory to <Literal>fptools</Literal> and typing <Literal>./configure</Literal>.  That should convert
236 <Literal>Makefile.in</Literal> to <Literal>Makefile</Literal>.
237 </Para>
238
239 <Para>
240 <IndexTerm><Primary>installing in-place</Primary></IndexTerm>
241 <IndexTerm><Primary>in-place installation</Primary></IndexTerm>
242 </Para>
243
244 <Para>
245 You can now either start using the tools <Emphasis>in-situ</Emphasis> without going
246 through any installation process, just type <Literal>make in-place</Literal> to set the
247 tools up for this. You'll also want to add the path which <Literal>make</Literal> will
248 now echo to your <Literal>PATH</Literal> environment variable. This option is useful if
249 you simply want to try out the package and/or you don't have the
250 necessary privileges (or inclination) to properly install the tools
251 locally. Note that if you do decide to install the package `properly'
252 at a later date, you have to go through the installation steps that
253 follows.
254 </Para>
255
256 <Para>
257 To install an <Literal>fptools</Literal> package, you'll have to do the following:
258 </Para>
259
260 <Para>
261
262 <OrderedList>
263 <ListItem>
264
265 <Para>
266  Edit the <Literal>Makefile</Literal> and check the settings of the following variables:
267
268 <IndexTerm><Primary>directories, installation</Primary></IndexTerm>
269 <IndexTerm><Primary>installation directories</Primary></IndexTerm>
270
271 <VariableList>
272
273 <VarListEntry>
274 <Term><Literal>platform</Literal></Term>
275 <ListItem>
276 <Para>
277 the platform you are going to install for.
278 </Para>
279 </ListItem></VarListEntry>
280 <VarListEntry>
281 <Term><Literal>bindir</Literal></Term>
282 <ListItem>
283 <Para>
284 the directory in which to install user-invokable
285 binaries.
286 </Para>
287 </ListItem></VarListEntry>
288 <VarListEntry>
289 <Term><Literal>libdir</Literal></Term>
290 <ListItem>
291 <Para>
292 the directory in which to install
293 platform-dependent support files.
294 </Para>
295 </ListItem></VarListEntry>
296 <VarListEntry>
297 <Term><Literal>datadir</Literal></Term>
298 <ListItem>
299 <Para>
300 the directory in which to install
301 platform-independent support files.
302 </Para>
303 </ListItem></VarListEntry>
304 <VarListEntry>
305 <Term><Literal>infodir</Literal></Term>
306 <ListItem>
307 <Para>
308 the directory in which to install Emacs info
309 files.
310 </Para>
311 </ListItem></VarListEntry>
312 <VarListEntry>
313 <Term><Literal>htmldir</Literal></Term>
314 <ListItem>
315 <Para>
316 the directory in which to install HTML
317 documentation.
318 </Para>
319 </ListItem></VarListEntry>
320 <VarListEntry>
321 <Term><Literal>dvidir</Literal></Term>
322 <ListItem>
323 <Para>
324 the directory in which to install DVI
325 documentation.
326 </Para>
327 </ListItem></VarListEntry>
328 </VariableList>
329
330 The values for these variables can be set through invocation of the
331 <Command>configure</Command><IndexTerm><Primary>configure</Primary></IndexTerm> script that comes with the distribution,
332 but doing an optical diff to see if the values match your expectations
333 is always a Good Idea.
334
335 <Emphasis>Instead of running <Command>configure</Command>, it is perfectly OK to copy
336 <Filename>Makefile.in</Filename> to <Filename>Makefile</Filename> and set all these variables
337 directly yourself.  But do it right!</Emphasis>
338
339 </Para>
340 </ListItem>
341 <ListItem>
342
343 <Para>
344 Run <Literal>make install</Literal>.  This <Emphasis> should</Emphasis> work with ordinary Unix
345 <Literal>make</Literal>&mdash;no need for fancy stuff like GNU <Literal>make</Literal>. 
346
347 </Para>
348 </ListItem>
349 <ListItem>
350
351 <Para>
352 <Literal>rehash</Literal> (t?csh or zsh users), so your shell will see the new
353 stuff in your bin directory.
354
355 </Para>
356 </ListItem>
357 <ListItem>
358
359 <Para>
360  Once done, test your ``installation'' as suggested in 
361 <XRef LinkEnd="sec-GHC-test">.  Be sure to use a <Literal>-v</Literal>
362 option, so you can see exactly what pathnames it's using.
363
364 If things don't work as expected, check the list of know pitfalls in
365 the building guide.
366 </Para>
367 </ListItem>
368
369 </OrderedList>
370
371 </Para>
372
373 <Para>
374 <IndexTerm><Primary>link, installed as ghc</Primary></IndexTerm>
375 When installing the user-invokable binaries, this installation
376 procedure will install GHC as <Literal>ghc-x.xx</Literal> where <Literal>x.xx</Literal> is the version
377 number of GHC.  It will also make a link (in the binary installation
378 directory) from <Literal>ghc</Literal> to <Literal>ghc-x.xx</Literal>.  If you install multiple versions
379 of GHC then the last one ``wins'', and ``<Literal>ghc</Literal>'' will invoke the last
380 one installed.  You can change this manually if you want.  But
381 regardless, <Literal>ghc-x.xx</Literal> should always invoke GHC version <Literal>x.xx</Literal>.
382 </Para>
383
384 </Sect3>
385
386
387 <Sect3>
388 <Title>What bundles there are</Title>
389
390 <Para>
391 <IndexTerm><Primary>bundles, binary</Primary></IndexTerm>
392 There are plenty of ``non-basic'' GHC bundles.  The files for them are
393 called <Literal>ghc-x.xx-&lt;bundle&gt;-&lt;platform&gt;.tar.gz</Literal>, where
394 the <Literal>&lt;platform&gt;</Literal> is as above, and <Literal>&lt;bundle&gt;</Literal> is one
395 of these:
396 </Para>
397
398 <Para>
399 <VariableList>
400
401 <VarListEntry>
402 <Term><Literal>prof</Literal>:</Term>
403 <ListItem>
404 <Para>
405 Profiling with cost-centres.  You probably want this.
406 <IndexTerm><Primary>profiling bundles</Primary></IndexTerm>
407 <IndexTerm><Primary>bundles, profiling</Primary></IndexTerm>
408 </Para>
409 </ListItem></VarListEntry>
410 <VarListEntry>
411 <Term><Literal>par</Literal>:</Term>
412 <ListItem>
413 <Para>
414 Parallel Haskell features (sits on top of PVM).
415 You'll want this if you're into that kind of thing.
416 <IndexTerm><Primary>parallel bundles</Primary></IndexTerm>
417 <IndexTerm><Primary>bundles, parallel</Primary></IndexTerm>
418 </Para>
419 </ListItem></VarListEntry>
420 <VarListEntry>
421 <Term><Literal>gran</Literal>:</Term>
422 <ListItem>
423 <Para>
424 The ``GranSim'' parallel-Haskell simulator
425 (hmm&hellip; mainly for implementors).
426 <IndexTerm><Primary>bundles, gransim</Primary></IndexTerm>
427 <IndexTerm><Primary>gransim bundles</Primary></IndexTerm>
428 </Para>
429 </ListItem></VarListEntry>
430 <VarListEntry>
431 <Term><Literal>ticky</Literal>:</Term>
432 <ListItem>
433 <Para>
434 ``Ticky-ticky'' profiling; very detailed
435 information about ``what happened when I ran this program''&mdash;really
436 for implementors.
437 <IndexTerm><Primary>bundles, ticky-ticky</Primary></IndexTerm>
438 <IndexTerm><Primary>ticky-ticky bundles</Primary></IndexTerm>
439 </Para>
440 </ListItem></VarListEntry>
441 </VariableList>
442 </Para>
443
444 <Para>
445 One likely scenario is that you will grab <Emphasis>two</Emphasis>
446 binary bundles&mdash;basic, and profiling.  We don't usually make the
447 rest, although you can build them yourself from a source distribution.
448 </Para>
449
450 </Sect3>
451
452 <Sect3 id="sec-GHC-test">
453 <Title>Testing that GHC seems to be working
454 </Title>
455
456 <Para>
457 <IndexTerm><Primary>testing a new GHC</Primary></IndexTerm>
458 </Para>
459
460 <Para>
461 The way to do this is, of course, to compile and run <Emphasis>this</Emphasis> program
462 (in a file <Literal>Main.hs</Literal>):
463 </Para>
464
465 <Para>
466
467 <ProgramListing>
468 main = putStr "Hello, world!\n"
469 </ProgramListing>
470
471 </Para>
472
473 <Para>
474 Compile the program, using the <Literal>-v</Literal> (verbose) flag to verify that
475 libraries, etc., are being found properly:
476
477 <Screen>
478 % ghc -v -o hello Main.hs
479 </Screen>
480
481 </Para>
482
483 <Para>
484 Now run it:
485
486 <Screen>
487 % ./hello
488 Hello, world!
489 </Screen>
490
491 </Para>
492
493 <Para>
494 Some simple-but-profitable tests are to compile and run the notorious
495 <Literal>nfib</Literal><IndexTerm><Primary>nfib</Primary></IndexTerm> program, using different numeric types.  Start with
496 <Literal>nfib :: Int -&gt; Int</Literal>, and then try <Literal>Integer</Literal>, <Literal>Float</Literal>, <Literal>Double</Literal>,
497 <Literal>Rational</Literal> and perhaps the overloaded version.  Code for this is
498 distributed in <Literal>ghc/misc/examples/nfib/</Literal> in a source distribution.
499 </Para>
500
501 <Para>
502 For more information on how to ``drive'' GHC, either do <Literal>ghc -help</Literal> or
503 consult the User's Guide (distributed in several pre-compiled formats
504 with a binary distribution, or in source form in
505 <Literal>ghc/docs/users&lowbar;guide</Literal> in a source distribution).
506 </Para>
507
508 </Sect3>
509
510 </Sect2>
511
512 </Sect1>
513
514
515 <Sect1><Title>Installing on Windows</Title>
516
517 <Para>
518 Getting the Glasgow Haskell Compiler(GHC) to run on Windows95/98 or
519 Windows NT4 platforms can be a bit of a trying experience. This document
520 tries to simplify the task by enumerating the steps you need to
521 follow in order to set up and configure your machine to run GHC (at
522 least that's the intention ;-)
523 </Para>
524
525 <Sect2><Title>System requirements</Title>
526
527 <Para>
528 An installation of GHC requires ca. 70M of disk space. The size of the
529 installed GHC distribution is just(!) 17M, the rest is needed by
530 supporting software.
531 </Para>
532
533 <Para>
534 To run GHC comfortably, your machine should have at least 32M of memory.
535 </Para>
536
537 </Sect2>
538
539
540 <Sect2><Title>Your environment variables</Title>
541
542 <Para>
543 Much of the Unixy stuff below involves setting environment variables.  For example, on WinNT/Win2k, to edit your <Constant>PATH</Constant> variable,
544 do the following:
545 </Para>
546
547 <ItemizedList>
548 <ListItem><Para>Press Start/Settings/Control Panels</Para></ListItem>
549 <ListItem><Para>Double-click System</Para></ListItem>
550 <ListItem><Para>Press Advanced</Para></ListItem>
551 <ListItem><Para>Press Environment Variables</Para></ListItem>
552 <ListItem><Para>Under System Variables, select PATH</Para></ListItem>
553 <ListItem><Para>Press Edit</Para></ListItem>
554 <ListItem><Para>Add "<Filename>;C:/whatever/</Filename>" to the end of the string (for example)</Para></ListItem>
555 <ListItem><Para>Press OK</Para></ListItem>
556 </ItemizedList>
557
558 <Para>
559 Some environment variables are ``user variables'' and
560 some are ``system variables''.  I'm not sure of the difference
561 but both are changed though the same dialogue.
562 </Para>
563
564 <Para>
565 In addition, when running a Cygwin (see <XRef LinkEnd="sec-required">) shell
566 you can set environment variables in your <Filename>.bashrc</Filename> file.
567 But it is better to set your environment variables from the
568 control panel (they get inherited by bash) because then they are visible
569 to applications that aren't started by bash.  For example,
570 when you're invoking CVS (and ssh) via Emacs keybindings;
571 it invokes <Filename>cvs.exe</Filename> without going via bash.
572 </Para>
573
574 <Para>
575 On a Win9x machine you need to edit <Filename>autoexec.bat</Filename> using
576 <Filename>Windows/system/Sysedit</Filename>.  You need to reboot to make
577 the new settings take effect.
578 </Para>
579
580 </Sect2>
581
582
583 <Sect2 id="sec-required"><Title>Software required</Title>
584
585 <VariableList>
586 <VarListEntry>
587 <Term>The cygwin toolchain (beta20.1)</Term>
588 <ListItem>
589 <Para>
590 GHC depends at the moment on the cygwin tools to operate, which
591 dresses up the Win32 environment into something more UNIX-like.
592 (notably, it provides <Command>gcc</Command>, <Command>as</Command> and <Command>ld</Command>),
593 so you'll need to install these tools first. You also need
594 Cygwin to use CVS.
595 </Para>
596
597 <Para>
598 Important grungy information about Cygwin:
599 </Para>
600
601 <ItemizedList>
602
603 <ListItem>
604 <Para>
605 Cygwin doesn't deal well with filenames that include
606 spaces. "<Filename>Program Files</Filename>" and "<Filename>Local files</Filename>" are
607 common gotchas.
608 </Para>
609 </ListItem>
610
611 <ListItem>
612 <Para>
613 Cygwin implements a symbolic link as a text file with some
614 magical text in it.  So programs that don't use Cygwin's
615 I/O libraries won't recognise such files as symlinks.  
616 In particular, programs compiled by GHC are meant to be runnable
617 without having Cygwin, so they don't use the Cygwin library, so
618 they don't recognise symlinks.
619 </Para>
620 </ListItem>
621
622 </ItemizedList>
623
624 <Para>
625 Here's how to install Cygwin.
626 </Para>
627
628 <ItemizedList>
629
630 <ListItem>
631 <Para>
632 Download cygwin, beta20.1 (<filename>full.exe</filename>) from
633 <ULink URL="http://sourceware.cygnus.com/cygwin/">sourceware.cygnus.com</ULink>
634 Install this somewhere locally.
635 </Para>
636 </ListItem>
637
638 <ListItem>
639 <Para>
640 Create the following directories (if they aren't already there):
641 </Para>
642
643 <ItemizedList>
644 <ListItem><Para><Filename>c:/etc</Filename></Para></ListItem>
645 <ListItem><Para><Filename>c:/bin</Filename></Para></ListItem>
646 <ListItem><Para><Filename>c:/usr/local/bin</Filename></Para></ListItem>
647 </ItemizedList>
648
649 <Para>
650 (using <Command>mkdir -p /bin</Command>, etc.)
651 </Para>
652 </ListItem>
653
654 <ListItem>
655 <Para>
656 Add the two <Filename>bin</Filename> directories to your <Constant>PATH</Constant>.
657 </Para>
658 </ListItem>
659
660 <ListItem>
661 <Para>
662 Copy <Filename>bash.exe</Filename> from the <Filename>bin</Filename> directory of the cygwin tree (<Filename>cygwin-b20/H-i586-cygwin32/bin/bash.exe</Filename>) to
663 <Filename>/bin</Filename> as <Filename>sh.exe</Filename>.  This is where Emacs looks for a shell (I think).
664 </Para>
665 </ListItem>
666
667 <ListItem>
668 <Para>
669 You might think that it was easier to use bash directly from it original
670 Cygwin directory, but (a) some UNIX utils have got <FIlename>/bin/sh</FIlename> hardwired in, and (b) the path following <Literal>#!</Literal> is limited to 32 characters.
671 </Para>
672 </ListItem>
673
674 <ListItem>
675 <Para>
676 Add <Filename>C:\cygnus\cygwin-b20\H-i586-cygwin32\bin</Filename> to your <Constant>PATH</Constant>.
677 <Command>bash</Command> needs this, and when it is invoked from <Filename>/bin</Filename> it can't
678 find it.
679 </Para>
680 </ListItem>
681
682 <ListItem>
683 <Para>
684 Set your <Constant>SHELL</Constant> user environment variable to <Filename>c:/bin/sh</Filename>.
685 </Para>
686 </ListItem>
687
688 <ListItem>
689 <Para>
690 Set your <Filename>HOME</Filename> user environment variable to point to your
691 home directory.  This is where, for example,
692 <Command>bash</Command> will look for your <Filename>.bashrc</Filename>
693 file.
694 </Para>
695 </ListItem>
696
697 <ListItem>
698 <Para>
699 Set your <Constant>MAKE_MODE</Constant> user environment variable to <Literal>UNIX</Literal>.  If you don't do
700 this you get very weird messages when you type `<Command>make</Command>', such as:
701 </Para>
702
703 <Screen>
704 /c: /c: No such file or directory
705 </Screen>
706 </ListItem>
707
708 <ListItem>
709 <Para>
710 Set the <Constant>TMPDIR</Constant> user environment variable to <Filename>/tmp</Filename>. For some reason, Win2k invisibly sets this variable to point to a temporary directory in your profile, that contains embedded spaces.  If GHC sees the <Constant>TMPDIR</Constant> variable set, it tries to use it for temporary files, but
711 Cygwin doesn't grok filenames with spaces, so disaster results.
712 </Para>
713 </ListItem>
714
715 <ListItem>
716 <Para>
717 If you're an Emacs user and want to be able to run <Command>bash</Command>
718 from within a shell buffer, see the <ULink URL="http://www.cs.washington.edu/homes/voelker/ntemacs.html">NT Emacs home page</ULink> for
719 instructions on how to set this up.
720 </Para>
721 </ListItem>
722
723 </ItemizedList>
724
725 </ListItem>
726 </VarListEntry>
727
728 <VarListEntry>
729 <Term>Perl5</Term>
730 <ListItem><Para>
731 The driver script is written in Perl, so you'll need to have this
732 installed too. However, the ghc binary distribution includes a
733 perl binary for you to make use of, should you not already have a
734 cygwin compatible one. Note: GHC does <Emphasis>not</Emphasis>
735 work with the ActiveState port of perl.
736 </Para>
737 </ListItem>
738 </VarListEntry>
739
740 </VariableList>
741
742 </Sect2>
743
744
745 <Sect2><Title>Installing the supporting software</Title>
746
747 <ItemizedList>
748 <ListItem>
749 <Para>
750 Download <ULink URL="http://sourceware.cygnus.com/cygwin/">cygwin beta20.1</ULink> (<Filename>full.exe</Filename>). Install this somewhere locally.
751 </Para>
752 </ListItem>
753
754 <ListItem>
755 <Para>
756 After having successfully installed this, make sure you do the following:
757 </Para>
758
759 <ItemizedList>
760 <ListItem>
761 <Para>
762 Create a <Filename>/bin</Filename> directory (using <Command>mkdir -p /bin</Command>).
763 </Para>
764 </ListItem>
765
766 <ListItem>
767 <Para>
768 Copy <Filename>bash.exe</Filename> from the <Filename>bin</Filename> directory of the cygwin tree (<Filename>cygwin-b20/H-i586-cygwin32/bin/bash.exe</Filename>) to
769 <Filename>/bin</Filename> as <Filename>sh.exe</Filename>.
770 </Para>
771 </ListItem>
772
773 <ListItem>
774 <Para>
775 If you haven't already got one, create a <Filename>/tmp</Filename> directory.
776 </Para>
777 </ListItem>
778
779 <ListItem>
780 <Para>
781 If you're an Emacs user and want to be able to run <Command>bash</Command>
782 from within a shell buffer, see the <ULink URL="http://www.cs.washington.edu/homes/voelker/ntemacs.html">NT Emacs home page</ULink> for
783 instructions on how to set this up.
784 </Para>
785 </ListItem>
786
787 </ItemizedList>
788
789 </ListItem>
790
791 </ItemizedList>
792
793 <Para>
794 With the supporting software in place, we can finally get on to installing GHC itself.
795 </Para>
796
797 </Sect2>
798
799
800 <Sect2><Title>Installing GHC</Title>
801
802 <Para>
803 Download a GHC distribution:
804 </Para>
805
806 <VariableList>
807
808 <VarListEntry>
809 <Term>ghc-4.045&mdash;InstallShield installer, 10M: <ULink URL="http://www.dcs.gla.ac.uk/~sof/ghc-4.045-win32-IS.zip">http</ULink> or <ULink URL="ftp://ftp.dcs.gla.ac.uk/pub/haskell/glasgow/4.04/ghc-4.045-win32-IS.zip">ftp</ULink>
810 </Term>
811
812 <ListItem>
813 <Para>
814 (The version number may change.) It is packaged up using an installer that should be familiar-looking to Windows users. Unpack and double click on <Filename>setup.exe</Filename>.
815 </Para>
816
817 <Para>
818 Note: The cygwin support for long file names containing
819 spaces is not 100%, so make sure that you install ghc in a directory
820 that has no embedded spaces (i.e., resist the temptation to put it
821 in <Filename>/Program Files/</Filename>!)
822 </Para>
823
824 <Para>
825 When the installer has completed its job, you may delete the
826 <Filename>ghcInstall</Filename> directory.
827 </Para>
828
829 <Para>
830 When the installer has completed, make sure you add the location of the
831 ghc <Filename>bin/</Filename> directory to your path (i.e. <Filename>/path/to/wherever/ghc-4.05/bin </Filename>).
832 You need to do this in order to bring the various GHC DLLs into scope;
833 if not, then you need to copy the DLLs into a directory that is (the
834 system directory, for example).
835 </Para>
836
837 <Para>
838 Note: In case you haven't got perl already installed,
839 you will have to manually copy the <Filename>perl.exe</Filename> binary from the
840 ghc <Filename>bin/</Filename> into your <Filename>/bin</Filename> directory before continuing&mdash;the installer will not currently do this.
841 </Para>
842 </ListItem>
843
844 </VarListEntry>
845
846 <VarListEntry>
847 <Term>
848 ghc-4.045 - gzip'ed tarfile, 7.5M: <ULink URL="http://www.dcs.gla.ac.uk/~sof/ghc-4.045-win32.tar.gz">
849 http</ULink> or <ULink URL="ftp://ftp.dcs.gla.ac.uk/pub/haskell/glasgow/4.04/ghc-4.045-win32.tar.gz">ftp</ULink>
850 </Term>
851
852 <ListItem>
853 <Para>
854 A `normal' GHC binary distribution packaged up as a compressed tar file.
855 If you're already accustomed to installing and using GHC distributions
856 on other platforms, the setup should be familiar to you, I
857 hope. Unpack and read the INSTALL file contained in the
858 distribution for instructions on how to set it up.
859 </Para>
860
861 <Para>
862 Notice that the top directory of the distribution contains
863 (rather clumsily) a perl binary (version 5.005_02). If you
864 haven't already got a working perl, install this somewhere
865 along your path too.
866 </Para>
867 </ListItem>
868
869 </VarListEntry>
870 </VariableList>
871
872 <Para>
873 To test the fruits of your labour, try now to compile a simple
874 Haskell program:
875 </Para>
876
877 <Screen>
878 bash$ cat main.hs
879 module Main(main) where
880
881 main = putStrLn "Hello, world!"
882 bash$ /path/to/the/ghc/bin/directory/ghc-4.05 -o main main.hs
883 ..
884 bash$ ./main
885 Hello, world!
886 bash$ 
887 </Screen>
888
889 <Para>
890 OK, assuming that worked, you're all set. Go forth and write useful
891 Haskell programs :-) If not, consult the installation FAQ (<XRef LinkEnd="winfaq">); if that still doesn't help then please report the problems you're experiencing (see <Xref LinkEnd="wrong">).
892 </Para>
893
894 <Para>
895 Further information on using GHC under Windows can be found in <ULink URL="http://www.dcs.gla.ac.uk/~sof/ghc-win32.html">Sigbj&oslash;rn Finne's pages</ULink>.
896 </Para>
897
898 </Sect2>
899
900 </Sect1>
901
902
903 <Sect1 id="winfaq"><title>Installing ghc-win32 FAQ</title>
904
905 <QandASet>
906
907 <QandAEntry>
908
909 <Question>
910 <Para>
911 Invoking ghc doesn't seem to do anything, it immediately returns without having compiled the input file.
912 </Para>
913 </Question>
914
915 <Answer>
916 <Para>
917 One cause of this is that <Filename>/bin/sh</Filename> is missing. To verify, open up a
918 bash session and type <Command>ls -l /bin/sh.exe</Command>. If <Filename>sh.exe</Filename> is 
919 reported as not being there, copy <Filename>bash.exe</Filename> (which you'll find
920 inside the cygwin installation tree as <Filename>H-i586-cygwin32/bin/bash.exe</Filename>)
921 to <Filename>/bin/sh.exe</Filename>.
922 </Para>
923
924 <Para>
925 All being well, ghc should then start to function.
926 </Para>
927 </Answer>
928
929 </QandAEntry>
930
931 <QandAEntry>
932
933 <Question>
934 <Para>
935 When compiling up the <Literal>Hello World</Literal> example, the following happens:
936 </Para>
937
938 <Screen>
939 bash$ /ghc/ghc-4.05/bin/ghc-4.05 main.hs
940 &lt;stdin&gt;:0:25: Character literal '{-# LINE 1 "main.hs" -}' too long
941 &lt;stdin&gt;:0:25:  on input: "'"
942 bash$ 
943 </Screen>
944
945 <Para>
946 or
947 </Para>
948
949 <Screen>
950 bash$ /ghc/ghc-4.05/bin/ghc-4.05 main.hs
951 Program too big fit into memory under NT
952 bash$ 
953 </Screen>
954 </Question>
955
956 <Answer>
957 <Para>
958 The cause of this is that you're using a version of <Command>perl</Command> that employs the Microsoft <Command>cmd</Command>/<Command>command</Command> shell when launching sub-processes to execute <Function>system()</Function> calls.
959 </Para>
960
961 <Para>
962 The GHC driver really needs a <Command>perl</Command> which uses a `UNIX'y  shell instead, so
963 make sure that the version you're using is of an compatible ilk. In particular, 
964 if <Command>perl -v</Command> reports that you've got a copy of the (otherwise fine) port
965 of perl done by ActiveState, you're in trouble.
966 </Para>
967
968 <Para>
969 If you're stuck with an incompatible <Command>perl</Command>, the GHC installation comes with a very basic <Command>perl</Command> binary for you to use. Simply copy it into the <Command>/bin</Command> directory.
970 </Para>
971
972 <Para>
973 Notice that copying <Filename>perl.exe</Filename> into <Filename>/bin</Filename> will not cause
974 the GHC install to suddenly start functioning. If you don't want to
975 re-run the InstallShield installer again, you need to edit the following
976 files within the directory tree that the installer created:
977 </Para>
978
979 <Screen>
980 bin/ghc-4.xx   -- where xx is the minor release number
981 bin/stat2resid
982 bin/hstags
983 lib/mkdependHS
984 </Screen>
985
986 <Para>
987 For each of these files, you need to edit the first line from instead
988 saying <Command>#!/path/to/your/other/perl/install</Command> to <Command>#!/bin/perl</Command>.
989 Once that is done, try compiling up the Hello, World example again.
990 </Para>
991
992 <Para>
993 Should you want to pick up a complete installation of a ghc-friendly port
994 of perl instead, a <ULink URL="http://cygutils.netpedia.net/">cygwin port</ULink> is available.
995 </Para>
996 </Answer>
997
998 </QandAEntry>
999
1000 <QAndAEntry>
1001
1002 <Question>
1003 <Para>
1004 <Function>System.getArgs</Function> always return the empty list, i.e. the following program always prints <Screen>"[]"</Screen>:
1005 </Para>
1006
1007 <ProgramListing>
1008 module Main(main) where
1009 import qualified System
1010 main = System.getArgs >>= print
1011 </ProgramListing>
1012
1013 </Question>
1014
1015 <Answer>
1016 <Para>
1017 This is a bug with the RTS DLL that comes with ghc-4.03. To fix, upgrade to
1018 ghc-4.05.
1019 </Para>
1020 </Answer>
1021
1022 </QAndAEntry>
1023
1024 </QandASet>
1025
1026 </Sect1>
1027
1028 </Chapter>