[project @ 2003-04-14 13:36:04 by simonpj]
[ghc-hetmet.git] / docs / building / building.sgml
index 071f4c9..6a0e950 100644 (file)
             from the access control list.  Don't leave them there but
             deny them access, because 'they' may be a list that
             includes you!</para>
+           <para>[March 2003] In fact <command>ssh</command> 3.6.1 now seems to <emphasis>require</emphasis>
+             you to have Unix permissions 600 (read/write for owner only) 
+             on the <literal>.ssh/identity</literal> file, else it 
+             bombs out.  For your local C drive, it seems that <literal>chmod 600 identity</literal> works,
+             but on Windows NT/XP, it doesn't work on a network drive (exact dteails obscure).  
+             The solution seems to be to set the CYGWIN environment
+             variable to "<literal>ntsec neta</literal>".  The CYGWIN environment variable is discussed
+             in <ulink url="http://cygwin.com/cygwin-ug-net/using-cygwinenv.html">the Cygwin User's Guide</ulink>,
+             and there are more details in <ulink url="http://cygwin.com/faq/faq_4.html#SEC44">the Cygwin FAQ</ulink>.
+             </para>
          </listitem>
 
          <listitem>
@@ -1142,6 +1152,23 @@ $ cvs checkout nofib/spectral
     <variablelist>
 
       <varlistentry>
+       <term>GHC</term>
+       <indexterm><primary>pre-supposed: GHC</primary></indexterm>
+       <indexterm><primary>GHC, pre-supposed</primary></indexterm>
+       <listitem>
+         <para>GHC is required to build many of the tools, including
+         GHC itself.  If you need to port GHC to your platform
+         because there isn't a binary distribution of GHC available,
+         then see <xref linkend="sec-porting-ghc">.</para>
+
+         <para>Which version of GHC you need will depend on the
+         packages you intend to build.  GHC itself will normally
+         build using one of several older versions of itself - check
+         the announcement or release notes for details.</para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
        <term>Perl</term>
        <indexterm><primary>pre-supposed: Perl</primary></indexterm>
        <indexterm><primary>Perl, pre-supposed</primary></indexterm>
@@ -1342,6 +1369,26 @@ $ cvs checkout nofib/spectral
     software, and lay hands on them gently when they don't
     work.</para>
 
+    <sect2 id="quick-start">
+      <title>Quick Start</title>
+
+      <para>If you are starting from a source distribution, and just
+      want a completely standard build, then the following should
+      work:</para>
+
+<screen>$ ./configure
+$ make
+$ make install
+</screen>
+
+      <para>For GHC, this will do a 2-stage bootstrap build of the
+      compiler, with profiling libraries, and install the
+      results.</para>
+
+      <para>If you want to do anything at all non-standard, or you
+      want to do some development, read on...</para>
+    </sect2>
+
     <sect2 id="sec-source-tree">
       <title>Your source tree</title>
 
@@ -1495,6 +1542,9 @@ $ cvs checkout nofib/spectral
        <varlistentry>
          <term>Step 1: get ready for configuration.</term>
          <listitem>
+           <para>NOTE: if you're starting from a source distribution,
+           rather than CVS sources, you can skip this step.</para>
+
            <para>Change directory to
             <constant>&dollar;(FPTOOLS&lowbar;TOP)</constant> and
             issue the command
@@ -1517,12 +1567,6 @@ $ cvs checkout nofib/spectral
             be short, although the resulting shell script,
             <command>configure</command>, and
             <filename>mk/config.h.in</filename>, are long.</para>
-
-           <para>In case you don't have <command>autoconf</command>
-            we distribute the results, <command>configure</command>,
-            and <filename>mk/config.h.in</filename>, with the source
-            distribution.  They aren't kept in the repository,
-            though.</para>
          </listitem>
        </varlistentry>
 
@@ -1865,7 +1909,92 @@ $ emacs mk/build.mk
       the top of your <literal>fptools</literal> tree and type
       <command>gmake</command>.  This will prepare the tree and build
       the various projects in the correct order.</para>
+    </sect2>
+
+    <sect2 id="sec-bootstrapping">
+      <title>Bootstrapping GHC</title>
+
+      <para>GHC requires a 2-stage bootstrap in order to provide 
+      full functionality, including GHCi.  By a 2-stage bootstrap, we
+      mean that the compiler is built once using the installed GHC,
+      and then again using the compiler built in the first stage.  You
+      can also build a stage 3 compiler, but this normally isn't
+      necessary except to verify that the stage 2 compiler is working
+      properly.</para>
+
+      <para>Note that when doing a bootstrap, the stage 1 compiler
+      must be built, followed by the runtime system and libraries, and
+      then the stage 2 compiler.  The correct ordering is implemented
+      by the top-level fptools <filename>Makefile</filename>, so if
+      you want everything to work automatically it's best to start
+      <command>make</command> from the top of the tree.  When building
+      GHC, the top-level fptools <filename>Makefile</filename> is set
+      up to do a 2-stage bootstrap by default (when you say
+      <command>make</command>).  Some other targets it supports
+      are:</para>
+
+      <variablelist>
+       <varlistentry>
+         <term>stage1</term>
+         <listitem>
+           <para>Build everything as normal, including the stage 1
+           compiler.</para>
+         </listitem>
+       </varlistentry>
+
+       <varlistentry>
+         <term>stage2</term>
+         <listitem>
+           <para>Build the stage 2 compiler only.</para>
+         </listitem>
+       </varlistentry>
+
+       <varlistentry>
+         <term>stage3</term>
+         <listitem>
+           <para>Build the stage 3 compiler only.</para>
+         </listitem>
+       </varlistentry>
+
+       <varlistentry>
+         <term>bootstrap</term> <term>bootstrap2</term>
+         <listitem>
+           <para>Build stage 1 followed by stage 2.</para>
+         </listitem>
+       </varlistentry>
+
+       <varlistentry>
+         <term>bootstrap3</term>
+         <listitem>
+           <para>Build stages 1, 2 and 3.</para>
+         </listitem>
+       </varlistentry>
+
+       <varlistentry>
+         <term>install</term>
+         <listitem>
+           <para>Install everything, including the compiler built in
+           stage 2.  To override the stage, say <literal>make install
+           stage=<replaceable>n</replaceable></literal> where
+           <replaceable>n</replaceable> is the stage to install.</para>
+         </listitem>
+       </varlistentry>
+      </variablelist>
+
+      <para>The top-level <filename>Makefile</filename> also arranges
+      to do the appropriate <literal>make boot</literal> steps (see
+      below) before actually building anything.</para>
 
+      <para>The <literal>stage1</literal>, <literal>stage2</literal>
+      and <literal>stage3</literal> targets also work in the
+      <literal>ghc/compiler</literal> directory, but don't forget that
+      each stage requires its own <literal>make boot</literal> step:
+      for example, you must do</para>
+
+      <screen>$ make boot stage=2</screen>
+
+      <para>before <literal>make stage2</literal> in
+      <literal>ghc/compiler</literal>.</para>
     </sect2>
 
     <sect2 id="sec-standard-targets">
@@ -3955,7 +4084,7 @@ guide) before continuing to read these notes.
 </para>
 
 
-<sect2><Title>Cygwin and MinGW</Title>
+<sect2 id="cygwin-and-mingw"><Title>Cygwin and MinGW</Title>
 
 <para> The Windows situation for building GHC is rather confusing.  This section
 tries to clarify, and to establish terminology.</para>
@@ -4010,6 +4139,37 @@ that Haskell programs compiled by GHC-cygwin can import the (Haskell) Posix libr
 </para>
 </sect3>
 
+<sect3><title>HOST_OS vs TARGET_OS</title>
+
+<para>
+In the source code you'll find various ifdefs looking like:
+<programlisting>
+  #ifdef mingw32_HOST_OS
+    ...blah blah...
+  #endif
+</programlisting>
+and 
+<programlisting>
+  #ifdef mingw32_TARGET_OS
+    ...blah blah...
+  #endif
+</programlisting>
+These macros are set by the configure script (via the file config.h).
+Which is which?  The criterion is this.  In the ifdefs in GHC's source code:
+<itemizedlist>
+  <listitem> <para>
+  The "host" system is the one on which GHC itself will be run.
+  </para> </listitem>
+  <listitem> <para>
+  The "target" system is the one for which the program compiled by GHC will be run.
+  </para> </listitem>
+</itemizedlist>
+For a stage-2 compiler, in which GHCi is available, the "host" and "target" systems must be the same.
+So then it doesn't really matter whether you use the HOST_OS or TARGET_OS cpp macros.
+
+</para>
+</sect3>
+
 <sect3><title>Summary</title>
 
 <para>Notice that "GHC-mingw" means "GHC that <emphasis>targets</emphasis> MinGW".  It says nothing about 
@@ -4047,9 +4207,13 @@ but you do need it to <emphasis>build</emphasis> GHC.</para>
 
 <para> Install Cygwin from <ulink url="http://www.cygwin.com/">http://www.cygwin.com/</ulink>.
 The installation process is straightforward; we install it in <Filename>c:/cygwin</Filename>.
-Both <command>cvs</command> and <command>ssh</command>
-come with Cygwin, but you'll need them, so make sure you select them when running
-the Cygwin installer.
+During the installation dialogue, make sure that you select:
+<command>cvs</command>, <command>openssh</command>,
+<command>autoconf</command>,
+<command>binutils</command> (includes ld and (I think) ar),
+<command>gcc</command>,
+<command>flex</command>,
+<command>make</command>.
 
 </para>
 <para> Now set the following user environment variables:
@@ -4171,7 +4335,8 @@ Happy is a parser generator used to compile the Haskell grammar.  Add it in your
 
 <listitem>
 <para>GHC uses the <emphasis>mingw</emphasis> C compiler to
-generate code, so you have to install that. Just pick up a mingw bundle at
+generate code, so you have to install that (see <xref linkend="cygwin-and-mingw">). 
+Just pick up a mingw bundle at
 <ulink url="http://www.mingw.org/">http://www.mingw.org/</ulink>.
 We install it in <filename>c:/mingw</filename>.
 </para>
@@ -4184,6 +4349,18 @@ you are likely to get into a mess because their names overlap with Cygwin binari
 
 
 <listitem>
+<para>We use <command>emacs</command> a lot, so we install that too.
+When you are in <filename>fptools/ghc/compiler</filename>, you can use
+"<literal>make tags</literal>" to make a TAGS file for emacs.  That uses the utility
+<filename>fptools/ghc/utils/hasktags/hasktags</filename>, so you need to make that first.
+The most convenient way to do this is by going <literal>make boot</literal> in <filename>fptools/ghc</filename>.
+The <literal>make tags</literal> command also uses <command>etags</command>, which comes with <command>emacs</command>,
+so you will need to add <filename>emacs/bin</filename> to your <literal>PATH</literal>.
+</para>
+</listitem>
+
+
+<listitem>
 <para> Finally, check out a copy of GHC sources from
 the CVS repository, following the instructions above (<xref linkend="cvs-access">).
 </para>
@@ -4247,13 +4424,22 @@ can be really confusing.
     <filename>fptools/</filename> thus:
 
 <Screen>
-  ./configure --host=i386-unknown-mingw32 --with-gcc=/mingw/bin/gcc
+  ./configure --host=i386-unknown-mingw32 --with-gcc=c:/mingw/bin/gcc
 </Screen>
 This is the point at which you specify that you are building GHC-mingw
-(see <xref linkend="ghc-mingw">).  
-
-Both these options are important! It's possible to get into
-trouble using the wrong C compiler!</para>
+(see <xref linkend="ghc-mingw">). </para>
+
+<para> Both these options are important! It's possible to get into
+trouble using the wrong C compiler!
+Furthermore, it's very important that you specify a 
+full mingw path for <command>gcc</command>, not a cygwin path, because GHC (which
+uses this path to invoke <command>gcc</command>) is a Mingw program and won't
+understand a cygwin path..  For example, if you 
+say <literal>--with-gcc=/mingw/bin/gcc</literal>, it'll be interpreted as
+<filename>/cygdrive/c/mingw/bin/gcc</filename>, and GHC will fail the first
+time it tries to invoke it.   (Worse, the failure does not come with
+a helpful error message, unfortunately.)
+</para>
 
 <para>
 If you want to build GHC-cygwin (<xref linkend="ghc-cygwin">)