
== Building using MinGW ==

**Note:** This section might be outdated as nowadays Visual C++ is use to build
the "official" packages.

**Note:** For a detailed account of building all the dependencies yourself you
can visit Marco Pasetti's website here:

http://www.webalice.it/marco.pasetti/qgis+grass/BuildFromSource.html

Read on to use the simplified approach with pre-built libraries...

=== MSYS ===

MSYS provides a unix style build environment under windows. We have created a
zip archive that contains just about all dependencies.

Get this: 

http://download.osgeo.org/qgis/win32/msys.zip

and unpack to c:\msys


If you wish to prepare your msys environment yourself rather than using 
our pre-made one, detailed instructions are provided elsewhere in this
document.

=== Qt ===

Download Qt opensource precompiled edition exe and install (including the
download and install of mingw) from here:

http://qt.nokia.com/downloads/

When the installer will ask for MinGW, you don't need to download and install
it, just point the installer to c:\msys\mingw

When Qt installation is complete:

Edit C:\Qt\4.8.0\bin\qtvars.bat and add the following lines:

``` 
set PATH=%PATH%;C:\msys\local\bin;c:\msys\local\lib 
set PATH=%PATH%;"C:\Program Files\Subversion\bin" 
```

I suggest you also add C:\Qt\4.8.0\bin\ to your Environment Variables Path in
the windows system preferences.

If you plan to do some debugging, you'll need to compile debug version of Qt:
C:\Qt\4.8.0\bin\qtvars.bat compile_debug

Note: there is a problem when compiling debug version of Qt 4.7, the script ends with
this message  "mingw32-make: *** No rule to make target `debug'.  Stop.". To 
compile the debug version you have to go out of src directory and execute the
following command:

``` 
c:\Qt\4.8.0 make 
```

=== Flex and Bison ===

Get Flex
http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=16424
(the zip bin) and extract it into c:\msys\mingw\bin

=== Python stuff (optional) ===

Follow this section in case you would like to use Python bindings for QGIS.  To
be able to compile bindings, you need to compile SIP and PyQt4 from sources as
their installer doesn't include some development files which are necessary.

==== Download and install Python - use Windows installer ====

(It doesn't matter to what folder you'll install it)

http://python.org/download/

==== Download SIP and PyQt4 sources ====

http://www.riverbankcomputing.com/software/sip/download
http://www.riverbankcomputing.com/software/pyqt/download

Extract each of the above zip files in a temporary directory. Make sure
to get versions that match your current Qt installed version.
   
==== Compile SIP ====

``` 
c:\Qt\4.8.0\bin\qtvars.bat 
python configure.py -p win32-g++ 
make 
make install 
```

==== Compile PyQt ====

``` 
c:\Qt\4.8.0\bin\qtvars.bat 
python configure.py 
make 
make install 
```

==== Final python notes ====

/!\ You can delete the directories with unpacked SIP and PyQt4 sources after a
successful install, they're not needed anymore.

=== git ===

In order to check out QGIS sources from the repository, you need a git client.
This installer should work fine:

http://msysgit.googlecode.com/files/Git-1.7.4-preview20110204.exe

=== CMake ===

CMake is build system used by QGIS. Download it from here:

http://www.cmake.org/files/v2.8/cmake-2.8.2-win32-x86.exe

=== QGIS ===

Start a cmd.exe window ( Start -> Run -> cmd.exe ) Create development 
directory and move into it

``` 
md c:\dev\cpp 
cd c:\dev\cpp 
```
   
Check out sources from GIT:

```
git clone git://github.com/qgis/QGIS.git
```

=== Compiling ===

As a background read the generic building with CMake notes at the end of 
this document.

Start a cmd.exe window ( Start -> Run -> cmd.exe ) if you don't have one
already.  Add paths to compiler and our MSYS environment:
  
``` 
c:\Qt\4.8.0\bin\qtvars.bat 
```

For ease of use add c:\Qt\4.8.0\bin\ to your system path in system
properties so you can just type qtvars.bat when you open the cmd console.
Create build directory and set it as current directory:


``` 
cd c:\dev\cpp\qgis 
md build 
cd build 
```

=== Configuration ===

```
cmakesetup ..  
```

**Note:** You must include the '..' above.

Click 'Configure' button.  When asked, you should choose 'MinGW Makefiles' as
generator.

There's a problem with MinGW Makefiles on Win2K. If you're compiling on this
platform, use 'MSYS Makefiles' generator instead.

All dependencies should be picked up automatically, if you have set up the
Paths correctly. The only thing you need to change is the installation
destination (CMAKE_INSTALL_PREFIX) and/or set 'Debug'.

For compatibility with NSIS packaging scripts I recommend to leave the install
prefix to its default c:\program files\

When configuration is done, click 'OK' to exit the setup utility.

=== Compilation and installation ===
 
``` 
 make make install 
```

=== Run qgis.exe from the directory where it's installed (CMAKE_INSTALL_PREFIX) ===

Make sure to copy all .dll:s needed to the same directory as the qgis.exe
binary is installed to, if not already done so, otherwise QGIS will complain
about missing libraries when started.

A possibility is to run qgis.exe when your path contains c:\msys\local\bin and
c:\msys\local\lib directories, so the DLLs will be used from that place.

=== Create the installation package: (optional) ===

Download and install NSIS from (http://nsis.sourceforge.net/Main_Page)

Now using windows explorer, enter the win_build directory in your QGIS source
tree. Read the READMEfile there and follow the instructions. Next right click
on qgis.nsi and choose the option 'Compile NSIS Script'. 

== Creation of MSYS environment for compilation of QGIS ==

=== Initial setup ===

==== MSYS ====

This is the environment that supplies many utilities from UNIX world in Windows and is needed
by many dependencies to be able to compile.

Download from here:
	http://puzzle.dl.sourceforge.net/sourceforge/mingw/MSYS-1.0.11-2004.04.30-1.exe

Install to ``c:\msys``

All stuff we're going to compile is going to get to this directory (resp. its subdirs).

==== MinGW ====

Download from here:
	http://puzzle.dl.sourceforge.net/sourceforge/mingw/MinGW-5.1.3.exe

Install to ``c:\msys\mingw``

It suffices to download and install only ``g++`` and ``mingw-make`` components.

==== Flex and Bison ====

Flex and Bison are tools for generation of parsers, they're needed for GRASS and also QGIS compilation.

Download the following packages:
	http://gnuwin32.sourceforge.net/downlinks/flex-bin-zip.php
	
	http://gnuwin32.sourceforge.net/downlinks/bison-bin-zip.php
	
	http://gnuwin32.sourceforge.net/downlinks/bison-dep-zip.php

Unpack them all to ``c:\msys\local``

=== Installing dependencies ===
 
==== Getting ready ====

Paul Kelly did a great job and prepared a package of precompiled libraries for GRASS.
The package currently includes:

- zlib-1.2.3
- libpng-1.2.16-noconfig
- xdr-4.0-mingw2
- freetype-2.3.4
- fftw-2.1.5
- PDCurses-3.1
- proj-4.5.0
- gdal-1.4.1


It's available for download here:
	http://www.stjohnspoint.co.uk/grass/wingrass-extralibs.tar.gz

Moreover he also left the notes how to compile it (for those interested):
	http://www.stjohnspoint.co.uk/grass/README.extralibs

Unpack the whole package to ``c:\msys\local``


==== GRASS ====

Grab sources from CVS or use a weekly snapshot, see:
	http://grass.itc.it/devel/cvs.php

In MSYS console go to the directory where you've unpacked or checked out sources
(e.g. ``c:\msys\local\src\grass-6.3.cvs``)

Run these commands:
```
export PATH="/usr/local/bin:/usr/local/lib:$PATH"
./configure --prefix=/usr/local --bindir=/usr/local --with-includes=/usr/local/include --with-libs=/usr/local/lib --with-cxx --without-jpeg \
--without-tiff --with-postgres=yes --with-postgres-includes=/local/pgsql/include --with-pgsql-libs=/local/pgsql/lib --with-opengl=windows --with-fftw \
--with-freetype --with-freetype-includes=/mingw/include/freetype2 --without-x --without-tcltk --enable-x11=no --enable-shared=yes \
--with-proj-share=/usr/local/share/proj
make
make install
```

It should get installed to ``c:\msys\local\grass-6.3.cvs``

By the way, these pages might be useful:
- http://grass.gdf-hannover.de/wiki/WinGRASS_Current_Status
- http://geni.ath.cx/grass.html


==== GEOS ====

Download the sources:
	http://geos.refractions.net/geos-2.2.3.tar.bz2

Unpack to e.g. ``c:\msys\local\src``

To compile, I had to patch the sources: in file ``source/headers/timeval.h`` line 13.
Change it from:
```
#ifdef _WIN32
```
to:
```
#if defined(_WIN32) && defined(_MSC_VER)
```

Now, in MSYS console, go to the source directory and run:

```
./configure --prefix=/usr/local
make
make install
```


==== SQLITE ====

You can use precompiled DLL, no need to compile from source:

Download this archive:
	http://www.sqlite.org/sqlitedll-3_3_17.zip

and copy sqlite3.dll from it to ``c:\msys\local\lib``

Then download this archive:
	http://www.sqlite.org/sqlite-source-3_3_17.zip

and copy sqlite3.h to ``c:\msys\local\include``


==== GSL ====

Download sources:
	ftp://ftp.gnu.org/gnu/gsl/gsl-1.9.tar.gz

Unpack to ``c:\msys\local\src``

Run from MSYS console in the source directory:

```
./configure
make
make install
```

==== EXPAT ====

Download sources:
	http://dfn.dl.sourceforge.net/sourceforge/expat/expat-2.0.0.tar.gz

Unpack to ``c:\msys\local\src``

Run from MSYS console in the source directory:

```
./configure
make
make install
```

==== POSTGRES ====

We're going to use precompiled binaries. Use the link below for download:
	http://wwwmaster.postgresql.org/download/mirrors-ftp?file=%2Fbinary%2Fv8.2.4%2Fwin32%2Fpostgresql-8.2.4-1-binaries-no-installer.zip

copy contents of pgsql directory from the archive to ``c:\msys\local``

=== Cleanup ===

We're done with preparation of MSYS environment. Now you can delete all stuff in ``c:\msys\local\src`` - it takes quite a lot
of space and it's not necessary at all.

