doc tweak
[ghc-hetmet.git] / docs / users_guide / installing.xml
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <chapter id="installing-bin-distrib">
3   <title>Installing GHC</title>
4 <indexterm><primary>binary installations</primary></indexterm>
5 <indexterm><primary>installation, of binaries</primary></indexterm>
6
7 <para>
8 Installing from binary distributions is easiest, and recommended!
9 (Why binaries? Because GHC is a Haskell compiler written in Haskell,
10 so you've got to bootstrap it somehow.  We provide machine-generated
11 C-files-from-Haskell for this purpose, but it's really quite a pain to
12 use them.  If you must build GHC from its sources, using a
13 binary-distributed GHC to do so is a sensible way to proceed.)
14 </para>
15
16 <para>This guide is in several parts:</para>
17
18   <itemizedlist>
19     <listitem>
20       <para> Installing on Unix-a-likes (<xref
21       linkend="unix-a-likes"/>). </para>
22     </listitem>
23     <listitem>
24       <para> Installing on Windows (<xref
25       linkend="install-windows"/>).  </para>
26     </listitem>
27     <listitem>
28       <para> The layout of installed files (<xref
29       linkend="install-files"/>).  You don't need to know this to
30       install GHC, but it's useful if you are changing the
31       implementation.</para>
32     </listitem>
33   </itemizedlist>
34   
35   <sect1 id="unix-a-likes"><title>Installing on Unix-a-likes</title>
36
37     <sect2>
38       <title>When a platform-specific package is available</title>
39       
40       <para>Most common OSes provide GHC binaries packaged
41       using the native package format for the platform.  This is
42       likely to be by far the best way to install GHC for your
43       platform if one of these packages is available, since
44       dependencies will automatically be handled and the package
45       system normally provides a way to uninstall the package at a
46       later date.</para>
47
48       <para>Check the <ulink url="http://www.haskell.org/ghc/distribution_packages.html">distribution packages</ulink> page to see if there is a package available for your platform.</para>
49     </sect2>
50
51 <sect2>
52 <title>GHC binary distributions</title>
53
54 <para>
55 <indexterm><primary>bundles of binary stuff</primary></indexterm>
56 </para>
57
58 <para>
59 Binary distributions come in &ldquo;bundles,&rdquo; called
60 <literal>ghc-<replaceable>version</replaceable>-<replaceable>platform</replaceable>.tar.bz2</literal>. (See the <ulink url="http://hackage.haskell.org/trac/ghc/wiki/Building">building guide</ulink> for the definition of a platform.)  Suppose that you untar a binary-distribution bundle, thus:
61 </para>
62
63 <para>
64 <screen>
65 % cd /your/scratch/space
66 % bunnzip2 &#60; ghc-<replaceable>version</replaceable>-<replaceable>platform</replaceable>.tar.bz2 | tar xvf -</screen>
67 </para>
68
69 <para>
70 Then you should find the bundle contents inside a single directory,
71 <literal>ghc-<replaceable>version</replaceable></literal>.
72 </para>
73
74 <sect3 id="install">
75 <title>Installing</title>
76
77 <para>
78 OK, so let's assume that you have unpacked your chosen bundles. What
79 next? Well, you will at least need to run the
80 <literal>configure</literal><indexterm><primary>configure</primary></indexterm>
81 script by changing directory into the top-level directory for the
82 bundle and typing <literal>./configure</literal>.  That should convert
83 <literal>Makefile-vars.in</literal> to <literal>Makefile-vars</literal>.
84 </para>
85
86 <para>
87 <indexterm><primary>installing in-place</primary></indexterm>
88 <indexterm><primary>in-place installation</primary></indexterm>
89 You can now either start using the tools <emphasis>in-situ</emphasis> without going
90 through any installation process, just type <literal>make in-place</literal> to set the
91 tools up for this. You'll also want to add the path which <literal>make</literal> will
92 now echo to your <literal>PATH</literal> environment variable. This option is useful if
93 you simply want to try out the package and/or you don't have the
94 necessary privileges (or inclination) to properly install the tools
95 locally. Note that if you do decide to install the package `properly'
96 at a later date, you have to go through the installation steps that
97 follow.
98 </para>
99
100 <para>
101 To install a package, you'll have to do the following:
102 </para>
103
104 <para>
105
106 <orderedlist>
107 <listitem>
108
109 <para>
110  Edit the <literal>Makefile</literal> and check the settings of the following variables:
111
112 <indexterm><primary>directories, installation</primary></indexterm>
113 <indexterm><primary>installation directories</primary></indexterm>
114
115 <variablelist>
116
117 <varlistentry>
118 <term><literal>platform</literal></term>
119 <listitem>
120 <para>
121 the platform you are going to install for.
122 </para>
123 </listitem></varlistentry>
124 <varlistentry>
125 <term><literal>bindir</literal></term>
126 <listitem>
127 <para>
128 the directory in which to install user-invokable
129 binaries.
130 </para>
131 </listitem></varlistentry>
132 <varlistentry>
133 <term><literal>libdir</literal></term>
134 <listitem>
135 <para>
136 the directory in which to install
137 platform-dependent support files.
138 </para>
139 </listitem></varlistentry>
140 <varlistentry>
141 <term><literal>datadir</literal></term>
142 <listitem>
143 <para>
144 the directory in which to install
145 platform-independent support files.
146 </para>
147 </listitem></varlistentry>
148 <varlistentry>
149 <term><literal>infodir</literal></term>
150 <listitem>
151 <para>
152 the directory in which to install Emacs info
153 files.
154 </para>
155 </listitem></varlistentry>
156 <varlistentry>
157 <term><literal>htmldir</literal></term>
158 <listitem>
159 <para>
160 the directory in which to install HTML
161 documentation.
162 </para>
163 </listitem></varlistentry>
164 <varlistentry>
165 <term><literal>dvidir</literal></term>
166 <listitem>
167 <para>
168 the directory in which to install DVI
169 documentation.
170 </para>
171 </listitem></varlistentry>
172 </variablelist>
173
174 The values for these variables can be set through invocation of the
175 <command>configure</command><indexterm><primary>configure</primary></indexterm>
176 script that comes with the distribution, but doing an optical diff to
177 see if the values match your expectations is always a Good Idea.
178 </para>
179
180 <para>
181 <emphasis>Instead of running <command>configure</command>, it is
182 perfectly OK to copy <filename>Makefile.in</filename> to
183 <filename>Makefile</filename> and set all these variables directly
184 yourself.  But do it right!</emphasis>
185 </para>
186
187 </listitem>
188 <listitem>
189
190 <para>
191 Run <literal>make install</literal>.  This <emphasis>
192 should</emphasis> work with ordinary Unix
193 <literal>make</literal>&mdash;no need for fancy stuff like GNU
194 <literal>make</literal>.
195
196 </para>
197 </listitem>
198 <listitem>
199
200 <para>
201 <literal>rehash</literal> (t?csh or zsh users), so your shell will see the new
202 stuff in your bin directory.
203
204 </para>
205 </listitem>
206 <listitem>
207
208 <para>
209  Once done, test your &ldquo;installation&rdquo; as suggested in 
210 <xref linkend="GHC-test"/>.  Be sure to use a <literal>-v</literal>
211 option, so you can see exactly what pathnames it's using.
212
213 If things don't work as expected, check the list of known pitfalls in
214 the <ulink url="http://hackage.haskell.org/trac/ghc/wiki/Building">building guide</ulink>.
215 </para>
216 </listitem>
217
218 </orderedlist>
219
220 </para>
221
222 <para>
223 <indexterm><primary>link, installed as ghc</primary></indexterm>
224 When installing the user-invokable binaries, this installation
225 procedure will install GHC as <literal>ghc-x.xx</literal> where <literal>x.xx</literal> is the version
226 number of GHC.  It will also make a link (in the binary installation
227 directory) from <literal>ghc</literal> to <literal>ghc-x.xx</literal>.  If you install multiple versions
228 of GHC then the last one &ldquo;wins&rdquo;, and &ldquo;<literal>ghc</literal>&rdquo; will invoke the last
229 one installed.  You can change this manually if you want.  But
230 regardless, <literal>ghc-x.xx</literal> should always invoke GHC version <literal>x.xx</literal>.
231 </para>
232
233 </sect3>
234
235
236 <sect3>
237 <title>What bundles there are</title>
238
239 <para>
240 <indexterm><primary>bundles, binary</primary></indexterm> There are
241 plenty of &ldquo;non-basic&rdquo; GHC bundles.  The files for them are
242 called
243 <literal>ghc-x.xx-<replaceable>bundle</replaceable>-<replaceable>platform</replaceable>.tar.gz</literal>,
244 where the <replaceable>platform</replaceable> is as above, and
245 <replaceable>bundle</replaceable> is one of these:
246 </para>
247
248 <para>
249 <variablelist>
250
251 <varlistentry>
252 <term><literal>prof</literal>:</term>
253 <listitem>
254 <para>
255 Profiling with cost-centres.  You probably want this.
256 <indexterm><primary>profiling bundles</primary></indexterm>
257 <indexterm><primary>bundles, profiling</primary></indexterm>
258 </para>
259 </listitem></varlistentry>
260 <varlistentry>
261 <term><literal>par</literal>:</term>
262 <listitem>
263 <para>
264 Parallel Haskell features (sits on top of PVM).
265 You'll want this if you're into that kind of thing.
266 <indexterm><primary>parallel bundles</primary></indexterm>
267 <indexterm><primary>bundles, parallel</primary></indexterm>
268 </para>
269 </listitem></varlistentry>
270 <varlistentry>
271 <term><literal>gran</literal>:</term>
272 <listitem>
273 <para>
274 The &ldquo;GranSim&rdquo; parallel-Haskell simulator
275 (hmm&hellip; mainly for implementors).
276 <indexterm><primary>bundles, gransim</primary></indexterm>
277 <indexterm><primary>gransim bundles</primary></indexterm>
278 </para>
279 </listitem></varlistentry>
280 <varlistentry>
281 <term><literal>ticky</literal>:</term>
282 <listitem>
283 <para>
284 &ldquo;Ticky-ticky&rdquo; profiling; very detailed
285 information about &ldquo;what happened when I ran this program&rdquo;&mdash;really
286 for implementors.
287 <indexterm><primary>bundles, ticky-ticky</primary></indexterm>
288 <indexterm><primary>ticky-ticky bundles</primary></indexterm>
289 </para>
290 </listitem></varlistentry>
291 </variablelist>
292 </para>
293
294 <para>
295 One likely scenario is that you will grab <emphasis>two</emphasis>
296 binary bundles&mdash;basic, and profiling.  We don't usually make the
297 rest, although you can build them yourself from a source distribution.
298 </para>
299
300 <para>The various GHC bundles are designed to be unpacked into the
301 same directory; then installing as per the directions above will
302 install the whole lot in one go.  Note: you <emphasis>must</emphasis>
303 at least have the basic GHC binary distribution bundle, these extra
304 bundles won't install on their own.</para>
305
306 </sect3>
307
308 <sect3 id="GHC-test">
309 <title>Testing that GHC seems to be working
310 </title>
311
312 <para>
313 <indexterm><primary>testing a new GHC</primary></indexterm>
314 </para>
315
316 <para>
317 The way to do this is, of course, to compile and run <emphasis>this</emphasis> program
318 (in a file <literal>Main.hs</literal>):
319 </para>
320
321 <para>
322
323 <programlisting>
324 main = putStr "Hello, world!\n"
325 </programlisting>
326
327 </para>
328
329 <para>
330 Compile the program, using the <literal>-v</literal> (verbose) flag to verify that
331 libraries, etc., are being found properly:
332
333 <screen>
334 % ghc -v -o hello Main.hs</screen>
335
336 </para>
337
338 <para>
339 Now run it:
340
341 <screen>
342 % ./hello
343 Hello, world!</screen>
344
345 </para>
346
347 <para>
348 Some simple-but-profitable tests are to compile and run the notorious
349 <literal>nfib</literal><indexterm><primary>nfib</primary></indexterm> program, using different numeric types.  Start with
350 <literal>nfib :: Int -&gt; Int</literal>, and then try <literal>Integer</literal>, <literal>Float</literal>, <literal>Double</literal>,
351 <literal>Rational</literal> and perhaps the overloaded version.  Code for this is
352 distributed in <literal>ghc/misc/examples/nfib/</literal> in a source distribution.
353 </para>
354
355 <para>For more information on how to &ldquo;drive&rdquo; GHC, read
356 on...</para>
357
358 </sect3>
359
360 </sect2>
361
362 </sect1>
363
364
365 <sect1 id="install-windows"><title>Installing on Windows</title>
366
367 <para>
368 Getting the Glasgow Haskell Compiler (post 5.02) to run on Windows platforms is
369 a snap: the installer does everything you need.  
370 </para>
371
372 <sect2><title>Installing GHC on Windows</title>
373
374 <para>
375 To install GHC, use the following steps:
376 </para>
377 <itemizedlist>
378 <listitem><para>Download the installer
379 from the
380 <ulink
381 url="http://www.haskell.org/ghc/download.html">GHC download page</ulink>.
382 </para></listitem>
383
384 <listitem><para>Run the installer.
385 On Windows, all of GHC's files are installed in a single directory.
386 You can override it, but by default this directory is
387 <filename>c:/ghc/<replaceable>ghc-version</replaceable></filename>.
388 The executable binary for GHC will be installed in the
389 <filename>bin/</filename> sub-directory of the installation directory.
390 If you want to invoke GHC from a command line, add this
391 to your PATH environment variable.
392 </para>
393 <para>
394 When installation is complete, you should find GHCi and the GHC
395 documentation are available in your Start menu under
396 "Start/All Programs/GHC/<replaceable>ghc-version</replaceable>".
397 </para>
398 </listitem>
399
400 <listitem><para>
401 GHC needs a directory in which to create, and later delete, temporary files.
402 It uses the standard Windows procedure <literal>GetTempPath()</literal> to
403 find a suitable directory.  This procedure returns:
404 <itemizedlist>
405 <listitem><para>The path in environment variable TMP, 
406 if TMP is set.</para></listitem>
407 <listitem><para>Otherwise, the path in environment variable TEMP, 
408 if TEMP is set.</para></listitem>
409 <listitem><para>Otherwise, there is a per-user default which varies
410 between versions of Windows. On NT and XP-ish versions, it might 
411 be:
412 <filename>c:\Documents and Settings\&lt;username&gt;\Local Settings\Temp</filename>
413 </para></listitem>
414 </itemizedlist>
415 The main point is that if you don't do anything GHC will work fine;
416 but if you want to control where the directory is, you can do so by
417 setting TMP or TEMP.
418 </para></listitem>
419
420 <listitem>
421 <para>
422 To test the fruits of your labour, try now to compile a simple
423 Haskell program:
424 </para>
425
426 <screen>
427 bash$ cat main.hs
428 module Main(main) where
429
430 main = putStrLn "Hello, world!"
431 bash$ ghc -o main main.hs
432 ..
433 bash$ ./main
434 Hello, world!
435 bash$</screen>
436 </listitem>
437 </itemizedlist>
438
439 <para>
440 You do <emphasis>not</emphasis> need the Cygwin toolchain, or anything
441 else, to install and run GHC.
442 </para>
443 <para>
444 An installation of GHC requires about 340M of disk space.
445 To run GHC comfortably, your machine should have at least
446 64M of memory.
447 </para>
448 </sect2>
449
450 <sect2><title>Moving GHC around</title>
451 <para>
452 Once GHC is installed, you can freely move the entire GHC tree just by copying
453 the <filename>c:/ghc/<replaceable>ghc-version</replaceable></filename>
454 directory. (You will need to fix up 
455 the links in "Start/All Programs/GHC/<replaceable>ghc-version</replaceable>"
456 if you do this.)
457 </para>
458 <para>
459 It is OK to put GHC tree in a directory whose path involves spaces.  However,
460 don't do this if you use want to use GHC with the Cygwin tools, 
461 because Cygwin can get confused when this happens.
462 We havn't quite got to the bottom of this, but so far as we know it's not 
463 a problem with GHC itself.  Nevertheless, just to keep life simple we usually
464 put GHC in a place with a space-free path.
465 </para>
466 </sect2>
467
468 <sect2 id="winfaq">
469 <title>Installing ghc-win32 FAQ</title>
470
471       <variablelist>
472         <varlistentry>
473           <term>I'm having trouble with symlinks.</term>
474           <listitem>
475             <para>Symlinks only work under Cygwin (<xref linkend="install" />),
476           so binaries not linked to the Cygwin
477               DLL, in particular those built for Mingwin, will not work with
478               symlinks.</para>
479           </listitem>
480         </varlistentry>
481
482         <varlistentry>
483           <term>I'm getting &ldquo;permission denied&rdquo; messages from the
484             <command>rm</command> or <command>mv</command>.</term>
485           <listitem>
486             <para>This can have various causes: trying to rename a directory
487               when an Explorer window is open on it tends to fail. Closing the
488               window generally cures the problem, but sometimes its cause is
489               more mysterious, and logging off and back on or rebooting may be
490               the quickest cure.</para>
491           </listitem>
492         </varlistentry>
493       </variablelist>
494 </sect2>
495
496 </sect1>
497
498
499 <sect1 id="install-files"><title>The layout of installed files</title>
500
501 <para>
502 This section describes what files get installed where.  You don't need to know it
503 if you are simply installing GHC, but it is vital information if you are changing
504 the implementation.
505 </para>
506 <para> GHC is installed in two directory trees:</para>
507 <variablelist>
508 <varlistentry>
509 <term>Library directory,</term>
510 <listitem> <para> known as <filename>$(libdir)</filename>, holds all the 
511 support files needed to run GHC.  On Unix, this 
512 directory is usually something like <filename>/usr/lib/ghc/ghc-5.02</filename>. </para>
513 </listitem>
514 </varlistentry>
515 <varlistentry>
516 <term>Binary directory</term>
517 <listitem> <para> known as <filename>$(bindir)</filename>, holds executables that 
518 the user is expected to invoke.
519 Notably, it contains
520 <filename>ghc</filename> and <filename>ghci</filename>.  On Unix, this directory
521 can be anywhere, but is typically something like <filename>/usr/local/bin</filename>.  On Windows,
522 however, this directory <emphasis>must be</emphasis> <filename>$(libdir)/bin</filename>.
523 </para>
524 </listitem>
525 </varlistentry>
526 </variablelist>
527
528 <para>
529 When GHC runs, it must know where its library directory is.
530 It finds this out in one of two ways:
531 </para>
532 <itemizedlist>
533 <listitem>
534 <para>
535 <filename>$(libdir)</filename> is passed to GHC using the <option>-B</option> flag.
536 On Unix (but not Windows), the installed <filename>ghc</filename> is just a one-line 
537 shell script that invokes the real GHC, passing a suitable <option>-B</option> flag. 
538 [All the user-supplied flags
539 follow, and a later <option>-B</option> flag overrides an earlier one, so a user-supplied
540 one wins.]
541 </para>
542 </listitem>
543 <listitem>
544 <para> On Windows (but not Unix), if no <option>-B</option> flag is given, GHC uses a system
545 call to find the directory in which the running GHC executable lives, and derives 
546 <filename>$(libdir)</filename> from that. [Unix lacks such a system call.]
547 That is why <filename>$(bindir)</filename> must be <filename>$(libdir)/bin</filename>.
548 </para>
549 </listitem>
550 </itemizedlist>
551
552 <sect2> <title>The binary directory</title>
553
554 <para>The binary directory, <filename>$(bindir)</filename> contains user-visible
555 executables, notably <filename>ghc</filename> and <filename>ghci</filename>.
556 You should add it to your <literal>$PATH</literal>
557 </para>
558
559 <para>On Unix, the user-invokable <filename>ghc</filename> invokes <filename>$(libdir)/ghc-<replaceable>version</replaceable></filename>,
560 passing a suitable <option>-B</option> flag to tell <filename>ghc-<replaceable>version</replaceable></filename> where
561 <filename>$(libdir)</filename> is.
562 Similarly <filename>ghci</filename>, except the extra flag <literal>--interactive</literal> is passed.
563 </para>
564
565 <para>On Win32, the user-invokable <filename>ghc</filename> binary 
566 is the Real Thing (no intervening
567 shell scripts or <filename>.bat</filename> files). 
568 Reason: we sometimes invoke GHC with very long command lines,
569 and <filename>cmd.exe</filename> (which executes <filename>.bat</filename> files)
570 truncates them.  Similarly <filename>ghci</filename> is a C wrapper program that invokes <filename>ghc --interactive</filename>
571 (passing on all other arguments), not a <filename>.bat</filename> file.
572 </para>
573
574
575 </sect2>
576
577 <sect2> <title>The library directory</title>
578
579 <para>The layout of the library directory, <filename>$(libdir)</filename> is almost identical on
580 Windows and Unix, as follows.  Differences between Windows and Unix
581 are noted thus <literal>[Win32 only]</literal> and are commented below.</para>
582
583 <programlisting>
584   $(libdir)/
585     package.conf           GHC package configuration
586     ghc-usage.txt          Message displayed by ghc &ndash;&ndash;help
587     
588     bin/                   [Win32 only]  User-visible binaries
589          ghc.exe
590          ghci.exe
591
592     unlit                  Remove literate markup
593     
594     touchy.exe             [Win32 only]
595     perl.exe               [Win32 only]
596     gcc.exe                [Win32 only]
597    
598     ghc-x.xx               GHC executable [Unix only]
599    
600     ghc-split              Asm code splitter
601     ghc-asm                Asm code mangler
602
603     gcc-lib/               [Win32 only] Support files for gcc
604         specs              gcc configuration
605  
606         cpp0.exe           gcc support binaries
607         as.exe
608         ld.exe
609
610         crt0.o              Standard
611            ..etc..          binaries
612         
613         libmingw32.a        Standard
614            ..etc..          libraries
615
616         *.h                 Include files
617
618     imports/                GHC interface files
619         std/*.hi              'std' library
620         lang/*.hi             'lang' library
621         ..etc..
622
623     include/                 C header files
624         StgMacros.h           GHC-specific
625         ..etc...              header files
626
627         mingw/*.h            [Win32 only] Mingwin header files
628
629     libHSrts.a              GHC library archives
630     libHSstd.a
631     libHSlang.a
632       ..etc..
633
634     HSstd1.o                GHC library linkables
635     HSstd2.o                  (used by ghci, which does
636     HSlang.o                  not grok .a files yet)
637 </programlisting>
638
639 <para>Note that:
640 <itemizedlist>
641
642         <listitem>
643           <para><filename>$(libdir)</filename> also contains support
644           binaries.  These are <emphasis>not</emphasis> expected to be
645           on the user's <filename>PATH</filename>, but and are invoked
646           directly by GHC.  In the Makefile system, this directory is
647           also called <filename>$(libexecdir)</filename>, but
648           <emphasis>you are not free to change it</emphasis>.  It must
649           be the same as <filename>$(libdir)</filename>.</para>
650         </listitem>
651
652 <listitem>
653 <para>We distribute <filename>gcc</filename> with the Win32 distribution of GHC, so that users
654 don't need to install <filename>gcc</filename>, nor need to care about which version it is.
655 All <filename>gcc</filename>'s support files are kept in  <filename>$(libdir)/gcc-lib/</filename>.
656 </para> 
657 </listitem>
658
659 <listitem>
660 <para>Similarly, we distribute <filename>perl</filename> and a <filename>touch</filename> 
661 replacement (<filename>touchy.exe</filename>)
662 with the Win32 distribution of GHC. </para> 
663 </listitem>
664
665         <listitem>
666           <para>The support programs <filename>ghc-split</filename>
667           and <filename>ghc-asm</filename> are Perl scripts.  The
668           first line says <literal>#!/bin/perl</literal>; on Unix, the
669           script is indeed invoked as a shell script, which invokes
670           Perl; on Windows, GHC invokes
671           <filename>$(libdir)/perl.exe</filename> directly, which
672           treats the <literal>#!/bin/perl</literal> as a comment.
673           Reason: on Windows we want to invoke the Perl distributed
674           with GHC, rather than assume some installed one.  </para>
675         </listitem>
676 </itemizedlist>
677 </para>
678
679 </sect2>
680
681 </sect1>
682
683 </chapter>
684
685 <!-- Emacs stuff:
686      ;;; Local Variables: ***
687      ;;; mode: xml ***
688      ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter") ***
689      ;;; End: ***
690  -->