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