Remove "What bundles there are" now we only have the standard one
[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 id="GHC-test">
158 <title>Testing that GHC seems to be working
159 </title>
160
161 <para>
162 <indexterm><primary>testing a new GHC</primary></indexterm>
163 </para>
164
165 <para>
166 The way to do this is, of course, to compile and run <emphasis>this</emphasis> program
167 (in a file <literal>Main.hs</literal>):
168 </para>
169
170 <para>
171
172 <programlisting>
173 main = putStr "Hello, world!\n"
174 </programlisting>
175
176 </para>
177
178 <para>
179 Compile the program, using the <literal>-v</literal> (verbose) flag to verify that
180 libraries, etc., are being found properly:
181
182 <screen>
183 % ghc -v -o hello Main.hs</screen>
184
185 </para>
186
187 <para>
188 Now run it:
189
190 <screen>
191 % ./hello
192 Hello, world!</screen>
193
194 </para>
195
196 <para>
197 Some simple-but-profitable tests are to compile and run the notorious
198 <literal>nfib</literal><indexterm><primary>nfib</primary></indexterm> program, using different numeric types.  Start with
199 <literal>nfib :: Int -&gt; Int</literal>, and then try <literal>Integer</literal>, <literal>Float</literal>, <literal>Double</literal>,
200 <literal>Rational</literal> and perhaps the overloaded version.  Code for this is
201 distributed in <literal>ghc/misc/examples/nfib/</literal> in a source distribution.
202 </para>
203
204 <para>For more information on how to &ldquo;drive&rdquo; GHC, read
205 on...</para>
206
207 </sect3>
208
209 </sect2>
210
211 </sect1>
212
213
214 <sect1 id="install-windows"><title>Installing on Windows</title>
215
216 <para>
217 Getting the Glasgow Haskell Compiler (post 5.02) to run on Windows platforms is
218 a snap: the installer does everything you need.  
219 </para>
220
221 <sect2><title>Installing GHC on Windows</title>
222
223 <para>
224 To install GHC, use the following steps:
225 </para>
226 <itemizedlist>
227 <listitem><para>Download the installer
228 from the
229 <ulink
230 url="http://www.haskell.org/ghc/download.html">GHC download page</ulink>.
231 </para></listitem>
232
233 <listitem><para>Run the installer.
234 On Windows, all of GHC's files are installed in a single directory.
235 You can override it, but by default this directory is
236 <filename>c:/ghc/<replaceable>ghc-version</replaceable></filename>.
237 The executable binary for GHC will be installed in the
238 <filename>bin/</filename> sub-directory of the installation directory.
239 If you want to invoke GHC from a command line, add this
240 to your PATH environment variable.
241 </para>
242 <para>
243 When installation is complete, you should find GHCi and the GHC
244 documentation are available in your Start menu under
245 "Start/All Programs/GHC/<replaceable>ghc-version</replaceable>".
246 </para>
247 </listitem>
248
249 <listitem><para>
250 GHC needs a directory in which to create, and later delete, temporary files.
251 It uses the standard Windows procedure <literal>GetTempPath()</literal> to
252 find a suitable directory.  This procedure returns:
253 <itemizedlist>
254 <listitem><para>The path in environment variable TMP, 
255 if TMP is set.</para></listitem>
256 <listitem><para>Otherwise, the path in environment variable TEMP, 
257 if TEMP is set.</para></listitem>
258 <listitem><para>Otherwise, there is a per-user default which varies
259 between versions of Windows. On NT and XP-ish versions, it might 
260 be:
261 <filename>c:\Documents and Settings\&lt;username&gt;\Local Settings\Temp</filename>
262 </para></listitem>
263 </itemizedlist>
264 The main point is that if you don't do anything GHC will work fine;
265 but if you want to control where the directory is, you can do so by
266 setting TMP or TEMP.
267 </para></listitem>
268
269 <listitem>
270 <para>
271 To test the fruits of your labour, try now to compile a simple
272 Haskell program:
273 </para>
274
275 <screen>
276 bash$ cat main.hs
277 module Main(main) where
278
279 main = putStrLn "Hello, world!"
280 bash$ ghc -o main main.hs
281 ..
282 bash$ ./main
283 Hello, world!
284 bash$</screen>
285 </listitem>
286 </itemizedlist>
287
288 <para>
289 You do <emphasis>not</emphasis> need the Cygwin toolchain, or anything
290 else, to install and run GHC.
291 </para>
292 <para>
293 An installation of GHC requires about 340M of disk space.
294 To run GHC comfortably, your machine should have at least
295 64M of memory.
296 </para>
297 </sect2>
298
299 <sect2><title>Moving GHC around</title>
300 <para>
301 Once GHC is installed, you can freely move the entire GHC tree just by copying
302 the <filename>c:/ghc/<replaceable>ghc-version</replaceable></filename>
303 directory. (You will need to fix up 
304 the links in "Start/All Programs/GHC/<replaceable>ghc-version</replaceable>"
305 if you do this.)
306 </para>
307 <para>
308 It is OK to put GHC tree in a directory whose path involves spaces.  However,
309 don't do this if you use want to use GHC with the Cygwin tools, 
310 because Cygwin can get confused when this happens.
311 We havn't quite got to the bottom of this, but so far as we know it's not 
312 a problem with GHC itself.  Nevertheless, just to keep life simple we usually
313 put GHC in a place with a space-free path.
314 </para>
315 </sect2>
316
317 <sect2 id="winfaq">
318 <title>Installing ghc-win32 FAQ</title>
319
320       <variablelist>
321         <varlistentry>
322           <term>I'm having trouble with symlinks.</term>
323           <listitem>
324             <para>Symlinks only work under Cygwin (<xref linkend="install" />),
325           so binaries not linked to the Cygwin
326               DLL, in particular those built for Mingwin, will not work with
327               symlinks.</para>
328           </listitem>
329         </varlistentry>
330
331         <varlistentry>
332           <term>I'm getting &ldquo;permission denied&rdquo; messages from the
333             <command>rm</command> or <command>mv</command>.</term>
334           <listitem>
335             <para>This can have various causes: trying to rename a directory
336               when an Explorer window is open on it tends to fail. Closing the
337               window generally cures the problem, but sometimes its cause is
338               more mysterious, and logging off and back on or rebooting may be
339               the quickest cure.</para>
340           </listitem>
341         </varlistentry>
342       </variablelist>
343 </sect2>
344
345 </sect1>
346
347
348 <sect1 id="install-files"><title>The layout of installed files</title>
349
350 <para>
351 This section describes what files get installed where.  You don't need to know it
352 if you are simply installing GHC, but it is vital information if you are changing
353 the implementation.
354 </para>
355 <para> GHC is installed in two directory trees:</para>
356 <variablelist>
357 <varlistentry>
358 <term>Library directory,</term>
359 <listitem> <para> known as <filename>$(libdir)</filename>, holds all the 
360 support files needed to run GHC.  On Unix, this 
361 directory is usually something like <filename>/usr/lib/ghc/ghc-5.02</filename>. </para>
362 </listitem>
363 </varlistentry>
364 <varlistentry>
365 <term>Binary directory</term>
366 <listitem> <para> known as <filename>$(bindir)</filename>, holds executables that 
367 the user is expected to invoke.
368 Notably, it contains
369 <filename>ghc</filename> and <filename>ghci</filename>.  On Unix, this directory
370 can be anywhere, but is typically something like <filename>/usr/local/bin</filename>.  On Windows,
371 however, this directory <emphasis>must be</emphasis> <filename>$(libdir)/bin</filename>.
372 </para>
373 </listitem>
374 </varlistentry>
375 </variablelist>
376
377 <para>
378 When GHC runs, it must know where its library directory is.
379 It finds this out in one of two ways:
380 </para>
381 <itemizedlist>
382 <listitem>
383 <para>
384 <filename>$(libdir)</filename> is passed to GHC using the <option>-B</option> flag.
385 On Unix (but not Windows), the installed <filename>ghc</filename> is just a one-line 
386 shell script that invokes the real GHC, passing a suitable <option>-B</option> flag. 
387 [All the user-supplied flags
388 follow, and a later <option>-B</option> flag overrides an earlier one, so a user-supplied
389 one wins.]
390 </para>
391 </listitem>
392 <listitem>
393 <para> On Windows (but not Unix), if no <option>-B</option> flag is given, GHC uses a system
394 call to find the directory in which the running GHC executable lives, and derives 
395 <filename>$(libdir)</filename> from that. [Unix lacks such a system call.]
396 That is why <filename>$(bindir)</filename> must be <filename>$(libdir)/bin</filename>.
397 </para>
398 </listitem>
399 </itemizedlist>
400
401 <sect2> <title>The binary directory</title>
402
403 <para>The binary directory, <filename>$(bindir)</filename> contains user-visible
404 executables, notably <filename>ghc</filename> and <filename>ghci</filename>.
405 You should add it to your <literal>$PATH</literal>
406 </para>
407
408 <para>On Unix, the user-invokable <filename>ghc</filename> invokes <filename>$(libdir)/ghc-<replaceable>version</replaceable></filename>,
409 passing a suitable <option>-B</option> flag to tell <filename>ghc-<replaceable>version</replaceable></filename> where
410 <filename>$(libdir)</filename> is.
411 Similarly <filename>ghci</filename>, except the extra flag <literal>--interactive</literal> is passed.
412 </para>
413
414 <para>On Win32, the user-invokable <filename>ghc</filename> binary 
415 is the Real Thing (no intervening
416 shell scripts or <filename>.bat</filename> files). 
417 Reason: we sometimes invoke GHC with very long command lines,
418 and <filename>cmd.exe</filename> (which executes <filename>.bat</filename> files)
419 truncates them.  Similarly <filename>ghci</filename> is a C wrapper program that invokes <filename>ghc --interactive</filename>
420 (passing on all other arguments), not a <filename>.bat</filename> file.
421 </para>
422
423
424 </sect2>
425
426 <sect2> <title>The library directory</title>
427
428 <para>The layout of the library directory, <filename>$(libdir)</filename> is almost identical on
429 Windows and Unix, as follows.  Differences between Windows and Unix
430 are noted thus <literal>[Win32 only]</literal> and are commented below.</para>
431
432 <programlisting>
433   $(libdir)/
434     package.conf           GHC package configuration
435     ghc-usage.txt          Message displayed by ghc &ndash;&ndash;help
436     
437     bin/                   [Win32 only]  User-visible binaries
438          ghc.exe
439          ghci.exe
440
441     unlit                  Remove literate markup
442     
443     touchy.exe             [Win32 only]
444     perl.exe               [Win32 only]
445     gcc.exe                [Win32 only]
446    
447     ghc-x.xx               GHC executable [Unix only]
448    
449     ghc-split              Asm code splitter
450     ghc-asm                Asm code mangler
451
452     gcc-lib/               [Win32 only] Support files for gcc
453         specs              gcc configuration
454  
455         cpp0.exe           gcc support binaries
456         as.exe
457         ld.exe
458
459         crt0.o              Standard
460            ..etc..          binaries
461         
462         libmingw32.a        Standard
463            ..etc..          libraries
464
465         *.h                 Include files
466
467     imports/                GHC interface files
468         std/*.hi              'std' library
469         lang/*.hi             'lang' library
470         ..etc..
471
472     include/                 C header files
473         StgMacros.h           GHC-specific
474         ..etc...              header files
475
476         mingw/*.h            [Win32 only] Mingwin header files
477
478     libHSrts.a              GHC library archives
479     libHSstd.a
480     libHSlang.a
481       ..etc..
482
483     HSstd1.o                GHC library linkables
484     HSstd2.o                  (used by ghci, which does
485     HSlang.o                  not grok .a files yet)
486 </programlisting>
487
488 <para>Note that:
489 <itemizedlist>
490
491         <listitem>
492           <para><filename>$(libdir)</filename> also contains support
493           binaries.  These are <emphasis>not</emphasis> expected to be
494           on the user's <filename>PATH</filename>, but and are invoked
495           directly by GHC.  In the Makefile system, this directory is
496           also called <filename>$(libexecdir)</filename>, but
497           <emphasis>you are not free to change it</emphasis>.  It must
498           be the same as <filename>$(libdir)</filename>.</para>
499         </listitem>
500
501 <listitem>
502 <para>We distribute <filename>gcc</filename> with the Win32 distribution of GHC, so that users
503 don't need to install <filename>gcc</filename>, nor need to care about which version it is.
504 All <filename>gcc</filename>'s support files are kept in  <filename>$(libdir)/gcc-lib/</filename>.
505 </para> 
506 </listitem>
507
508 <listitem>
509 <para>Similarly, we distribute <filename>perl</filename> and a <filename>touch</filename> 
510 replacement (<filename>touchy.exe</filename>)
511 with the Win32 distribution of GHC. </para> 
512 </listitem>
513
514         <listitem>
515           <para>The support programs <filename>ghc-split</filename>
516           and <filename>ghc-asm</filename> are Perl scripts.  The
517           first line says <literal>#!/bin/perl</literal>; on Unix, the
518           script is indeed invoked as a shell script, which invokes
519           Perl; on Windows, GHC invokes
520           <filename>$(libdir)/perl.exe</filename> directly, which
521           treats the <literal>#!/bin/perl</literal> as a comment.
522           Reason: on Windows we want to invoke the Perl distributed
523           with GHC, rather than assume some installed one.  </para>
524         </listitem>
525 </itemizedlist>
526 </para>
527
528 </sect2>
529
530 </sect1>
531
532 </chapter>
533
534 <!-- Emacs stuff:
535      ;;; Local Variables: ***
536      ;;; mode: xml ***
537      ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter") ***
538      ;;; End: ***
539  -->