[project @ 2002-06-27 09:41:18 by simonmar]
[ghc-hetmet.git] / docs / building / building.sgml
index b01aad7..efe108d 100644 (file)
@@ -437,14 +437,15 @@ setsockopt IPTOS_THROUGHPUT: Invalid argument
           the <literal>fpconfig</literal> bit.</para>
 <screen>
     $ cd <replaceable>directory</replaceable>
-    $ cvs checkout ghc hslibs
+    $ cvs checkout ghc hslibs libraries
 </screen>
 
          <para>The second command here checks out the relevant
           modules you want to work on. For a GHC build, for instance,
-          you need at least the <literal>ghc</literal> and
-          <literal>hslibs</literal> modules (for a full list of the
-          projects available, see <xref linkend="projects">).</para>
+          you need at least the <literal>ghc</literal>,
+          <literal>hslibs</literal> and <literal>libraries</literal>
+          modules (for a full list of the projects available, see
+          <xref linkend="projects">).</para>
        </listitem>
       </itemizedlist>
     </sect2>
@@ -1060,6 +1061,15 @@ $ cvs checkout nofib/spectral
        </varlistentry>
 
        <varlistentry>
+         <term>ia64-unknown-linux</term>
+         <indexterm><primary>ia64-unknown-linux</primary></indexterm>
+         <listitem>
+           <para>GHC currently works unregisterised.  A registerised
+           port is in progress.</para>
+         </listitem>
+       </varlistentry>
+
+       <varlistentry>
          <term>mips-sgi-irix5</term>
          <indexterm><primary>mips-sgi-irix[5-6]</primary></indexterm>
          <listitem>
@@ -3254,8 +3264,8 @@ $ make way=p
           corresponding Haskell source (<filename>.hs</filename> or
           <filename>.lhs</filename>) in the compiler subdirectory
           <filename>ghc/compiler</filename> and in the libraries
-          (<filename>ghc/lib</filename>, and subdirectories of
-          <filename>hslibs</filename>).</para>
+          (subdirectories of <filename>hslibs</filename> and
+          <literal>libraries</literal>).</para>
        </listitem>
 
        <listitem>
@@ -3331,7 +3341,8 @@ foo% make install
        Either (a)&nbsp;download them from the GHC site (if there are
        some available for the right version of GHC), or
        (b)&nbsp;build them yourself on any machine with a working
-       GHC.</para>
+       GHC.  If at all possible this should be a machine with the
+       same word size as the target.</para>
 
        <para>There is a script available which should automate the
        process of doing the 2-stage bootstrap necessary to get the
@@ -3708,7 +3719,7 @@ Workaround: don't put weird things in string args to <command>cpp</command> macr
 </sect1>
 
 
-<sect1 id="winbuild"><title>Notes for building under Windows</title>
+<Sect1 id="winbuild"><Title>Notes for building under Windows</Title>
 
 <para>
 This section summarises how to get the utilities you need on your
@@ -3720,21 +3731,206 @@ guide) before continuing to read these notes.
 </para>
 
 
-<sect2><title>Before you start</title>
+<sect2><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>
+
+<sect3 id="ghc-mingw"><title>GHC-mingw</title>
+
+<para> <ulink url="http://www.mingw.org">MinGW (Minimalist GNU for Windows)</ulink> 
+is a collection of header
+files and import libraries that allow one to use <command>gcc</command> and produce
+native Win32 programs that do not rely on any third-party DLLs. The
+current set of tools include GNU Compiler Collection (<command>gcc</command>), GNU Binary
+Utilities (Binutils), GNU debugger (Gdb), GNU make, and a assorted
+other utilities. 
+</para>
+<para>The GHC that we distribute includes, inside the distribution itself, the MinGW <command>gcc</command>,
+<command>as</command>, <command>ld</command>, and a bunch of input/output libraries.  
+GHC compiles Haskell to C (or to 
+assembly code), and then invokes these MinGW tools to generate an executable binary.
+The resulting binaries can run on any Win32 system.
+</para>
+<para> We will call a GHC that targets MinGW in this way <emphasis>GHC-mingw</emphasis>.</para>
+
+<para> The down-side of GHC-mingw is that the MinGW libraries do not support anything like the full
+Posix interface.  So programs compiled with GHC-mingw cannot import the (Haskell) Posix 
+library; they have to do
+their input output using standard Haskell I/O libraries, or native Win32 bindings.
+</para>
+</sect3>
+
+<sect3 id="ghc-cygwin"><title>GHC-cygwin</title>
+
+<para>There <emphasis>is</emphasis> a way to get the full Posix interface, which is to use Cygwin.  
+<ulink url="http://www.cygwin.com">Cygwin</ulink> is a complete Unix simulation that runs on Win32.
+Cygwin comes with a shell, and all the usual Unix commands: <command>mv</command>, <command>rm</command>,
+<command>ls</command>, plus of course <command>gcc</command>, <command>ld</command> and so on.
+A C program compiled with the Cygwin <command>gcc</command> certainly can use all of Posix.
+</para>
+<para>So why doesn't GHC use the Cygwin <command>gcc</command> and libraries?  Because
+Cygwin comes with a DLL <emphasis>that must be linked with every runnable Cygwin-compiled program</emphasis>.
+A program compiled by the Cygwin tools cannot run at all unless Cygwin is installed. 
+If GHC targeted Cygwin, users would have to install Cygwin just to run the Haskell programs
+that GHC compiled; and the Cygwin DLL would have to be in the DLL load path.
+Worse, Cygwin is a moving target.  The name of the main DLL, <literal>cygwin1.dll</literal>
+does not change, but the implementation certainly does.  Even the interfaces to functions
+it exports seem to change occasionally. So programs compiled by GHC might only run with
+particular versions of Cygwin.  All of this seems very undesirable.
+</para>
+<para>
+Nevertheless, it is certainly possible to build a version of GHC that targets Cygwin;
+we will call that <emphasis>GHC-cygwin</emphasis>.  The up-side of GHC-cygwin is
+that Haskell programs compiled by GHC-cygwin can import the (Haskell) Posix library.
+</para>
+</sect3>
+
+<sect3><title>Summary</title>
+
+<para>Notice that "GHC-mingw" means "GHC that <emphasis>targets</emphasis> MinGW".  It says nothing about 
+how that GHC was <emphasis>built</emphasis>.  It is entirely possible to have a GHC-mingw that was built
+by compiling GHC's Haskell sources with a GHC-cygwin, or vice versa.</para>
+
+<para>We distribute only a GHC-mingw built by a GHC-mingw; supporting
+GHC-cygwin too is beyond our resources.  The GHC we distribute
+therefore does not require Cygwin to run, nor do the programs it
+compiles require Cygwin.</para>
+
+<para>The instructions that follow describe how to build GHC-mingw. It is
+possible to build GHC-cygwin, but it's not a supported route, and the build system might
+be flaky.</para>
+</sect3>
+</sect2>
+
+<Sect2><Title>Installing and configuring Cygwin</Title>
+
+<para>You don't need Cygwin to <emphasis>use</emphasis> GHC, 
+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.
 
+</para>
+<para> Now set the following user environment variables:
 <itemizedlist>
+
+<listitem><para> Add <filename>c:/cygwin/bin</filename> and <filename>c:/cygwin/usr/bin</filename> to your 
+<constant>PATH</constant></para></listitem>
+
 <listitem>
 <para>
-Make sure that the user environment variable
-<constant>MAKE_MODE</constant> is set to <literal>UNIX</literal>. If you
+Set <constant>MAKE_MODE</constant> to <Literal>UNIX</Literal>. If you
 don't do this you get very weird messages when you type
-<command>make</command>, such as:
+<Command>make</Command>, such as:
 <Screen>
 /c: /c: No such file or directory
 </Screen>
 </para>
 </listitem>
 
+<listitem><para> Set <constant>SHELL</constant> to
+<Filename>c:/cygwin/bin/sh</Filename>. When you invoke a shell in Emacs, this
+<constant>SHELL</constant> is what you get.
+</para></listitem>
+
+<listitem><para> Set <constant>HOME</constant> to point to your 
+home directory.  This is where, for example,
+<command>bash</command> will look for your <filename>.bashrc</filename>
+file.  Ditto <command>emacs</command> looking for <filename>.emacsrc</filename>
+</para></listitem>
+</itemizedlist>
+</para>
+
+<para>
+There are a few other things to do:
+<itemizedlist>
+<listitem>
+<para>
+Some script files used in the make system start with "<Command>#!/bin/perl</Command>",
+(and similarly for <Command>bash</Command>).  Notice the hardwired path!
+So you need to ensure that your <Filename>/bin</Filename> directory has the following
+binaries in it:
+<itemizedlist>
+<listitem> <para><Command>sh</Command></para></listitem>
+<listitem> <para><Command>perl</Command></para></listitem>
+<listitem> <para><Command>cat</Command></para></listitem>
+</itemizedlist>
+All these come in Cygwin's <Filename>bin</Filename> directory, which you probably have
+installed as <Filename>c:/cygwin/bin</Filename>.  By default Cygwin mounts "<Filename>/</Filename>" as
+<Filename>c:/cygwin</Filename>, so if you just take the defaults it'll all work ok.
+(You can discover where your Cygwin
+root directory <Filename>/</Filename> is by typing <Command>mount</Command>).
+Provided <Filename>/bin</Filename> points to the Cygwin <Filename>bin</Filename>
+directory, there's no need to copy anything.
+</para>
+</listitem>
+
+<listitem>
+<para>
+By default, cygwin provides the command shell <filename>ash</filename>
+as <filename>sh.exe</filename>. It has a couple of 'issues', so
+in your <filename>/bin</filename> directory, make sure that <filename>
+bash.exe</filename> is also provided as <filename>sh.exe</filename>
+(i.e. overwrite the old <filename>sh.exe</filename> with a copy of
+<filename>bash.exe</filename>).
+</para>
+</listitem>
+</itemizedlist>
+</para>
+
+<para>Finally, here are some things to be aware of when using Cygwin:
+<itemizedlist>
+<listitem> <para>Cygwin doesn't deal well with filenames that include
+spaces. "<filename>Program Files</filename>" and "<filename>Local files</filename>" are
+common gotchas.
+</para></listitem>
+
+<listitem> <para> Cygwin implements a symbolic link as a text file with some
+magical text in it.  So other programs that don't use Cygwin's
+I/O libraries won't recognise such files as symlinks.  
+In particular, programs compiled by GHC are meant to be runnable
+without having Cygwin, so they don't use the Cygwin library, so
+they don't recognise symlinks.
+</para></listitem>
+
+<listitem> <para>
+Win32 has a <command>find</command> command which is not the same as Cygwin's find.
+You will probably discover that the Win32 <command>find</command> appears in your <constant>PATH</constant>
+before the Cygwin one, because it's in the <emphasis>system</emphasis> <constant>PATH</constant> 
+environment variable, whereas you have probably modified the <emphasis>user</emphasis> <constant>PATH</constant> 
+variable.  You can always invoke <command>find</command> with an absolute path, or rename it.
+</para></listitem>
+</itemizedlist>
+</para>
+
+</Sect2>
+
+<Sect2><Title>Other things you need to install</Title>
+
+<para>You have to install the following other things to build GHC:
+<itemizedlist>
+<listitem>
+<para>
+Install an executable GHC, from <ulink url="http://www.haskell.org/ghc">http://www.haskell.org/ghc</ulink>.
+This is what you will use to compile GHC.  Add it in your
+<constant>PATH</constant>: the installer tells you the path element
+you need to add upon completion.
+</para>
+</listitem>
+
+<listitem>
+<para>
+Install an executable Happy, from <ulink url="http://www.haskell.org/happy">http://www.haskell.org/happy</ulink>.
+Happy is a parser generator used to compile the Haskell grammar.  Add it in your
+<constant>PATH</constant>.
+</para>
+</listitem>
+
+
 <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
@@ -3743,15 +3939,87 @@ We install it in <filename>c:/mingw</filename>.
 </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>
+</listitem>
+</itemizedlist>
+</para>
+</sect2>
+
+<Sect2><Title>Building GHC</Title>
+
+<para>OK!  
+Now go read the documentation above on building from source (<xref linkend="sec-building-from-source">); 
+the bullets below only tell
+you about Windows-specific wrinkles.</para>
+<ItemizedList>
+<listitem>
+<para>
+Run <Command>autoconf</Command> both in <filename>fptools</filename>
+and in <filename>fptools/ghc</filename>.  If you omit the latter step you'll
+get an error when you run <filename>./configure</filename>:
+<Screen>
+...lots of stuff...
+creating mk/config.h
+mk/config.h is unchanged
+configuring in ghc
+running /bin/sh ./configure  --cache-file=.././config.cache --srcdir=.
+./configure: ./configure: No such file or directory
+configure: error: ./configure failed for ghc
+</Screen>
+</para>
+</listitem>
+
+<listitem> <para><command>autoconf</command> seems to create the file <filename>configure</filename>
+read-only.  So if you need to run autoconf again (which I sometimes do for safety's sake),
+you get
+<screen>
+/usr/bin/autoconf: cannot create configure: permission denied
+</screen>
+Solution: delete <filename>configure</filename> first.
+</para></listitem>
+
 <listitem>
 <para>
-Install a version of GHC, and put it in your
-<constant>PATH</constant> (the installer tells you the path element
-you need to add upon completion.)
+You either need to add <filename>ghc</filename> to your
+<constant>PATH</constant> before you invoke
+<Command>configure</Command>, or use the <Command>configure</Command>
+option <option>--with-ghc=c:/ghc/ghc-some-version/bin/ghc</option>.
 </para>
 </listitem>
-      </itemizedlist>
-    </sect2>
+
+<listitem>
+  <para> 
+    After <command>autoconf</command> run <command>./configure</command> in
+    <filename>fptools/</filename> thus:
+
+<Screen>
+  ./configure --host=i386-unknown-mingw32 --with-gcc=/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>
+
+<para>
+If you want to build GHC-cygwin (<xref linkend="ghc-cygwin">)
+you'll have to do something more like:
+<Screen>
+  ./configure --with-gcc=...the Cygwin gcc...
+</Screen>
+</para>
+</listitem>
+
+<listitem><para> Do not attempt to build the documentation.
+It needs all kinds of wierd Jade stuff that we haven't worked out for
+Win32.</para></listitem>
+</ItemizedList>
+</Sect2>
+
 
 </sect1>