[project @ 2003-09-11 10:26:31 by simonmar]
[ghc-hetmet.git] / docs / building / building.sgml
index 913cb1b..4d25aa2 100644 (file)
@@ -434,8 +434,8 @@ setsockopt IPTOS_THROUGHPUT: Invalid argument
           <xref linkend="projects">).</para>
 
          <para>Remember that if you do not have
-          <literal>happy</literal> installed, you need to check it out
-          as well.</para>
+          <literal>happy</literal> and/or <literal>Alex</literal>
+          installed, you need to check them out as well.</para>
        </listitem>
       </itemizedlist>
     </sect2>
@@ -1262,6 +1262,19 @@ $ cvs checkout nofib/spectral
       </varlistentry>
 
       <varlistentry>
+       <term>Alex</term>
+       <indexterm><primary>Alex</primary></indexterm>
+       <listitem>
+         <para>Alex is a lexical-analyser generator for Haskell,
+         which GHC uses to generate its lexer.  Like Happy, Alex is
+         written in Haskell and is a project in the CVS repository.
+         Alex distributions are available from <ulink
+         url="http://www.haskell.org/alex/">Alex's Web
+         Page</ulink>.</para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
        <term>Autoconf</term>
        <indexterm><primary>pre-supposed: Autoconf</primary></indexterm>
        <indexterm><primary>Autoconf, pre-supposed</primary></indexterm>
@@ -2238,7 +2251,8 @@ Foo.o : Baz.hi
       build tree.</para>
 
       <para>Happy can similarly be run from the build tree, using
-      <filename>happy/src/happy-inplace</filename>.</para>
+      <filename>happy/src/happy-inplace</filename>, and similarly for
+      Alex and Haddock.</para>
     </sect2>
 
     <sect2>
@@ -3711,6 +3725,20 @@ foo% make install
       since unregisterised compilation is usually just a step on the
       way to a full registerised port, we don't mind too much.</para>
 
+      <para>Notes on GHC portability in general: we've tried to stick
+      to writing portable code in most parts of the system, so it
+      should compile on any POSIXish system with gcc, but in our
+      experience most systems differ from the standards in one way or
+      another.  Deal with any problems as they arise - if you get
+      stuck, ask the experts on
+      <email>glasgow-haskell-users@haskell.org</email>.</para>
+       
+      <para>Lots of useful information about the innards of GHC is
+      available in the <ulink
+      url="http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/">GHC
+      Commentary</ulink>, which might be helpful if you run into some
+      code which needs tweaking for your system.</para>
+
       <sect3>
        <title>Cross-compiling to produce an unregisterised GHC</title>
 
@@ -3742,6 +3770,7 @@ foo% make install
 
            <listitem>
 <screen>
+$ cd <replaceable>T</replaceable>
 $ ./configure --enable-hc-boot --enable-hc-boot-unregisterised
 </screen>
 
@@ -3795,17 +3824,6 @@ GhcStage2HcOpts = -O -fvia-C -keep-hc-files
            </listitem>
 
            <listitem>
-             <para>Copy
-             <filename><replaceable>T</replaceable>/ghc/includes/config.h</filename>
-             to
-             <filename><replaceable>H</replaceable>/ghc/includes</filename>.
-             Note that we are building on the host machine, using the
-             target machine's <literal>config.h</literal> file.  This
-             is so that the intermediate C files generated here will
-             be suitable for compiling on the target system.</para>
-           </listitem>
-
-           <listitem>
              <para>Edit
              <filename><replaceable>H</replaceable>/mk/config.mk</filename>:</para>
              <itemizedlist>
@@ -3821,16 +3839,30 @@ GhcStage2HcOpts = -O -fvia-C -keep-hc-files
            </listitem>
            
            <listitem>
-<screen>
-$ cd <replaceable>H</replaceable>/glafp-utils && make boot && make
-</screen>
+             <para>Copy
+             <filename><replaceable>T</replaceable>/ghc/includes/config.h</filename>
+             to
+             <filename><replaceable>H</replaceable>/ghc/includes</filename>.
+             Note that we are building on the host machine, using the
+             target machine's <literal>config.h</literal> file.  This
+             is so that the intermediate C files generated here will
+             be suitable for compiling on the target system.</para>
+
            </listitem>
-           
+
+             <listitem>
+               <para>Touch <literal>config.h</literal>, just to make
+               sure it doesn't get replaced during the build:</para>
+<screen>
+$ touch <replaceable>H</replaceable>/ghc/includes/config.h</screen>
+             </listitem>
+
            <listitem>
+               <para>Now build the compiler:</para>
 <screen>
+$ cd <replaceable>H</replaceable>/glafp-utils && make boot && make
 $ cd <replaceable>H</replaceable>/ghc && make boot && make
 </screen>
-
              <para>Don't worry if the build falls over in the RTS, we
               don't need the RTS yet.</para>
            </listitem>
@@ -3876,55 +3908,32 @@ $ make hc-file-bundle Project=Ghc
          <listitem>
            <para>On the target machine:</para>
 
-         <para>At this stage we simply need to bootstrap a compiler
-         from the intermediate C files we generated above.  It is
-         possible to follow the instructions for bootstrapping from C
-         files in <xref linkend="sec-booting-from-hc">, but we find
-         that the script <literal>hc-build</literal> is more suited
-         to booting a registerised compiler on an already-working
-         platform.  The following instructions duplicate some of what
-         the <literal>hc-build</literal> script does, but the process
-         is made simpler by just aiming to get a working compiler,
-         then using this to bootstrap a completely fresh tree.</para>
-
-         <itemizedlist>
-           <listitem>
-<screen>
-$ cd <replaceable>T</replaceable>/.. && tar xvzf ghc-*-hc.tar.gz
-</screen>
-           </listitem>
-
-           <listitem>
-             <para>Create
-             <filename><replaceable>T</replaceable>/mk/build.mk</filename>,
-             with the following contents:</para>
-
-<programlisting>
-GhcUnregisterised = YES
-GhcLibWays =
-SplitObjs = NO
-GhcWithNativeCodeGen = NO
-GhcWithInterpreter = NO
-</programlisting>
-           </listitem>
-
-           <listitem>
-             <para>Bootstrap GHC from the .hc files:</para>
+           <para>At this stage we simply need to bootstrap a compiler
+           from the intermediate C files we generated above.  The
+           process of bootstrapping from C files is automated by the
+           script in <literal>distrib/hc-build</literal>, and is
+           described in <xref linkend="sec-booting-from-hc">.</para>
 
 <screen>
-$ ./configure --enable-hc-boot --enable-hc-boot-unregisterised
-$ make -C glafp-utils boot all
-$ make -C ghc boot
-$ make -C libraries boot all
-$ make -C ghc all
+$ ./distrib/hc-build --enable-hc-boot-unregisterised
 </screen>
-           </listitem>
 
-           <listitem>
-             <para>You should now have a working GHC binary.  You
-              might want to try using this GHC to compile a Hello
-              World, to make sure it's doing something
-              reasonable:</para>
+           <para>However, since this is a bootstrap on a new machine,
+           the automated process might not run to completion the
+           first time.  For that reason, you might want to treat the
+           <literal>hc-build</literal> script as a list of
+           instructions to follow, rather than as a fully automated
+           script.  This way you'll be able to restart the process
+           part-way through if you need to fix anything on the
+           way.</para>
+
+           <para>Don't bother with running
+           <literal>make&nbsp;install</literal> in the newly
+           bootstrapped tree; just use the compiler in that tree to
+           build a fresh compiler from scratch, this time without
+           booting from C files.  Before doing this, you might want
+           to check that the bootstrapped compiler is generating
+           working binaries:</para>
 
 <screen>
 $ cat >hello.hs
@@ -3932,39 +3941,17 @@ main = putStrLn "Hello World!\n"
 ^D
 $ <replaceable>T</replaceable>/ghc/compiler/ghc-inplace hello.hs -o hello
 $ ./hello
-Hello World!\n
+Hello World!
 </screen>
-           </listitem>
 
-           <listitem>
-             <para>Now, use this compiler
-             (<filename><replaceable>T</replaceable>/ghc/compiler/ghc-inplace</filename>)
-             to build another GHC tree from scratch, as
-             normal.</para>
-           </listitem>
-         </itemizedlist>
+           <para>Once you have the unregisterised compiler up and
+           running, you can use it to start a registerised port.  The
+           following sections describe the various parts of the
+           system that will need architecture-specific tweaks in
+           order to get a registerised build going.</para>
+
          </listitem>
        </itemizedlist>
-
-       <para>The build may not go through cleanly.  We've tried to
-       stick to writing portable code in most parts of the compiler,
-       so it should compile on any POSIXish system with gcc, but in
-       our experience most systems differ from the standards in one
-       way or another.  Deal with any problems as they arise - if you
-       get stuck, ask the experts on
-       <email>glasgow-haskell-users@haskell.org</email>.</para>
-       
-       <para>Once you have the unregisterised compiler up and
-       running, you can use it to start a registerised port.  The
-       following sections describe the various parts of the system
-       that will need architecture-specific tweaks in order to get a
-       registerised build going.</para>
-
-       <para>Lots of useful information about the innards of GHC is
-       available in the <ulink
-       url="http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/">GHC
-       Commentary</ulink>, which might be helpful if you run into
-       some code which needs tweaking for your system.</para>
       </sect3>
 
       <sect3>
@@ -4623,6 +4610,12 @@ Happy is a parser generator used to compile the Haskell grammar.  Add it in your
 </para>
 </listitem>
 
+         <listitem>
+           <para>Install Alex.  This can be done by building from the
+           source distribution in the usual way.  Sources are
+           available from <ulink
+           url="http://www.haskell.org/alex">http://www.haskell.org/alex</ulink>.</para>
+         </listitem>
 
 <listitem>
 <para>GHC uses the <emphasis>mingw</emphasis> C compiler to