HOW TO BUILD GMP 6.0.0 for 64-bit Windows

This version of GMP is built using the MINGW64 compiler (i.e. GCC,
producing executables linked to the Microsoft C run-time library
MSVCRT.DLL), and the MSYS simple Unix-like build environment.

(1) First we must install the 32-bit MinGW32 system.
    If you have already done this previously, skip to step (3).

    Go to http://www.mingw.org
    Under "About" in the left-hand margin, click on "Downloads".
    Click on the link near the top of the page which reads:
      "Looking for the latest version?  Download mingw-get-inst-...."
    (The version I used was mingw-get-inst-20120426.exe)
    This downloads a "setup" program.

(2) Run the mingw-get "setup" program you downloaded.
     (A) Choose "Download latest repository catalogues"
     (B) Click "Accept" the agreement.
     (C) Install to C:\MinGW   (this is the default)
           You can choose a different directory, but from here on
           I will describe what to do in terms of C:\MinGW

     (D) Choose the following components to install from the menu:
         * C Compiler
         * C++ Compiler
         * MinGW Developer Toolkit (Includes MSYS Basic System)

      Click Install and let it finish.  This will take a while.

     [Note: to UNINSTALL: (i)  Run C:\MinGW\unins000.exe,
                          (ii) Remove the directory C:\MinGW by hand]

(3) Download MINGW64 from   http://tdm-gcc.tdragon.net/
    If you have done this previously, skip to step (5).
     Choose the basic "bundle installer"
     Choose the MinGW-w64 / sjlj version

(4) Install MINGW into the directory  C:\MinGW64

    Note: We will tell MinGW32 about MinGW64 below in step (9).

(5) CVS checkout the following directories:
     cvs checkout Components/GMP/6.0.0/Build
     cvs checkout Components/GMP/6.0.0/Source
     cvs checkout Components/GMP/6.0.0/Windows-x86-64
    (the last one may not exist yet)

(6) Start a command prompt.

(7) Run the batch file which puts the Microsoft compiler tools on your PATH.
    This is typically called "vcvars64.bat" or "vcvarsall.bat"
    and it is located in a subdirectory of your Visual Studio installation.
    (C:\Program Files\Microsoft Visual Studio 10\VC\bin\amd64\vcvars64.bat)
    Check that it worked by seeing if entering "LIB" gives you the Microsoft
    Library Manager.

(8) Start MSYS by running C:\MinGW\msys\1.0\msys.bat.
    Since you are doing this in the same command prompt as step (7),
    shell scripts will have access to the Microsoft LIB.EXE tool.

(9) To tell MinGW32 to use the tools in C:\MinGW64, give the following
    command to the MSYS bash shell:

       export PATH=/c/MinGW64/bin:$PATH

(10) Within the MSYS bash shell window, navigate to:
        Components/GMP/6.0.0/Build/Windows-x86-64/mingw
     This may require starting with:   cd /c/  or cd /d/  (drive letters)

Now you can build.  What happens from here on out must be done every time
you rebuild GMP.

(11) Run
      ./build.sh

    This builds a 64-bit FAT (i.e. multiple-CPUs) dynamic library of GMP.
    It first copies the Components/GMP/6.0.0/Source tree to a local directory,
    converts all the Windows newlines in source files to Unix newlines
    (unfortunately MSYS is incapable of working with native Windows text files),
    and then runs the build.  It constructs the DLL's import library using
    Microsoft LIB.EXE and the DLL's .DEF file.  Then it copies all the resulting
    files to the output directory Components/GMP/6.0.0/Windows-x86-64/mingw

(12) Go to the output directory   Components/GMP/6.0.0/Windows-x86-64/mingw
     and commit the files that are there.

     You should see the following:

        libgmp-10.dll     (the GMP DLL)
        libgmp-10.lib     (the import library)

        config.h
        fac_table.h
        fat.h
        fib_table.h
        gmp.h
        gmp-impl.h
        gmp-mparam.h
        gmpxx.h
        longlong.h
        mp_bases.h
        trialdivtab.h

    Remember!  Binary files that end in .DLL and .LIB must be added to the
    repository using the "cvs add -kb" command, not the "cvs add" command!

    The GMP DLL should also end up in the Mathematica layout, so it can be
    found when the kernel is run.  That is,
        $TopDirectory/SystemFiles/Kernel/Binaries/Windows-x86-64

(13) In the kernel project file, add this directory to the includes path:
        Components/GMP/6.0.0/Windows-x86-64/mingw
     and put the "libgmp-10.lib" file in the Libraries > Win64 filter
     in the Solution Explorer (64-bit configurations only).
