# Building the clnum Package on Windows

Frank Palazzolo
palazzol@comcast.net
12-August-2006

This is the process for building clnum on Windows, using the mingw/MSYS compile environment, and the standard Python distutils system.

This process has several steps:

1. Downloading the required files

2. Setting up the mingw/MSYS compile environment

3. Building gmp-4.2.1

4. Building cln-1.1.13

5. Building clnum, and the binary installer

## Step 1 - Downloading the required files:

These instructions are for downloading the exact versions of the files that I did. (Future versions may work as well.)

These directions assume that you download the mingw.org files to:

c:\mingw_downloads

and the rest to:

c:\clnum_build

From http://www.mingw.org/ (from the "Current" distribution):

GCC section:
gcc-core-3.4.2-20040916-1.tar.gz
gcc-g++-3.4.2-20040916-1.tar.gz

MSYS section:
MSYS-1.0.10.exe

MinGW Runtime:
mingw-runtime-3.9.tar.gz

Windows API:
w32api-3.6.tar.gz

binutils:
binutils-2.15.91-20040904-1.tar.gz

From http://www.swox.com/gmp/
gmp-4.2.1.tar.gz

From http://www.ginac.de/CLN/
cln-1.1.13.tar.bz2

From http://sourceforge.net/projects/calcrpnpy/
clnum-1.3.tar.gz

## Step 2 - Setting up the mingw/MSYS compile environment

The easiest way to do this from scratch is to install MSYS first, just to get tar, gzip, and bzip2 on your system. Usually, it is better to install MSYS after mingw, since MSYS wants to know where your mingw is. In this case, we will just install it twice.

Install MSYS-1.0.10.exe

During the post-install questions, answer that you do not have a mingw install yet.

Now, you can launch the MSYS shell:

Program Files->Mingw->MSYS

From within the MSYS shell, we will unpack the mingw compiler:
(We will put mingw into c:/mingw)
cd /c/
mkdir mingw
cd mingw
(Unpack the C compiler core)
tar zxvf /c/mingw_downloads/gcc-core-3.4.2-20040916-1.tar.gz
(Unpack the C++ compiler)
tar zxvf /c/mingw_downloads/gcc-g++-3.4.2-20040916-1.tar.gz
(Unpack the runtime)
tar zxvf /c/mingw_downloads/mingw-runtime-3.9.tar.gz
(Unpack winapi)
tar zxvf /c/mingw_downloads/w32api-3.6.tar.gz
(Unpack utilities)
tar zxvf /c/mingw_downloads/binutils-2.15.91-20040904-1.tar.gz

Close the shell, and install MSYS-1.0.10.exe again. This time give c:\mingw as your mingw path.

## Step 3 - Building gmp-4.2.1

From within the MSYS shell, we will unpack and build GMP:

    cd /c/clnum_build
    tar zxvf gmp-4.2.1.tar.gz
    cd gmp-4.2.1
    ./configure
    make
    make check
    make install

GMP should build correctly with the default settings. All tests during "make check" should pass. The "make install" puts files in the MSYS /usr/local/include and /usr/local/lib directories.

## Step 4 - Building cln-1.1.13

From within the MSYS shell, we will unpack and build CLN:

Build CLN with these settings, per the manual, enabling gmp.

    cd /c/clnum_build
    bunzip2 cln-1.1.13.tar.bz2
    tar xvf cln-1.1.13.tar
    cd cln-1.1.13

And finally, configure and build:

(Now, all on one long line:)

    CC="gcc" CFLAGS="-O" CXX="g++" CXXFLAGS="-O -fno-exceptions -finline-limit=1000" \
    CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" \
    ./configure --with-gmp

Note: compiling with -O2 fails during "make check", so I reverted to -O. If you check config.log, you should see that gmp.h was found and that gmp will be used for the build.

    make
    make check
    make install

As with gmp, all checks should pass and the install puts things in MSYS's /usr/local/.

Before we leave the MSYS shell, we should uncompress clnum, since we'll need it for the next step

    cd /c/clnum_build
    tar zxvf clnum-1.3.tar.gz

## Step 5 - Building clnum, and the Binary Installer

Now, we are building clnum at the command prompt, (not in MSYS!), using Python distutils.

First, we set up the command prompt to paths
(To find the mingw compiler)
set PATH=c:\mingw\bin;%PATH%
(To find the cln include files - this is /usr/local/include, assuming MSYS is installed in the default place)
set CPLUS_INCLUDE_PATH=c:\msys\1.0\local\include
(To find the cln library file - this is /usr/local/lib, assuming MSYS is installed in the default place)
set LIBRARY_PATH=c:\msys\1.0\local\lib

Now, we assume Python 2.4 is installed and in the path (Mine was Python2.4.3)

    cd c:\clnum_build\clnum-1.3
    python setup.py build --compiler=mingw32 bdist_wininst -o

(You can replace python with c:\python24\python or whatever, if python is not in your path.) This should build and link clnum, and build a binary installer.

Now go into the dist subdirectory, to find the binary installer. Run this to install clnum into your python environment.

    cd dist
    clnum-1.3.win32-py2.4.exe

You can run the test scripts to verify functionality:

    cd c:\clnum_build\clnum-1.3\test
    test_clnum.py

If all tests pass, congratulations - you're done!