= Pidgin for Windows Build Instructions =

Note: These instructions are kept current for the development version of 2.x.y branch of Pidgin. You may need to look at an older version of this page in order to build an older version of Pidgin. Alternatively, you may need the instructions for 3.0.0 branch.
||[wiki:BuildingWinPidgin/3.0.0 3.0.0]||2.x.y (current)||[wiki:BuildingWinPidgin?version=161 2.10.11]||[wiki:BuildingWinPidgin?version=147 2.10.7]||[wiki:BuildingWinPidgin?version=135 2.10.6]||[wiki:BuildingWinPidgin/Pre2.7.0 <2.7.0]||

== Set up your build environment ==

{{{
#!comment
=== The easy way === 
'''Note''': Currently out of date! Use [#Themanualway the manual instructions].

  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, '''ca-certificates''', coreutils,  gawk, '''gnupg''', grep, gzip, '''libiconv''', '''make''', '''patch''', sed, tar, '''unzip''', '''wget''', and '''zip''' (several of these are selected by default, those in bold are not). Be sure to add Cygwin versions of any programs you may use that require Cygwin path names (for example, if you want to use vim to edit monotone commit messages, you need to install the Cygwin version of vim -- native Win32 vim will be unable to read Cygwin-style paths). [[BR]]
     You may prefer to use [http://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.11/MSYS-1.0.11.exe/download MSYS] instead of Cygwin.

  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 Pidgin's source code distribution; you will be prompted to choose which version you'd like to use.[[BR]]
     Note that this script is occasionally out of date, especially immediately following releases, in which case you will need to perform some of the manual steps in addition.  The ChangeLog may clue you into which dependencies have changed.

  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.
     Also make sure you install bash, bzip2, '''ca-certificates''', coreutils, gawk, '''gnupg''', grep, gzip, '''libiconv''', '''make''', '''patch''', sed, tar, '''unzip''', '''wget''', and '''zip''' (several of these are selected by default, those in bold are not).[[BR]]
     You may prefer to use [http://sourceforge.net/projects/mingw/files/MSYS%20Base%20System/msys-1.0.11/MSYS-1.0.11.exe/download MSYS] instead of Cygwin, but if you do so, you may need to tweak the instructions. Alternatively, if you wish, there is a ''third-party'' [https://launchpad.net/pidgin-windev automation script for MSYS] which should cover most of the steps described here.

  2. The following instructions were written under the assumption that [#GetthePidginsourcecode the Pidgin source] will be extracted or checked out into `$PIDGIN_DEV_ROOT/pidgin-<version>` 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).
     Some users may find the [#CustomizingtheBuildEnvironment instructions for customizing their build environment] useful.

  You don't have to actually define an environment variable called `PIDGIN_DEV_ROOT`, it is simply used here as a placeholder.

  ** Note: You should avoid using a `$PIDGIN_DEV_ROOT` path that contains spaces as that can cause unnecessary complications.

  People are sometimes confused about the directory structure, so here is an example structure after all the dependencies have been installed (`$PIDGIN_DEV_ROOT` is `c:\devel\pidgin-devel` in this example):
{{{
c:\devel\pidgin-devel
(The following is the source tree root, containing config.h.mingw and libpurple.)
c:\devel\pidgin-devel\pidgin-<version>
c:\devel\pidgin-devel\win32-dev
(If the following file is present, your structure is probably correct.)
c:\devel\pidgin-devel\win32-dev\gtk_2_0-2.14\include\libintl.h
}}}

  3. Install the MinGW "GCC Version 4.7.2" packages from the [http://www.mingw.org MinGW site] by following [http://www.mingw.org/node/24/revisions/908/view their instructions].
  * Download the following:
   * [http://sourceforge.net/projects/mingw/files/MinGW/Base/binutils/binutils-2.23.1/binutils-2.23.1-1-mingw32-bin.tar.lzma/download binutils-2.23.1]
   * mingw-runtime-3.20 ([http://sourceforge.net/projects/mingw/files/MinGW/Base/mingw-rt/mingwrt-3.20/mingwrt-3.20-2-mingw32-dev.tar.lzma/download dev] and [http://sourceforge.net/projects/mingw/files/MinGW/Base/mingw-rt/mingwrt-3.20/mingwrt-3.20-2-mingw32-dll.tar.lzma/download dll])
   * [http://sourceforge.net/projects/mingw/files/MinGW/Base/w32api/w32api-3.17/w32api-3.17-2-mingw32-dev.tar.lzma/ w32api-3.17]
   * Required runtime libraries for GCC:
    * mpc-0.8.1-1 ([http://sourceforge.net/projects/mingw/files/MinGW/Base/mpc/mpc-0.8.1-1/mpc-0.8.1-1-mingw32-dev.tar.lzma/ dev] and [http://sourceforge.net/projects/mingw/files/MinGW/Base/mpc/mpc-0.8.1-1/libmpc-0.8.1-1-mingw32-dll-2.tar.lzma/ dll])
    * mpfr-2.4.1-1 ([http://sourceforge.net/projects/mingw/files/MinGW/Base/mpfr/mpfr-2.4.1-1/mpfr-2.4.1-1-mingw32-dev.tar.lzma/ dev] and [http://sourceforge.net/projects/mingw/files/MinGW/Base/mpfr/mpfr-2.4.1-1/libmpfr-2.4.1-1-mingw32-dll-1.tar.lzma/ dll])
    * gmp-5.0.1-1 ([http://sourceforge.net/projects/mingw/files/MinGW/Base/gmp/gmp-5.0.1-1/gmp-5.0.1-1-mingw32-dev.tar.lzma/ dev] and [http://sourceforge.net/projects/mingw/files/MinGW/Base/gmp/gmp-5.0.1-1/libgmp-5.0.1-1-mingw32-dll-10.tar.lzma/ dll])
    * pthreads-2.9.0-pre-20110507-2 ([http://sourceforge.net/projects/mingw/files/MinGW/Base/pthreads-w32/pthreads-w32-2.9.0-pre-20110507-2/pthreads-w32-2.9.0-mingw32-pre-20110507-2-dev.tar.lzma/ dev] and [http://sourceforge.net/projects/mingw/files/MinGW/Base/pthreads-w32/pthreads-w32-2.9.0-pre-20110507-2/libpthreadgc-2.9.0-mingw32-pre-20110507-2-dll-2.tar.lzma/ dll])
    * iconv ([http://sourceforge.net/projects/mingw/files/MinGW/Base/libiconv/libiconv-1.14-2/libiconv-1.14-2-mingw32-dev.tar.lzma/ dev] and [http://sourceforge.net/projects/mingw/files/MinGW/Base/libiconv/libiconv-1.14-2/libiconv-1.14-2-mingw32-dll-2.tar.lzma/ dll])
    * [http://sourceforge.net/projects/mingw/files/MinGW/Base/gettext/gettext-0.18.1.1-2/libintl-0.18.1.1-2-mingw32-dll-8.tar.lzma/ intl-0.18.1.1-2]
    * [http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/gcc-4.7.2-1/libgomp-4.7.2-1-mingw32-dll-1.tar.lzma/ gomp-4.7.2-1]
    * [http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/gcc-4.7.2-1/libssp-4.7.2-1-mingw32-dll-0.tar.lzma/ ssp-4.7.2-1]
    * [http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/gcc-4.7.2-1/libquadmath-4.7.2-1-mingw32-dll-0.tar.lzma/ quadmath-4.7.2-1]
   * gcc-core-4.7.2-1 ([http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/gcc-4.7.2-1/gcc-core-4.7.2-1-mingw32-bin.tar.lzma/ bin] and dev and [http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/gcc-4.7.2-1/libgcc-4.7.2-1-mingw32-dll-1.tar.lzma/ dll])
   * [http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/gcc-4.7.2-1/gcc-4.7.2-1-mingw32-src.tar.lzma/download gcc-4.7.2-1-mingw32-src]
    * so we can distribute the libssp source since we distribute the binary
  * Extract all of the above into the desired location (e.g. `$PIDGIN_DEV_ROOT/win32-dev/mingw-4.7.2`)
   * Prepare a `libssp-src.tar.gz` file containing the libssp sources and licenses:
{{{
#!sh
  cd $PIDGIN_DEV_ROOT/win32-dev/mingw-4.7.2
  mkdir libsspsrctmp
  tar -C libsspsrctmp -xf gcc-4.7.2-1-mingw32-src/gcc-4.7.2.tar.bz2 gcc-4.7.2/COPYING3 gcc-4.7.2/COPYING.RUNTIME gcc-4.7.2/libssp --strip-components=1
  tar -C libsspsrctmp -czf bin/libssp-src.tar.gz .
  rm -r libsspsrctmp
}}}

  * Set the MinGW gcc's bin directory to be before Cygwin's in your `PATH`.[[BR]]
   For Example (You should add the following to your `~/.bashrc` file, which is found in `C:\cygwin\home\YourUsername\` by default):
{{{
#!sh
  export PATH=/cygdrive/c/devel/pidgin-devel/win32-dev/mingw-4.7.2/bin:$PATH
}}}


== Install Pidgin's build dependencies ==

=== GTK+ ===
  Pidgin depends on GTK+ 2.14.7 (newer runtime versions can be used).
  The GTK+ All-in-one bundle contains all of GTK+'s dependencies in one zip file.
  Download [http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.14/gtk+-bundle_2.14.7-20090119_win32.zip gtk+-bundle_2.14.7-20090119_win32.zip] and extract to `$PIDGIN_DEV_ROOT/win32-dev/gtk_2_0-2.14` (you'll need to create this directory).[[BR]]
  Visit the [http://www.gtk.org/download-windows.html GTK+ website] for official binary and source releases.

=== gettext ===
  You'll need gettext to compile translations. Download [http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-tools-0.17.zip gettext-tools-0.17.zip] and [http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime-0.17-1.zip gettext-runtime-0.17-1.zip]. Extract both to `$PIDGIN_DEV_ROOT/win32-dev/gettext-0.17` (you'll need to create this directory).

=== Libxml2 ===
  Download and extract [/static/win32/libxml2-2.9.2_daa1.tar.gz libxml2-2.9.2_daa1.tar.gz] to `$PIDGIN_DEV_ROOT/win32-dev`

=== Perl 5.20 ===
  You'll need a functioning perl 5.20.x runtime (if the perl executable isn't in your `PATH`, you will need to override the `PERL` variable in `pidgin/local.mak` to point to the appropriate perl executable). A good option is [http://strawberryperl.com/ Strawberry Perl].

  Download the [/static/win32/perl-5.20.1.1.tar.gz perl-5.20.1.1.tar.gz] development package and extract to `$PIDGIN_DEV_ROOT/win32-dev` (it creates its own directory).  This is a subset of the full 32-bit strawberry perl zip containing just the headers, import lib, and source for perl.

  * Note: If using MSYS and you installed the `mingw-developer-toolkit`, keep in mind that it installs `msys-perl-bin` (Perl 5.6) which takes precedence over the newer perl in your path, and that will cause problems!  The easiest solution is to set the `PERL` variable in your `pidgin/local.mak` to point to the right perl.exe.

=== !GtkSpell ===
    * Download and extract [/static/win32/gtkspell-2.0.16.tar.bz2 gtkspell-2.0.16.tar.bz2] to `$PIDGIN_DEV_ROOT/win32-dev`

=== Enchant ===
    * Download and extract [/static/win32/enchant_1.6.0_win32.zip enchant_1.6.0_win32.zip] to `$PIDGIN_DEV_ROOT/win32-dev/`

=== Mozilla NSS ===
  * Download and extract [/static/win32/nss-3.17.3-nspr-4.10.7.tar.gz nss-3.17.3-nspr-4.10.7.tar.gz] under `$PIDGIN_DEV_ROOT/win32-dev`
    * Note: NSS/NSPR are built from the upstream sources using [wiki:BuildingWinNSS these instructions].

=== SILC Toolkit ===
  Download and extract [/static/win32/silc-toolkit-1.1.12.tar.gz silc-toolkit-1.1.12.tar.gz] to `$PIDGIN_DEV_ROOT/win32-dev`
  
=== Meanwhile ===
  Download and extract [/static/win32/meanwhile-1.0.2_daa3-win32.zip meanwhile-1.0.2_daa3-win32.zip] to `$PIDGIN_DEV_ROOT/win32-dev`

=== Cyrus SASL ===
  Download and extract [/static/win32/cyrus-sasl-2.1.26_daa1.tar.gz cyrus-sasl-2.1.26_daa1.tar.gz] to `$PIDGIN_DEV_ROOT/win32-dev`

=== Intltool ===
  Download and extract [http://ftp.acc.umu.se/pub/GNOME/binaries/win32/intltool/0.40/intltool_0.40.4-1_win32.zip intltool_0.40.4-1_win32.zip] to `$PIDGIN_DEV_ROOT/win32-dev/intltool_0.40.4-1_win32`

=== Crash Reporting Library ===
  Download and extract [/static/win32/pidgin-inst-deps-20130214.tar.gz pidgin-inst-deps-20130214.tar.gz] to `$PIDGIN_DEV_ROOT/win32-dev`.

== Get the Pidgin source code ==
  The source for Pidgin 2.10.11 is available [http://prdownloads.sourceforge.net/pidgin/pidgin-2.10.11.tar.bz2 here] (use the latest release if this isn't updated yet).[[BR]][[BR]]
  The development source is available via mercurial. See [wiki:UsingPidginMercurial] for more information.

== Build Pidgin ==

  Run the following:
{{{
#!sh
cd $PIDGIN_DEV_ROOT/pidgin-<version>
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-<version>/win32-install-dir`.

== Build the Pidgin Installer ==

  * If you want to build the Pidgin installer, do the following:
    * Download and install [http://nsis.sourceforge.net/Download NSIS]. Include NSIS to Cygwin's `PATH`.
     *  For information on the NSIS installer, visit the [http://nsis.sourceforge.net NSIS website].[[BR]]
    * Download the [http://nsis.sourceforge.net/Nsisunz_plug-in nsisunz plugin], and extract `nsisunz.dll` into the `Plugins` directory of your NSIS installation.
    * Copy `$PIDGIN_DEV_ROOT/win32-dev/pidgin-inst-deps-20130214/SHA1Plugin.dll` into the `Plugins` directory of your NSIS installation.
    * Now you'll need to decide if you want to sign the executables (not necessary for personal use)
     * If you do, you'll need to get an appropriate code signing certificate, generate a GPG key if you don't already have one, then download and install [http://www.mono-project.com/Download Mono]. In your `local.mak` file (see [wiki:"BuildingWinPidgin#CustomizingtheBuildEnvironment" below]), define the `MONO_SIGNCODE` variable to the fully qualified path to the `signcode` batch file in the Mono `bin` directory, and the `SIGNCODE_SPC` and `SIGNCODE_PVK` variables to the appropriate files from your certificate. E.g.:
{{{
MONO_SIGNCODE=/cygdrive/c/Program\ Files\ \(x86\)/Mono-2.10.8/bin/signcode
SIGNCODE_SPC=c:\\Path\\to\\authenticode.spc
SIGNCODE_PVK=c:\\Path\\to\\authenticode.pvk
#Set up gpg to use a separate keyring
GPG_SIGN=gpg --no-default-keyring --secret-keyring /path/to/secring.gpg
}}}
     * Otherwise, in your `local.mak` file (see [wiki:"BuildingWinPidgin#CustomizingtheBuildEnvironment" below]),add the following:
{{{
#Disable Signing
MONO_SIGNCODE=echo ***Bypassing signcode***
GPG_SIGN=echo ***Bypassing gpg***
}}}
  * Now you can actually build the installer.[[BR]]
    There are 2 different installers, an "Offline" installer that includes all dependencies (except spellchecking dictionaries) and the debug symbols and an "Online" installer that includes only Pidgin itself and will download the various dependencies if necessary.
    The `Makefile.mingw` targets for these are `installer_offline`, and `installer` respectively.  To build both, use the `installers` target.
{{{
#!sh
cd $PIDGIN_DEV_ROOT/pidgin-<version>
make -f Makefile.mingw installers
}}}
    When it finishes, your installer(s) should be in `$PIDGIN_DEV_ROOT/pidgin-<version>/`.

== Customizing the Build Environment ==
  Most people will find that the standard build environment directory is completely adequate.
  It is, however, possible to override the locations of the various dependencies and target directories.
  This is often useful to test against a development version of a library dependency or to override compiler flags.

  This done is by overriding the various Makefile variables in a `local.mak` file in the `$PIDGIN_DEV_ROOT/pidgin-<version>` directory.
  This file does not exist by default.

  Most of the variables that can be overridden with this method are defined in the [http://hg.pidgin.im/pidgin/main/file/default/libpurple/win32/global.mak libpurple/win32/global.mak] file.
  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:
{{{
 #Override the install location
 PIDGIN_INSTALL_DIR = /cygdrive/c/Program\ Files/Pidgin
 PURPLE_INSTALL_DIR = /cygdrive/c/Program\ Files/Pidgin
}}}

  One nice use of the `local.mak` file is for cross compiling, there is an additional example in the [#CrossCompiling section below]. 

== 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 3.

  Create a `local.mak` file in the source directory root to override the Makefile variables - mine looks like this:
{{{
SHELL := /bin/bash
CC := /usr/bin/i586-mingw32msvc-cc
GMSGFMT := msgfmt
MAKENSIS := /usr/bin/makensis
WINDRES := /usr/bin/i586-mingw32msvc-windres
STRIP := /usr/bin/i586-mingw32msvc-strip
INTLTOOL_MERGE := /usr/bin/intltool-merge

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.

      NSIS version 2.46 or greater is required to cross-compile.  If compiling NSIS from source, the [http://www.scons.org/ scons] package is a dependency.  This can usually be installed through your linux distribution's package archive.  An example of how to install the NSIS package is given below (Assuming use of the NSIS 2.46 version):

      `.tar.bz2` file contains latest source[[BR]]
      `.zip` file contains libraries
{{{
#!sh
mkdir nsis; cd nsis
wget http://prdownloads.sourceforge.net/nsis/nsis-2.46-src.tar.bz2?download 
wget http://prdownloads.sourceforge.net/nsis/nsis-2.46.zip?download
tar -jxvf nsis-2.46-src.tar.bz2
cd nsis-2.46
scons SKIPSTUBS=all SKIPPLUGINS=all SKIPUTILS=all SKIPMISC=all NSIS_CONFIG_CONST_DATA_PATH=no
sudo scons install-compiler
cd ..
sudo unzip nsis-2.46 -d /usr/local/share
sudo mv /usr/local/share/nsis-2.46/ /usr/local/share/nsis 
}}}
      If following the above instructions, the local.mak file ([#CrossCompiling listed above]) should be modified[[BR]]
{{{
MAKENSIS := /usr/local/bin/makensis
}}}


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