## 6.2 Acquiring the Required Packages

Package Directory

We will install all our packages in a new directory we create especially for them. Say this directory is `/opt/packages`. Whatever it is, we will refer to it as packages throughout this document. Furthermore, we populate the packages directory with the following subdirectories:

Directory | Purpose
--- | ---
`dlls` | For the Dynamically Linked Libraries (DLLs).
`include` | For the packages' C/C++ header files (`.h`).
`lib` | For the libraries (`.a`).

Furthermore, we create a separate directory for the builds, for example, `/tmp/build`. We will refer to this as build.

Required Packages

The following table lists the packages we need, along with their versions and the place where they can be downloaded.

Package | Version | Location
--- | --- | ---
GNU MP | 4.1.4 | `ftp://ftp.gnu.org/pub/gnu/gmp/gmp-4.1.4.tar.gz`
zlib | 1.2.3 | `http://www.gzip.org/zlib-1.2.3.tar.gz`
Tcl/Tk | 8.4.12.0 | `http://aspn.activestate.com/ASPN/Downloads/ActiveTcl/`
GDBM | 1.8.3 | `ftp://ftp.gnu.org/pub/gnu/gdbm/gdbm-1.8.3.tar.gz`
regex | 0.12 | `ftp://ftp.gnu.org/pub/gnu/regex/regex-0.12.tar.gz`

Note that these are all source packages except for Tcl/Tk. You'll soon find out why.

Build Flags

The remainder of this chapter will use CFLAGS to indicate a meaningful set of flags for the C/C++ compilers. For instance, you can use the following, which we used for the last releases:

> `-mno-cygwin -O3 -fomit-frame-pointer -march=i586 -mcpu=i686`

It is imperative that you include `-mno-cygwin`!

A Note for the Lazy

There's some good news: If you are lazy enough that you would trust the packages I built, you can just obtain a copy of my packages directory from `http://www.mozart-oz.org/download/mozart-ftp/extras/packages.tgz` and skip most of the following sections (in fact, all but those about the msvcrt and Emacs). Be sure to adapt the included `tclConfig.sh` and `tkConfig.sh` files to reflect your system's paths!

### 6.2.1 Microsoft Visual C++ Runtime

This one is easy: You already have it! It is located in `$SYSTEMROOT/system32/` (at least under Windows 2000; if you're running 9x, then you'll have to locate it yourself). So we just copy it to our packages`/dlls` directory:

> `cp $SYSTEMROOT/system32/msvcrt.dll` packages`/dlls`

### 6.2.2 GNU MP

Unpack it, configure it, build it, and install it thus:

> `cd` build`
> tar zxvf gmp-4.1.2.tar.gz
> cd gmp-4.1.2
> ./configure --prefix=`packages`--disable-shared CFLAGS="`CFLAGS`"
> make
> make install`

You should end up with the following files:

packages`/include/gmp.h`
packages`/lib/libgmp.a`

### 6.2.3 zlib

Unpack it, configure it, build it, and install it thus:

> `cd` build`
> tar zxvf zlib.tar.gz
> cd zlib-1.1.4
> CFLAGS="`CFLAGS`" ./configure --prefix=`packages`
> make
> make install`

You should end up with the following files:

packages`/include/zlib.h`
packages`/include/zconf.h`
packages`/lib/libz.a`

### 6.2.4 Tcl/Tk

Install your Tcl/Tk distribution (for example, ActiveTcl). Copy the following files and directories from the installed location:

packages`/include/tcl.h`
packages`/include/tclDecls.h`
packages`/include/tclPlatDecls.h`
packages`/include/tk.h`
packages`/include/tkDecls.h`
packages`/include/tkIntXlibDecls.h`
packages`/include/tkPlatDecls.h`
packages`/include/X11/*`
packages`/lib/tk8.4/*`
packages`/lib/tcl8.4/*`
packages`/dlls/tcl84.dll`
packages`/dlls/tclpip84.dll`
packages`/dlls/tk84.dll`

Unfortunately, Windows Tcl/Tk distributions come without the all-important `tclConfig.sh` and `tkConfig.sh` files, which we therefore have to create manually (directly in the packages directory). `tclConfig.sh` should have the following contents:

> `# tclConfig.sh --
> TCL_VERSION='8.4'
> TCL_PREFIX='`packages`'
> TCL_LIBS=''
> TCL_LIB_SPEC='`packages`/dlls/tcl84.dll'`

Whereas `tkConfig.sh` ought to look like this:

> `# tkConfig.sh --
> TK_VERSION='8.4'
> TK_PREFIX='`packages`'
> TK_LIBS=''
> TK_LIB_SPEC='`packages`/dlls/tk84.dll'
> TK_XINCLUDES=''`

(Don't forget to substitute your actual packages directory for packages in these files!)

### 6.2.5 GDBM

Unpack it thus:

> `cd` packages`
> tar zxvf gdbm-1.8.3.tar.gz
> cd gdbm-1.8.3`

GDBM does not compile out-of-the-box for MinGW, so we have to apply a patch. Copy the file gdbm-1.8.3-patch.diff, then patch it, configure it, build it, and install it thus:

> `patch < gdbm-1.8.3-patch.diff
> CFLAGS="`CFLAGS`" ./configure --disable-shared
> make CFLAGS="`CFLAGS`"
> make prefix=`packages `install`

You should end up with the following files:

packages`/include/gdbm.h`
packages`/lib/libgdbm.a`

### 6.2.6 regex

Unpack it thus:

> `cd` packages`
> tar zxvf regex-0.12.tar.gz
> cd regex-0.12`

Like GDBM, the regex package needs a patch regex-0.12-patch.diff. Patch the package, configure it, build it, and install it thus:

> `patch < regex-0.12-patch.diff
> CFLAGS="`CFLAGS`" ./configure --prefix=`packages`
> make CFLAGS="`CFLAGS`"
> make prefix=`packages `install`

You should end up with the following files:

packages`/include/regex.h`
packages`/lib/libregex.a`

### 6.2.7 Emacs

You need an installed Emacs. You can get it at `http://www.gnu.org/software/emacs/windows/`. Unpack it somewhere, for example to `/cygdrive/c/Program\ Files/` and execute the `addpm.exe` binary in the `bin` subdirectory. We will refer to the directory where Emacs is installed as emacs.

You really need to use the Emacs version you have installed in your Windows system. If you have Emacs installed along with cygwin, you have to change your PATH to build Mozart in order to find first the Emacs that it's installed for Windows. Be aware that the `configure` script is not going to check whether you have Emacs installed in your system, but it will be necessary to build, so install it NOW!