Changes between Version 3 and Version 4 of Building/Platforms/Windows


Ignore:
Timestamp:
Nov 18, 2011 10:12:31 AM (2 years ago)
Author:
dterei
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Building/Platforms/Windows

    v3 v4  
    1  
    2  
    31= Windows platforms: Cygwin, MSYS, and MinGW = 
    42 
    5 The build system is built around Unix-y makefiles.  Because it's not native, 
    6 the Windows situation for building GHC is particularly confusing.  This section 
    7 tries to clarify, and to establish terminology. 
     3The build system is built around UNIX Makefiles. Because it's not native, the Windows situation for building GHC is a little confusing. This section tries to outline the situation for building GHC on Windows. 
    84 
    9 See also [http://hackage.haskell.org/trac/ghc/wiki/Building/Preparation/Windows Preparation]. 
     5If you are already familiar with using UNIX build tools on Windows and simply want to build GHC the jump to [http://hackage.haskell.org/trac/ghc/wiki/Building/Preparation/Windows build preparation]. 
    106 
    117== MinGW == 
    128 
    13 [http://www.mingw.org MinGW (Minimalist GNU for Windows)]  
    14 is a collection of header 
    15 files and import libraries that allow one to use {{{gcc}}} and produce 
    16 native Win32 programs that do not rely on any third-party DLLs. The 
    17 current set of tools include GNU Compiler Collection ({{{gcc}}}), GNU Binary 
    18 Utilities (Binutils), GNU debugger (Gdb), GNU make, and assorted 
    19 other utilities.  
     9[http://www.mingw.org MinGW (Minimalist GNU for Windows)] is a native port of {{{GCC}}} to windows such that it can be used to compile and produce native windows programs that have no reliance on third party DLLs. The tools distributed include the GNU Compiler Collection ({{{GCC}}}), GNU Binary Utilities ({{{Binutils}}}), GNU Debuger ({{{GDB}}}) and some other utilities. 
    2010 
    21 GHC requires both the MinGW "core system" (a C compiler + other essential stuff) 
    22 and the g++ system (required by libffi) to be installed.  
    23  
    24 The down-side of MinGW is that the MinGW libraries do not support anything like the full 
    25 Posix interface.   
     11MinGW doesn't provide a UNIX shell environment though so by itself can't be used to build GHC as we rely on GNU Make, a UNIX Shell and the standard UNIX utilities. 
    2612 
    2713== Cygwin and MSYS == 
    2814 
    29 You can't use the MinGW to ''build'' GHC, because MinGW doesn't have a shell, 
    30 or the standard Unix commands such as {{{mv}}}, {{{rm}}}, 
    31 {{{ls}}}, nor build-system stuff such as {{{make}}} and {{{darcs}}}. 
    32 For that, there are two choices: [http://www.cygwin.com Cygwin]  
    33 and [http://www.mingw.org/msys.shtml MSYS]: 
    34  * Cygwin comes with compilation tools ({{{gcc}}}, {{{ld}}} and so on), which 
    35    compile code that has access to all of Posix.  The price is that the executables must be  
    36    dynamically linked with the Cygwin DLL, so that ''you cannot run a Cywin-compiled program on a machine 
    37    that doesn't have Cygwin''.  Worse, Cygwin is a moving target.  The name of the main DLL, {{{cygwin1.dll}}} 
    38    does not change, but the implementation certainly does.  Even the interfaces to functions 
    39    it exports seem to change occasionally.  
    40    [[br]] 
    41  * MSYS is a fork of the Cygwin tree, so they 
    42    are fundamentally similar.  However, MSYS is by design much smaller and simpler.  
    43    Access to the file system goes 
    44    through fewer layers, so MSYS is quite a bit faster too. 
    45    [[br]] 
    46    Furthermore, MSYS provides no compilation tools; it relies instead on the MinGW tools. These 
    47    compile binaries that run with no DLL support, on any Win32 system. 
    48    However, MSYS does come with all the make-system tools, such as {{{make}}}, {{{autoconf}}},  
    49    {{{darcs}}}, {{{ssh}}} etc.  To get these, you have to download the  
    50    MsysDTK (Developer Tool Kit) package, as well as the base MSYS package. 
    51    [[br]] 
    52    MSYS does have a DLL, but it's only used by MSYS commands ({{{sh}}}, {{{rm}}},  
    53    {{{ssh}}} and so on), 
    54    not by programs compiled under MSYS. 
     15As you can't use MinGW to "build" GHC since it doesn't provide a shell or GNU Make, another additional project will be needed. For that there are two choices: 
    5516 
    56 == Targeting MinGW == 
     17* [http://www.mingw.org/wiki/MSYS MSYS] MSYS provides a bare bones UNIX like environment, including GNU Bash, GNU Make, GNU Autoconf, SSH and GNU Coretuils. Its enough so that in combination with MinGW you can build native windows tools using the GNU build chain and utilities. MSYS is managed by the MinGW project. 
     18 
     19* [http://www.cygwin.com Cygwin] aims to provide a POSIX API and environment on windows. The price is that executables built against Cygwin must be dynamically linked with the Cygwin DLL. It is also a little more of an abstracted (from Windows) environment to work in. Cygwin does provide far more of a UNIX like environment than MSYS does though, even offering X Windows for example. 
     20 
     21== GHC Targets MinGW == 
    5722 
    5823We want GHC to compile programs that work on any Win32 system.  Hence: 
    59  * GHC does invoke a C compiler, assembler, linker and so on, but we ensure that it only 
    60    invokes the MinGW tools, not the Cygwin ones.  That means that the programs GHC compiles 
    61    will work on any system, but it also means that the programs GHC compiles do not have access 
    62    to all of Posix.  In particular, they cannot import the (Haskell) Posix  
    63    library; they have to do 
    64    their input output using standard Haskell I/O libraries, or native Win32 bindings. 
    65    We will call a GHC that targets MinGW in this way ''GHC-mingw''. 
    66  * To make the GHC distribution self-contained, the GHC distribution includes the MinGW {{{gcc}}}, 
    67    {{{as}}}, {{{ld}}}, and a bunch of input/output libraries.   
    6824 
    69 So ''GHC targets MinGW'', not Cygwin. 
    70 It is in principle possible to build a version of GHC, ''GHC-cygwin'',  
    71 that targets Cygwin instead.  The up-side of GHC-cygwin is 
    72 that Haskell programs compiled by GHC-cygwin can import the (Haskell) Posix library. 
    73 ''We do not support GHC-cygwin, however; it is beyond our resources.'' 
     25 * GHC does invoke a C compiler, assembler, linker and so on, but we ensure that it only invokes the MinGW tools, not the Cygwin ones. That means that the programs GHC compiles will work on any system, but it also means that the programs GHC compiles do not have access to all of Posix.  In particular, they cannot import the (Haskell) POSIX library; they have to do their input output using standard Haskell I/O libraries, or native Win32 bindings. We will call a GHC that targets MinGW in this way ''GHC-mingw''. 
    7426 
     27 * To make the GHC distribution self-contained, the GHC distribution includes the MinGW {{{gcc}}}, {{{as}}}, {{{ld}}}, and a bunch of input/output libraries.   
    7528 
    76 While GHC ''targets'' MinGW, that says nothing about  
    77 how GHC is ''built''.  We use both MSYS and Cygwin as build environments for 
    78 GHC; both work fine, though MSYS is rather lighter weight. 
     29So ''GHC targets MinGW'', not Cygwin. It is in principle possible to build a version of GHC, ''GHC-cygwin'',  that targets Cygwin instead.  The up-side of GHC-cygwin is that Haskell programs compiled by GHC-cygwin can import the (Haskell) Posix library. ''We do not support GHC-cygwin, however; it is beyond our resources.'' 
    7930 
    80 In your build tree, the compiler you build uses the {{{gcc}}} that you specify using the 
    81 {{{--with-gcc}}} flag when you run {{{configure}}} (see below). 
    82 The makefiles are careful to use the right gcc, either via the in-place ghc or directly, 
    83 to compile any C files, so that we use correct {{{gcc}}} rather than 
    84 whatever one happens to be in your path.  However, the makefiles do use whatever {{{ld}}}  
    85 and {{{ar}}} happen to be in your path. This is a bit naughty, but (a) they are only 
    86 used to glom together .o files into a bigger .o file, or a .a file,  
    87 so they don't ever get libraries (which would be bogus; they might be the wrong libraries), and (b) 
    88 Cygwin and MinGW use the same .o file format.  So its ok. 
     31While GHC ''targets'' MinGW, that says nothing about how GHC is ''built''.  We use both MSYS and Cygwin as build environments for GHC; both work fine, though MSYS is rather lighter weight. 
     32 
     33In your build tree, the compiler you build uses the {{{gcc}}} that you specify using the {{{--with-gcc}}} flag when you run {{{configure}}} (see below). The makefiles are careful to use the right gcc, either via the in-place ghc or directly, to compile any C files, so that we use correct {{{gcc}}} rather than whatever one happens to be in your path.  However, the makefiles do use whatever {{{ld}}} and {{{ar}}} happen to be in your path. This is a bit naughty, but (a) they are only used to pull together .o files into a bigger .o file, or a .a file, so they don't ever get libraries (which would be bogus; they might be the wrong libraries), and (b) Cygwin and MinGW use the same .o file format.  So its ok. 
    8934 
    9035== File names == 
    9136 
    92 Cygwin, MSYS, and the underlying Windows file system all understand file paths of form {{{c:/tmp/foo}}}. 
    93 However: 
    94  * MSYS programs understand {{{/bin}}}, {{{/usr/bin}}}, and map Windows's lettered drives as 
    95    {{{/c/tmp/foo}}} etc.  The exact mount table is given in the doc subdirectory of the MSYS distribution. 
     37Cygwin, MSYS, and the underlying Windows file system all understand file paths of form {{{c:/tmp/foo}}}. However: 
     38  
     39* MSYS programs understand {{{/bin}}}, {{{/usr/bin}}}, and map Windows's lettered drives as {{{/c/tmp/foo}}} etc.  The exact mount table is given in the doc subdirectory of the MSYS distribution. 
    9640   [[br]] 
    97    When it invokes a command, the MSYS shell sees whether the invoked binary lives in the MSYS {{{/bin}}} 
    98    directory.  If so, it just invokes it.  If not, it assumes the program is no an MSYS program, and walks over the command-line 
    99    arguments changing MSYS paths into native-compatible paths. 
    100    It does this inside sub-arguments and inside quotes. For example, 
    101    if you invoke 
     41   When it invokes a command, the MSYS shell sees whether the invoked binary lives in the MSYS {{{/bin}}} directory.  If so, it just invokes it.  If not, it assumes the program is no an MSYS program, and walks over the command-line arguments changing MSYS paths into native-compatible paths. It does this inside sub-arguments and inside quotes. For example, if you invoke 
    10242   {{{ 
    10343foogle -B/c/tmp/baz