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