= Pidgin for Windows Build Instructions =

== Set up your build environment ==

=== The easy way === 
('''not yet available''')

  1. Install the [http://cygwin.com Cygwin] Bash shell. Make sure to select Unix file mode during setup.
     Also make sure you install bash, bzip2, coreutils, gawk, grep, gzip, make, patch, sed, monotone, tar, unzip, and wget (several of these are selected by default).[[BR]]
     You may prefer to use the native Windows monotone binary available [http://www.monotone.ca here].

  2. Download the [http://gaim-extprefs.sourceforge.net/bef.shtml Build Environment Fetcher] script. Follow the instructions on the website to fetch and install most of the needed build dependencies. The script can fetch Gaim's source code from either Subversion or a source distribution; you will be prompted to choose which you'd like to use.[[BR]]
     Note that this script is sometimes out of date, in which case you will need to perform some of the manual steps in addition.

  3. Skip the [#Themanualway The manual way], [#InstallPidginsbuilddependencies Install Pidgin's build dependencies], and [#GetthePidginsourcecode Get the Pidgin source code] sections and go straight to [#BuildPidgin Build Pidgin].

=== The manual way ===

  1. Install the [http://cygwin.com Cygwin] Bash shell.
     Make sure you install bash, bzip2, coreutils, gawk, grep, gzip, make, patch, sed, monotone, tar, unzip, and wget (several of these are selected by default).[[BR]]
     You may prefer to use the native Windows monotone binary available [http://www.monotone.ca here].

  2. Install the MinGW "current" packages from the [http://www.mingw.org MinGW site].[[BR]]
     The easiest way to install these is to use the MinGW Installer linked to from the main site.[[BR]]
     Specifically, you will need `gcc-core 3.4.2`, `binutils 2.15.91`, `mingw-runtime 3.9` and `win32api 3.9` (or newer). Note that a bug with the MinGW site causes win32api 3.9 to not appear. You'll need to grab it from their [http://sourceforge.net/project/showfiles.php?group_id=2435 Sourceforge page].[[BR]]
     You will need to set MinGW's bin directory before Cygwin's in your PATH.[[BR]]
     For Example (You can add the following to your `~/.bashrc` file (create the file if it doesn't exist yet)):
{{{
  export PATH=/cygdrive/c/MinGW/bin:$PATH
}}}
     You do not want to use any of Cygwin's build tools, with one exception; you need to use Cygwin's make utility. If typing `which make` produces MinGW's make utility, then just rename the `make.exe` in the MinGW bin directory to something else so that cygwin's make utility will be used instead. This shouldn't be a problem with recent versions of MinGW.

  3. The following instructions were written under the assumption that you checkout Pidgin from monotone to `$PIDGIN_DEV_ROOT/pidgin` and that you install all of Pidgin's build dependencies under `$PIDGIN_DEV_ROOT/win32-dev` (the point being that the pidgin source root and `win32-dev` directories should be on the same level). It is not required to actually define `$PIDGIN_DEV_ROOT`, it is simply mentioned here to show which parts of the process are up to your personal choice.[[BR]][[BR]]
     ** Note: You should avoid using a `$PIDGIN_DEV_ROOT` path that contains spaces as that can cause unnecessary complications.[[BR]][[BR]]
     The location of win32-dev and it's contents can be changed by creating a `local.mak` file in the `$PIDGIN_DEV_ROOT/pidgin` directory and overriding the various Makefile variables. While this is not necessary, it allows you the freedom to install dependencies wherever you please. The variables that can be overridden with this method are listed in the source archive in [/viewmtn/revision/file/8c0ef1cb63204eeb0e5cda5501300c62d11bf89e/libpurple/win32/global.mak libpurple/win32/global.mak]. For example, to install Pidgin over `C:\Program Files\Pidgin` instead of `$PIDGIN_DEV_ROOT/pidgin/win32-install-dir`, create a `$PIDGIN_DEV_ROOT/pidgin/local.mak` containing:
{{{
 PIDGIN_INSTALL_DIR = /cygdrive/c/Program\ Files/Pidgin
 PURPLE_INSTALL_DIR = /cygdrive/c/Program\ Files/Pidgin
}}}
     People are sometimes confused about the directory structure, so here is an example that will build without any local.mak overrides (`$PIDGIN_DEV_ROOT` is `c:/development/pidgin_dev` in this example):
{{{
C:\development\pidgin_dev
(The following is the source tree root, containing config.h.mingw and libpurple.)
C:\development\pidgin_dev\pidgin
C:\development\pidgin_dev\win32-dev
(If the following file is present, your structure is probably correct.)
C:\development\pidgin_dev\win32-dev\gtk_2_0\include\libintl.h
}}}

== Install Pidgin's build dependencies ==

=== GTK+ ===

  Pidgin depends on GTK+ 2.6.10 (newer runtime versions can be used, but building against newer headers will prevent Win98/ME compatibility).
  For your convenience, we have included all of GTK's dependencies in one tarball.
  Extract [http://prdownloads.sourceforge.net/pidgin/gtk-dev-2.6.10-rev-a.tar.gz?download gtk-dev-2.6.10-rev-a.tar.gz] within `$PIDGIN_DEV_ROOT/win32-dev`.[[BR]]
  If you wish to run Pidgin from the `win32-install-dir` directory once it is built, you will need to make sure that you have installed the GTK+ runtime, and make sure that its bin dir is in your PATH.[[BR]]
  Visit the [http://www.gtk.org GTK+ website] for official binary and source releases.

=== Libxml2 ===
  Download and extract [/static/win32/libxml2-2.6.24.tar.gz libxml2-2.6.24.tar.gz] to `win32-dev`.

=== Perl 5.8 ===
  Install Perl 5.8 for Windows (I use [http://www.activestate.com/Products/ActivePerl/ ActivePerl]), to `C:\Perl`.
  If you install Perl anywhere else, you will need to override the `PERL` and `EXTUTILS` variables in your `pidgin/local.mak` file.
  You will also need to install [/static/win32/perl582.tar.gz perl582.tar.gz] under `$PIDGIN_DEV_ROOT/win32-dev` (Containing headers and import lib for mingw gcc).

=== Tcl 8.4.5 ===
  Download and extract [/static/win32/tcl-8.4.5.tar.gz tcl-8.4.5.tar.gz] to `win32-dev`

=== !GtkSpell / Aspell ===
  * Download the following development packages for !GtkSpell and Aspell, and extract them under `win32-dev`:
    * [http://ftp.gnu.org/gnu/aspell/w32/aspell-dev-0-50-3-3.zip aspell-dev-0-50-3-3.zip]
    * [/static/win32/gtkspell-2.0.6.tar.gz gtkspell-2.0.6.tar.gz]

=== Mozilla NSS ===
  * Download and unzip the following under `$PIDGIN_DEV_ROOT/win32-dev`:
    * [ftp://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/NSS_3_11_4_RTM/msvc6.0/WIN954.0_OPT.OBJ/nss-3.11.4.zip Network Security Services (NSS)]
    * [ftp://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v4.6.4/msvc6.0/WIN954.0_OPT.OBJ/nspr-4.6.4.zip Netscape Portable Runtime (NSPR)]

=== SILC Toolkit ===
  Download and extract [/static/win32/silc-toolkit-1.0.2.tar.gz silc-toolkit-1.0.2.tar.gz] to `win32-dev`.
  
=== Meanwhile ===
  Download and extract [http://prdownloads.sourceforge.net/meanwhile/meanwhile-1.0.2-win32.zip?download meanwhile-1.0.2-win32.zip] to `win32-dev`.

== Get the Pidgin source code ==
  The source for Pidgin 2.0.0 is available [http://prdownloads.sourceforge.net/pidgin/pidgin-2.0.0.tar.bz2 here].[[BR]]
  The development source is available via monotone. See [wiki:UsingPidginMonotone] for more information.

== Build Pidgin ==
  Run the following:
{{{
$ cd $PIDGIN_DEV_ROOT/pidgin
$ make -f Makefile.mingw install
}}}
  Now just wait and let your compiler do its thing.  When finished, Pidgin will be in `$PIDGIN_DEV_ROOT/pidgin/win32-install-dir`.

== Build the Pidgin Installer ==

  * If you want to build the Pidgin installer, do the following (skip to the `make` command below if you chose to use the Build Environment Fetcher):
    * Download and install [http://nsis.sourceforge.net/Download NSIS]. Include NSIS to your PATH.
      For information on the NSIS installer, visit the [http://nsis.sourceforge.net NSIS website].
    * Download [http://prdownloads.sourceforge.net/pidgin/gtk-2.10.11-rev-b-installer.tar.gz?download gtk-2.10.11-rev-b-installer.tar.gz]
      and extract it to `$PIDGIN_DEV_ROOT/`. From within the new `gtk_installer directory`, run `. build.sh` (this builds the GTK+ runtime installer, which the Pidgin installer will include).
    * Download [/static/win32/pidgin-inst-deps.tar.gz pidgin-inst-deps.tar.gz] and extract under `$PIDGIN_DEV_ROOT/win32-dev`.
  * Now you can actually build the installer.[[BR]]
    There are 3 different installers: "Normal" (with GTK+), "No GTK+" and "Debug".
    The Makefile targets for these are `installer`, `installer_nogtk`, and `installer_debug` respectively.  To build all 3, use the `installers` target.
{{{
$ cd $PIDGIN_DEV_ROOT/pidgin
$ make -f Makefile.mingw installers
}}}

== Debugging ==
  There is a quite good '''Just In Time''' debugger for MinGW: [http://jrfonseca.planetaclix.pt/projects/gnu-win32/software/drmingw/index.html drmingw].
  You can download it [/static/win32/drmingw.exe here].[[BR]]
  There is also a version of `gdb` available from MinGW, if you prefer.

== Cross Compiling ==
  It is quite easy to cross compile Pidgin for Windows on a Linux machine.

  To begin, you'll need to install MinGW. On Debian/Ubuntu, this involves installing packages `mingw32`, `mingw32-binutils`, and `mingw32-runtime`. On other distributions, the packages may be named differently.

  Set up a build environment as described [#Themanualway above], skipping steps 1 and 2.

  Create a `local.mak` file in the source directory root to override the Makefile variables - mine looks like this:
{{{
CC := /usr/bin/i586-mingw32msvc-cc
GMSGFMT := msgfmt
MAKENSIS := /usr/bin/makensis
PERL := /usr/bin/perl
EXTUTILS := /usr/share/perl/5.8/ExtUtils
WINDRES := /usr/bin/i586-mingw32msvc-windres
STRIP := /usr/bin/i586-mingw32msvc-strip

INCLUDE_PATHS := -I$(PIDGIN_TREE_TOP)/../win32-dev/w32api/include
LIB_PATHS := -L$(PIDGIN_TREE_TOP)/../win32-dev/w32api/lib
}}}

  If your distribution doesn't include a recent enough win32api, you can download it from the [http://www.mingw.org/ MinGW site], extract it into your `win32-dev` directory, and override the `INCLUDE_PATHS` and `LIB_PATHS` variables in your `local.mak` as I have done.

  Once this is set up, you should be able to follow the [#BuildPidgin building instructions above].

  ** Note: I haven't been able to get the NSIS installer to build correctly on my 64-bit Linux system.

