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