<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">

<?ifndef var.BINBASE ?>
  <?define BINBASE = ".." ?>
<?endif?>

<?if $(sys.BUILDARCH) = x64 ?>
  <?define Platform = "x64" ?>
  <?define ModuleName = "psqlODBC_x64" ?>
  <?define BIT64 = "yes" ?>
  <?define ANSIFOLDER = "x64_ANSI_Release" ?>
  <?define UNICODEFOLDER = "x64_Unicode_Release" ?>
  <?define Module_PackageId = "970B6E07-7105-4d66-80FA-9E208952FB96" ?>
  <?define InstallerVersion = "300" ?>
  <?define GUIDSEED = "400790AA-1377-4E65-B004-AB66FAD634B2" ?>
<?if $(env.PROCESSOR_ARCHITECTURE) = "AMD64" ?>
  <?define SysFolder = "$(env.SystemRoot)\system32" ?>
<?else?>
  <?define SysFolder = "$(env.SystemRoot)\sysnative" ?>
<?endif?>
<?elseif $(sys.BUILDARCH) = x86 ?>
  <?define Platform = "x86" ?>
  <?define ModuleName = "psqlODBC" ?>
  <?define BIT64 = "no" ?>
  <?define ANSIFOLDER = "x86_ANSI_Release" ?>
  <?define UNICODEFOLDER = "x86_Unicode_Release" ?>
  <?define Module_PackageId = "ACF10866-5C01-46f0-90F0-D5618638CA48" ?>
  <?define InstallerVersion = "150" ?>
  <?define GUIDSEED = "1B43106C-C8D7-4F21-84CF-44DBF1C1D934" ?>
<?if $(env.PROCESSOR_ARCHITECTURE) = "AMD64" ?>
  <?define SysFolder = "$(env.SystemRoot)\syswow64" ?>
<?else?>
  <?define SysFolder = "$(env.SystemRoot)\system32" ?>
<?endif?>
<?else?><!-- sys.BUILDARCH -->
  <?error Invalid build architecture ?>
<?endif?>

  <Module
    Id="$(ModuleName)"
    Guid="$(Module_PackageId)"
    Version="$(VERSION)"
    InstallerVersion="$(InstallerVersion)"
    Language="1033">

    <SummaryInformation
      Description="PostgreSQL ODBC Driver"
      Keywords="PostgreSQL, ODBC"
      Manufacturer="PostgreSQL Global Development Group"
      Codepage="1252" />

    <!-- Avoid WIX0267 with naked files in a merge module -->
    <Directory Id="INSTALLFOLDER" ComponentGuidGenerationSeed="$(GUIDSEED)"/>

    <!-- PostgreSQL -->
    <File Name="podbc30a.dll" Source="$(BINBASE)\$(ANSIFOLDER)\psqlodbc30a.dll">
      <CopyFile DestinationName="psqlodbc30a.dll" />
      <ODBCDriver Id="Psqlodbc_9.0_Driver_ANSI" Name="PostgreSQL ANSI($(Platform))">
        <Property Id="CPTimeout" Value="60" />
      </ODBCDriver>
      <ODBCDriver Id="Psqlodbc_11_newid_Driver_ANSI" Name="PostgreSQL ANSI">
        <Property Id="CPTimeout" Value="60" />
      </ODBCDriver>
    </File>
    <File Name="pgenlista.dll" Source="$(BINBASE)\$(ANSIFOLDER)\pgenlista.dll" />
<?if $(NoPDB) != True ?>
    <File Name="psqlodbc30a.pdb" Source="$(BINBASE)\$(ANSIFOLDER)\psqlodbc30a.pdb" />
    <File Name="pgenlista.pdb" Source="$(BINBASE)\$(ANSIFOLDER)\pgenlista.pdb" />
<?endif ?>
    <File Name="podbc35w.dll" Source="$(BINBASE)\$(UNICODEFOLDER)\psqlodbc35w.dll">
      <CopyFile DestinationName="psqlodbc35w.dll" />
      <ODBCDriver Id="Psqlodbc_9.0_Driver" Name="PostgreSQL Unicode($(Platform))">
        <Property Id="CPTimeout" Value="60" />
      </ODBCDriver>
      <ODBCDriver Id="Psqlodbc_11_newid_Driver" Name="PostgreSQL Unicode">
        <Property Id="CPTimeout" Value="60" />
      </ODBCDriver>
    </File>
    <File Name="pgenlist.dll" Source="$(BINBASE)\$(UNICODEFOLDER)\pgenlist.dll" />
<?if $(NoPDB) != True ?>
    <File Name="psqlodbc35w.pdb" Source="$(BINBASE)\$(UNICODEFOLDER)\psqlodbc35w.pdb" />
    <File Name="pgenlist.pdb" Source="$(BINBASE)\$(UNICODEFOLDER)\pgenlist.pdb" />
<?endif ?>

    <!-- MSVC Runtime -->
<?if "$(PODBCMSVCDLL)" != "" ?>
    <File Source="$(PODBCMSVCDLL)" />
<?endif ?>
<?if "$(PODBCMSVPDLL)" != "" ?>
    <File Source="$(PODBCMSVPDLL)" />
<?endif ?>
<?if "$(PODBCMSVCSYS)" != "" ?>
    <File Source="$(SysFolder)\$(PODBCMSVCSYS)" />
<?endif ?>
<?if "$(PODBCMSVPSYS)" != "" ?>
    <File Source="$(SysFolder)\$(PODBCMSVPSYS)" />
<?endif ?>
<?if "$(LIBPQMSVCDLL)" != "" ?>
    <File Source="$(LIBPQMSVCDLL)" />
<?endif ?>
<?if "$(LIBPQMSVCSYS)" != "" ?>
    <File Source="$(SysFolder)\$(LIBPQMSVCSYS)" />
<?endif ?>

    <!-- libpq -->
    <File Source="$(LIBPQBINDIR)\libpq.dll" />
<?if "$(LIBPQMEM0)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM0)" />
<?endif ?>
<?if "$(LIBPQMEM1)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM1)" />
<?endif ?>
<?if "$(LIBPQMEM2)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM2)" />
<?endif ?>
<?if "$(LIBPQMEM3)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM3)" />
<?endif ?>
<?if "$(LIBPQMEM4)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM4)" />
<?endif ?>
<?if "$(LIBPQMEM5)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM5)" />
<?endif ?>
<?if "$(LIBPQMEM6)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM6)" />
<?endif ?>
<?if "$(LIBPQMEM7)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM7)" />
<?endif ?>
<?if "$(LIBPQMEM8)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM8)" />
<?endif ?>
<?if "$(LIBPQMEM9)" != "" ?>
    <File Source="$(LIBPQBINDIR)\$(LIBPQMEM9)" />
<?endif ?>

    <!-- MSDTC runs in 64bit mode on 64bit machines and 32bit mode on
         32bit machines. Install the XA DLL only from a native package.
    -->
    <Component Id="pgxalib.files" Condition='"$(sys.BUILDARCHSHORT)"="X64" OR NOT VersionNT64'>
      <File Name="pgxalib.dll" Source="$(BINBASE)/$(UNICODEFOLDER)/pgxalib.dll" />
      <RegistryValue Id="pgxalib.reg.1" Root="HKLM" Key="SOFTWARE\Microsoft\MSDTC\XADLL" Name="pgxalib.dll" Type="string" Value="[#pgxalib.dll]" />
    </Component>

  </Module>
</Wix>