<!-- $PostgreSQL: pgsql/doc/src/sgml/install-win32.sgml,v 1.49 2008/07/29 15:23:44 mha Exp $ -->

<chapter id="install-win32">
 <title>Installation on <productname>Windows</productname></title>

 <indexterm>
  <primary>installation</primary>
  <secondary>on Windows</secondary>
 </indexterm>

 <para>
  It is recommended that most users download the binary distribution for 
  Windows, available as a <productname>Windows Installer</productname> package
  from the <productname>PostgreSQL</productname> website. Building from source
  is only intended for people developing <productname>PostgreSQL</productname>
  or extensions.
 </para>

 <para>
  There are several different ways of building PostgreSQL on
  <productname>Windows</productname>. The complete system can
  be built using <productname>MinGW</productname> or
  <productname>Visual C++ 2005</productname>. It can also be
  built for older versions of <productname>Windows</productname> using
  <productname>Cygwin</productname>. Finally, the client access library
  (<application>libpq</application>) can be built using
  <productname>Visual C++ 7.1</productname> or 
  <productname>Borland C++</productname> for compatibility with statically
  linked applications built using these tools.
 </para>

 <para>
  Building using <productname>MinGW</productname> or
  <productname>Cygwin</productname> uses the normal build system, see
  <xref linkend="installation"> and the FAQs in
  <filename>doc/FAQ_MINGW</filename> and <filename>do/FAQ_CYGWIN</filename>.
  Note that <productname>Cygwin</productname> is not recommended, and should
  only be used for older versions of <productname>Windows</productname> where
  the native build does not work, such as 
  <productname>Windows 98</productname>.
 </para>

 <sect1 id="install-win32-full">
  <title>Building with <productname>Visual C++ 2005</productname></title>

 <para>
  The tools for building using <productname>Visual C++ 2005</productname>,
  are in the <filename>src/tools/msvc</filename> directory. When building,
  make sure there are no tools from <productname>MinGW</productname> or
  <productname>Cygwin</productname> present in your system PATH. Also, make
  sure you have all the required Visual C++ tools available in the PATH,
  usually by starting a <application>Visual Studio Command Prompt</application>
  and running the commands from there. All commands should be run from the
  <filename>src\tools\msvc</filename> directory.
 </para>

 <para>
  Before you build, edit the file <filename>config.pl</filename> to reflect the
  configuration options you want set, including the paths to libraries used.
  If you need to set any other environment variables, create a file called
  <filename>buildenv.pl</filename> and put the required commands there. For
  example, to add the path for bison when it's not in the PATH, create a file
  containing:
  <screen>
   $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
  </screen>
 </para>

 <sect2>
  <title>Requirements</title>
  <para>
   PostgreSQL will build using either the professional versions (any edition)
   or the free Express edition of
   <productname>Visual Studio 2005</productname>. The following additional products
   are required to build the complete package. Use the
   <filename>config.pl</filename> file to specify which directories the libraries
   are available in.

   <variablelist>
    <varlistentry>
     <term><productname>ActiveState Perl</productname></term>
     <listitem><para>
      ActiveState Perl is required to run the build generation scripts. MinGW
      or Cygwin Perl will not work. It must also be present in the PATH.
      Binaries can be downloaded from
      <ulink url="http://www.activestate.com"></> (Note: version 5.8 is required,
      the free Standard Distribution is sufficient).
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>ActiveState TCL</productname></term>
     <listitem><para>
      Required for building <application>PL/TCL</application> (Note: version
      8.4 is required, the free Standard Distribution is sufficient).
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>Bison</productname> and
      <productname>Flex</productname></term>
     <listitem><para>
      Bison and Flex are required to build from CVS, but not required when
      building from a release file. Note that only Bison 1.875 or versions
      2.2 and later will work. Bison and Flex can be
      downloaded from <ulink url="http://gnuwin32.sourceforge.net"></>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>Diff</productname></term>
     <listitem><para>
      Diff is required to run the regression tests, and can be downloaded
      from <ulink url="http://gnuwin32.sourceforge.net"></>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>Gettext</productname></term>
     <listitem><para>
      Gettext is required to build with NLS support, and can be downloaded
      from <ulink url="http://gnuwin32.sourceforge.net"></>. Note that binaries,
      dependencies and developer files are all needed.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>Microsoft Platform SDK</productname></term>
     <listitem><para>
      It is recommended that you upgrade to the latest available version
      of the <productname>Microsoft Platform SDK</productname>, available
      for download from <ulink url="http://www.microsoft.com/downloads/"></>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>MIT Kerberos</productname></term>
     <listitem><para>
      Required for Kerberos authentication support. MIT Kerberos can be
      downloaded from 
      <ulink url="http://web.mit.edu/Kerberos/dist/index.html"></>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>libxml2</productname> and
      <productname>libxslt</productname></term>
     <listitem><para>
      Required for XML support. Binaries can be downloaded from
      <ulink url="http://zlatkovic.com/pub/libxml"></> or source from
      <ulink url="http://xmlsoft.org"></>. Note that libxml2 requires iconv,
      which is available from the same download location.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>openssl</productname></term>
     <listitem><para>
      Required for SSL support. Binaries can be downloaded from
      <ulink url="http://www.slproweb.com/products/Win32OpenSSL.html"></>
      or source from <ulink url="http://www.openssl.org"></>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>ossp-uuid</productname></term>
     <listitem><para>
      Required for UUID-OSSP support (contrib only). Source can be 
      downloaded from
      <ulink url="http://www.ossp.org/pkg/lib/uuid/"></>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>Python</productname></term>
     <listitem><para>
      Required for building <application>PL/Python</application>. Binaries can
      be downloaded from <ulink url="http://www.python.org"></>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term><productname>zlib</productname></term>
     <listitem><para>
      Required for compression support in <application>pg_dump</application>
      and <application>pg_restore</application>. Binaries can be downloaded
      from <ulink url="http://www.zlib.net"></>.
     </para></listitem>
    </varlistentry>

   </variablelist>
  </para>
 </sect2>

 <sect2>
  <title>Building</title>

  <para>
   To build all of PostgreSQL in release configuration (the default), run the
   command:
   <screen>
    <userinput>
     build
    </userinput>
   </screen>
   To build all of PostgreSQL in debug configuration, run the command:
   <screen>
    <userinput>
     build DEBUG
    </userinput>
   </screen>
   To build just a single project, for example psql, run the commands:
   <screen>
    <userinput>
     build psql
    </userinput>
    <userinput>
     build DEBUG psql
    </userinput>
   </screen>
   To change the default build configuration to debug, put the following
   in the <filename>buildenv.pl</filename> file:
   <screen>
    <userinput>
     $ENV{CONFIG}="Debug";
    </userinput>
   </screen>
  </para>

  <para>
   It is also possible to build from inside the Visual Studio GUI. In this
   case, you need to run:
   <screen>
    <userinput>
     perl mkvcbuild.pl
    </userinput>
   </screen>
   from the command prompt, and then open the generated
   <filename>pgsql.sln</filename> (in the root directory of the source tree)
   in Visual Studio.
  </para>
 </sect2>

 <sect2>
  <title>Cleaning and installing</title>

  <para>
   Most of the time, the automatic dependency tracking in Visual Studio will
   handle changed files. But if there have been large changes, you may need
   to clean the installation. To do this, simply run the
   <filename>clean.bat</filename> command, which will automatically clean out
   all generated files. You can also run it with the
   <parameter>dist</parameter> parameter, in which case it will behave like
   <userinput>make distclean</userinput> and remove the flex/bison output files
   as well.
  </para>

  <para>
   By default, all files are written into a subdirectory of the
   <filename>debug</filename> or <filename>release</filename> directories. To
   install these files using the standard layout, and also generate the files
   required to initialize and use the database, run the command:
   <screen>
    <userinput>
     perl install.pl c:\destination\directory
    </userinput>
   </screen>
  </para>
 </sect2>

 <sect2>
  <title>Running the regression tests</title>

  <para>
   To run the regression tests, make sure you have completed the build of all
   required parts first. Also, make sure that the DLLs required to load all
   parts of the system (such as the Perl and Python DLLs for the procedural
   languages) are present in the system path. If they are not, set it through
   the <filename>buildenv.pl</filename> file. To run the tests, run one of
   the following commands from the <filename>src\tools\msvc</filename>
   directory:
   <screen>
    <userinput>
     vcregress check
    </userinput>
    <userinput>
     vcregress installcheck
    </userinput>
    <userinput>
     vcregress plcheck
    </userinput>
    <userinput>
     vcregress contribcheck
    </userinput>
   </screen>

   To change the schedule used (default is the parallel), append it to the
   command line like:
   <screen>
    <userinput>
     vcregress check serial
    </userinput>
   </screen>

   For more information about the regression tests, see
   <xref linkend="regress">.
  </para>
 </sect2>

 <sect2>
  <title>Building the documentation</title>

  <para>
   Building the PostgreSQL documentation in HTML format requires several tools
   and files. Create a root directory for all these files, and store them
   in the subdirectories in the list below.
   <variablelist>
    <varlistentry>
     <term>OpenJade 1.3.1-2</term>
     <listitem><para>
      Download from
      <ulink url="http://sourceforge.net/project/downloading.php?groupname=openjade&amp;filename=openjade-1_3_1-2-bin.zip"></>
      and uncompress in the subdirectory <filename>openjade-1.3.1</filename>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term>DocBook DTD 4.2</term>
     <listitem><para>
      Download from
      <ulink url="http://www.oasis-open.org/docbook/sgml/4.2/docbook-4.2.zip"></>
      and uncompress in the subdirectory <filename>docbook</filename>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term>DocBook DSSSL 1.79</term>
     <listitem><para>
      Download from
      <ulink url="http://sourceforge.net/project/downloading.php?groupname=docbook&amp;filename=docbook-dsssl-1.79.zip"></>
      and uncompress in the subdirectory
      <filename>docbook-dsssl-1.79</filename>.
     </para></listitem>
    </varlistentry>

    <varlistentry>
     <term>ISO character entities</term>
     <listitem><para>
      Download from
      <ulink url="http://www.oasis-open.org/cover/ISOEnts.zip"></> and
      uncompress in the subdirectory <filename>docbook</filename>.
     </para></listitem>
    </varlistentry>
   </variablelist>
   Edit the <filename>buildenv.pl</filename> file, and add a variable for the
   location of the root directory, for example:
   <screen>
    $ENV{DOCROOT}='c:\docbook';
   </screen>
   To build the documentation, run the command
   <filename>builddoc.bat</filename>. Note that this will actually run the
   build twice, in order to generate the indexes. The generated HTML files
   will be in <filename>doc\src\sgml</filename>.
  </para>
 </sect2>

 </sect1>

 <sect1 id="install-win32-libpq">
  <title>Building <application>libpq</application> with
  <productname>Visual C++</productname> or
  <productname>Borland C++</productname></title>

 <para>
  Using <productname>Visual C++ 7.1-8.0</productname> or
  <productname>Borland C++</productname> to build libpq is only recommended
  if you need a version with different debug/release flags, or if you need a
  static library to link into an application. For normal use the
  <productname>MinGW</productname> or
  <productname>Visual Studio 2005</productname> version is recommended.
 </para>

 <para>
  To build the <application>libpq</application> client library using
  <productname>Visual Studio 7.1 or later</productname>, change into the
  <filename>src</filename> directory and type the command
<screen>
<userinput>nmake /f win32.mak</userinput>
</screen>
 </para>
 <para>
 To build a 64-bit version of the <application>libpq</application>
 client library using <productname>Visual Studio 8.0 or
 later</productname>, change into the <filename>src</filename>
 directory and type in the command
<screen>
<userinput>nmake /f win32.mak CPU=AMD64</userinput>
</screen>
 See the <filename>win32.mak</filename> file for further details
 about supported variables.
 </para>

 <para>
  To build the <application>libpq</application> client library using
  <productname>Borland C++</productname>, change into the
  <filename>src</filename> directory and type the command
<screen>
<userinput>make -N -DCFG=Release /f bcc32.mak</userinput>
</screen>
 </para>

 <sect2>
 <title>Generated files</title>
 <para>
  The following files will be built:

  <variablelist>
   <varlistentry>
    <term><filename>interfaces\libpq\Release\libpq.dll</filename></term>
    <listitem>
     <para>
      The dynamically linkable frontend library
     </para>
    </listitem>
   </varlistentry>
  
   <varlistentry>
    <term><filename>interfaces\libpq\Release\libpqdll.lib</filename></term>
    <listitem>
     <para>
      Import library to link your programs to <filename>libpq.dll</filename>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><filename>interfaces\libpq\Release\libpq.lib</filename></term>
    <listitem>
     <para>
      Static version of the frontend library
     </para>
    </listitem>
   </varlistentry>

  </variablelist>
 </para>

 <para>
  Normally you do not need to install any of the client files. You should
  place the <filename>libpq.dll</filename> file in the same directory
  as your applications executable file. Do not install
  <filename>libpq.dll</filename> into your Windows, System or System32
  directory unless absolutely necessary.
  If this file is installed using a setup program, it should
  be installed with version checking using the
  <symbol>VERSIONINFO</symbol> resource included in the file, to
  ensure that a newer version of the library is not overwritten.
 </para>

 <para>
  If you are planning to do development using <application>libpq</application>
  on this machine, you will have to add the
  <filename>src\include</filename> and
  <filename>src\interfaces\libpq</filename> subdirectories of the source
  tree to the include path in your compiler's settings.
 </para>

 <para>
  To use the library, you must add the
  <filename>libpqdll.lib</filename> file to your project.  (In Visual
  C++, just right-click on the project and choose to add it.)
 </para>
 </sect2>
 </sect1>
</chapter>
