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


Here are the instructions on how to build GMP.dll for GMP 5.0.5 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 2010 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 2010, 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-5.0.5.zip file into a directory.  This
   includes the unmodified sources for GMP 5.0.5 in a subdirectory (gmp-5.0.5).

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

* Increasing lt_cv_sys_max_cmd_len.
* The maximum command-line length that configure sets for Cygwin is too short.
*
* Edit "configure".  Find the line:
*     lt_cv_sys_max_cmd_len=8192;
* which is beneath the line reading:
*   cygwin* | mingw*)
* and replace the 8192 with 65536

* Edit "gmp-h.in" to define __GMP_EXTERN_INLINE correctly
* Find:
*   #ifdef _MSC_VER
*   #define __GMP_EXTERN_INLINE  __inline
* rewrite the second line to:
*   #define __GMP_EXTERN_INLINE  static __forceinline

* In MSVC, __declspec() is a storage class and cannot be used to modify a
* field in a struct.  The cpuvec_t struct in gmp-impl.h tries to declare
* its fields using a macro that includes GMP_DECLSPEC (which is __declspec).
* So you must edit "gmp-impl.h" to temporarily undefine GMP_DECLSPEC.
* Find:
*    struct cpuvec_t { ..... }
* Before the declaration of struct cpuvec_t, add the lines:

#if defined (_MSC_VER) && defined(__GMP_DECLSPEC)
#define __GMP_DECLSPEC_WAS_DEFINED
#pragma push_macro("__GMP_DECLSPEC")
#undef __GMP_DECLSPEC
#define __GMP_DECLSPEC
#endif

* Immediately after the declaration of struct cpuvec_t, add the lines:

#if defined (_MSC_VER) && defined(__GMP_DECLSPEC_WAS_DEFINED)
#pragma pop_macro("__GMP_DECLSPEC")
#undef __GMP_DECLSPEC_WAS_DEFINED


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

6. Run "C:\Program Files\Microsoft Visual Studio 9.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 15.00.30729.01 for 80x86

7. Start Cygwin.  (Be sure to run it in a Command Prompt with Administrator
   privileges, otherwise you may get "access denied" or even "file not found"
   errors.)  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-5.0.5.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-5.0.5/.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 2012 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/.


