HOW TO BUILD GMP 6.0.0 for 32-bit or 64-bit Windows

INSTRUCTIONS FOR EXTERNAL USERS WHO WANT TO BUILD THEIR OWN GMP
LIBRARIES ON MICROSOFT WINDOWS.

(This file should appear at the top level of the ZIP file
redistributed to interested users.  That ZIP file should contain
the Build subdirectory [Windows and Windows-x86-64 subdirectories
only plus common-Windows-build.sh], and the Source subdirectory.)

This version of GMP is built using the MINGW32 or 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]

If you are building GMP for 32-bit Windows, skip to step (5)

(3) Download MINGW64 from   http://tdm-gcc.tdragon.net/
    If you have done this previously, skip to step (5).

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

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

(5) Start a command prompt.

(6) Are you building a GMP purely to put into the Wolfram Language
    kernel, or do you want a library you can link to your own Windows
    programs using Visual Studio?

    If you want to be able to link it to your own Visual C++ programs, then
    you need a .LIB file.  There's a bug in MINGW that generates bad .LIB
    files (they don't work with the Microsoft linker), so you must have
    Microsoft Visual Studio installed to run its own .LIB file generator.

    If you merely want a new DLL to use in Mathematica (Wolfram Language),
    you don't need a .LIB file that works with Visual Studio.  Edit the file
    "build.sh" to change
        use_microsoft_LIB=true
    to
        use_microsoft_LIB=false
    and skip to step (8).

(7) Run the batch file which puts the Microsoft compiler tools on your PATH.
    This is typically called "vcvars32.bat" for 32-bit or "vcvars64.bat" for
    64-bit, and is located in a subdirectory of your Visual Studio installation.
    (C:\Program Files\Microsoft Visual Studio 10\VC\bin\vcvars32.bat, or
     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, necessary for a
    64-bit build, give the following command to the MSYS bash shell:

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

(10) Within the MSYS bash shell window, navigate to the place you installed
     the GMP bundle from Wolfram Research, then navigate to the subdirectory
        Build/Windows/mingw          (for 32-bit GMP)
        Build/Windows-x86-64/mingw   (for 64-bit GMP)
     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 FAT (i.e. multiple-CPUs) dynamic library of GMP.  It first
    copies the 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.  If
    requested (see step 6), it constructs the DLL's import library using
    Microsoft LIB.EXE and the DLL's .DEF file.  Then it copies the resulting
    files to the output directory Windows/mingw or Windows-x86-64/mingw.

(12) Replace the libgmp-10.dll file in the subdirectory of your Mathematica/
     Wolfram Language installation
         SystemFiles/Kernel/Binaries/Windows/libgmp-10.dll         (32-bit)
      or SystemFiles/Kernel/Binaries/Windows-x86-64/libgmp-10.dll  (64-bit)
