INSTRUCTIONS ON HOW I BUILD GMP 4.2.1 FOR 32-BIT WINDOWS
USING VISUAL C++ 2005, CYGWIN, AND A LOT OF HACKY SCRIPTS


Here are the instructions on how to build GMP.dll for GMP 4.2.1 just like I do.
They are quite hacky.  This is because I want to:
(1) Use the Unix-based configure/make (autoconf) system provided with GMP to
    script the build.  It is very complex and does a lot of code generation
    for you, especially if you build a fat binary.
(2) Have the actual compilation done using Visual C 2005 compiler and linker.

As a result, I have written shell scripts which "wrap" Microsoft CL and LINK to
make them look like Unix-style cc and ld.  Also I have to hack up the configure
script so it doesn't make too many unwarranted assumptions, and rewrite some
erroneous bits in the GMP sources.

If you don't want to do all this but still want to build your own GMP, I'm
told that MPIR (www.mpir.com) works fine as a drop-in replacement, and it's
a lot easier to build.


(1) Download legacy Cygwin 1.5 (www.cygwin.com).  Version 1.7 doesn't work.

    Download the executable:  http://www.cygwin.com/setup-legacy.exe
    Run setup-legacy.exe
    Select "Default Text Format:  DOS"  (not Unix - this is important)
    When it asks you what you want to install, choose (at least):
        Base > ALL packages
        Devel > binutils, gcc, flex, make, mktmp
        Interpreters > m4
        Shells > sh-utils
        Utils > cygutils, file
    (It might be easier to choose "all" if you don't mind the bloat.)

2. Install Visual Studio 2005, so you can run the CL compiler and LINK linker.
   I believe you can get this for free from Microsoft; look for "Visual Studio
   Express".

   I have not tried later versions of Visual Studio, but I believe VS2010 works.

3. Unzip the Wolfram-Windows32-GMP-4.2.1.zip file into a directory.  This
   includes the unmodified sources for GMP 4.2.1 in a subdirectory (gmp-4.2.1).

4. Make the following modifications to the GMP sources and scripts.

* Removing references to mpn_add_nc and mpn_sub_nc from mpn/generic/addsub_n.c
* The "fat binary" version of GMP doesn't export functions mpn_add_nc and
* mpn_sub_nc.  Unfortunately the file addsub_n.c uses them by default.  Edit
* gmp-4.2.1/mpn/generic/addsub_n.c to change all lines of the form:
*   #if HAVE_NATIVE_mpn_add_nc || !HAVE_NATIVE_mpn_add_n
*   #if HAVE_NATIVE_mpn_sub_nc || !HAVE_NATIVE_mpn_sub_n
* to remove everything from the || onwards, giving:
*   #if HAVE_NATIVE_mpn_add_nc
*   #if HAVE_NATIVE_mpn_sub_nc
* For CPU-specific libraries, this is not necessary -- just the "fat" version.

5. Start a Command Prompt.  (Start menu > Run > cmd)

6. Run "C:\Program Files\Microsoft Visual Studio 8.0\VC\bin\vsvars32.bat"
   This gives you command-line access to CL and LINK.  Test this by typing
   CL
   to the command prompt and seeing if it runs and displays:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

7. Start Cygwin.  Chances are this will be by running C:\Cygwin\Cygwin.bat
   This will give you a bash shell prompt.  Be sure that CL still works
   (repeat the test in step 6, just to be sure).

8. cd into the current directory, the one with this README in it.  (If you
   unzipped the Wolfram-Windows32-GMP-4.2.1.zip file into C:\wolfram\gmp, you
   could get there in Cygwin by doing "cd /cygdrive/c/wolfram/gmp".)

9. To run an optimized build for all x86 architectures, a "fat binary", run:
        ../wri-build-gmp -O2 fat

   THIS IS THE VERSION THAT IS USED IN MATHEMATICA FOR 32-BIT WINDOWS



    To run an optimized build for core2, run

        ../wri-build-gmp -O2 core2

    To run a debug build for i486, run

        ../wri-build-gmp -g i486

    Other possibilities are:
      none - 100% C, no assembly.  When all else fails.
      pentium, pentiummmx, pentiumpro, pentium2, pentium3, k6, k62, k63,
          athlon, pentium4 - some specific CPUs.  Not a complete list.  Poke
          around in "configure" to see what else is available, if you care.
      <leave it blank> - configure will detect your CPU automagically.

         If you want to do the build in stages, rather than using the master
         "wri-build-gmp" script, you can use some sub-scripts:
           1. wri-config - Performs just the configure, not the make.
           2. make clean - Must always be run between config and make.
           3. wri-make [or wri-make -g] - Performs full GMP make [w/ debugging]

10. When the build has succeeded, there should be a GMP.dll file in the
    gmp-4.2.1/.libs subdirectory.  Copy that into your Mathematica layout,
    in the SystemFiles/Kernel/Binaries/Windows subdirectory (from the
    directory given by evaluating $InstallationDirectory in Mathematica).
    There will already by a GMP.dll there; you may want to rename it to
    something else before you go copying the new one over it.



- David Librik, Kernel Technology Department, Wolfram Research Inc.

CONTACT INFORMATION:  E-mail to support@wolfram.com





LGPL boilerplate:

Copyright 2010 Wolfram Research, Inc.

This file is part of the build scripts for building the GNU MP Library
for Mathematica on Windows (32-bit).

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see http://www.gnu.org/licenses/.


