## Compiling WinMerge

Compiling sources is usually the first thing you want to do. Source packages for different versions are available from SourceForge.net downloads or from Subversion repository. See readme-Subversion.html for more information about Subversion repository and using it.

### Table of Contents

1. Environment
2. BuildAll.bat
3. Project Files
4. Compiling expat
5. Compiling SCEW
6. Compiling PCRE
7. Compiling WinMerge executables
8. Shell Extension (64-bit)
9. Visual Studio 2005 & 2008 Manifest File

### Environment

#### Supported Compilers

- Visual Studio 2003.Net + Service Pack 1 (used for releases)
- Visual Studio 6 + Service Pack 6
- Visual Studio 2005 (occasional checks for compiling) (Service Pack 1 recommended)
- Visual Studio 2008

Note that WinMerge uses MFC heavily. So free (Express) editions of Visual Studio cannot compile WinMerge, unless you have MFC installed separately.

#### Libraries

WinMerge executable depends on Expat XML parser, SCEW and PCRE libraries. All are in the source tree (in `/Externals` -folder), and need to be compiled before compiling WinMerge executable.

Visual Studio 2003.Net and later: You'll need to convert library workspace and project files to new format before compiling.

To convert workspace/project files, just open them into Visual Studio and let the Visual Studio to convert. Files are:

- `Externals\expat\expat.dsw`
- `Externals\scew\win32\scew.dsp`
- `Externals\pcre\pcre.dsw`

#### Additional requirements (out of source tree)

- HTML Help Workshop (either stand-alone or from Platform SDK)
  Download it from : HTMLHelp download.
- Platform SDK - be sure to use version that works with your version of Visual Studio:
  - VC6: Platform SDK February 2003 - Download and install
  - VS2003.Net and later: Platform SDK Windows 2003 SP1 - Download and install
  Visual Studio 2003.Net and later come with Platform SDK but you may still want more recent version...
- Installer needs own tools, documented in readme-InnoSetup.html
- Manual needs Docbook tools, documented in readme-manual.html

##### Platform SDK components

With Feb 2003 Platform SDK (and VC6) following components are needed:

- Core SDK - obviously..
- MDAC SDK - for some ODBC etc headers needed by other PSDK headers..
- Internet Devlopment SDK - for IE/Shell headers

Basically same components are needed for Windows 2003 SP1 PSDK, but with a different name:

- Microsoft Windows Core SDK - obviously..
- Microsoft Data Access Services (MDAC) SDK - for some ODBC etc headers needed by other PSDK headers..
- Microsoft Web Workshop (IE) SDK - for IE/Shell headers

If you installed PSDK separately, don't forget to add the PSDK paths to Visual Studio's Include and Library directories. The easiest way is to use the "Visual Studio Registration\Register PSDK directories with Visual Studio" item from the "Platform SDK" start menu folder.

### buildall.bat

There is a `buildall.bat` in the root folder of source tree. This batch file invokes `devenv.exe` to build (almost) all projects in WinMerge tree. However, it has a couple of restrictions:

- It cannot convert project files from VC6 format to newer formats. This must be done first by opening every project to Visual Studio.
- It cannot build 64-bit shell extension

To use `buildall.bat`:

- Open Visual Studio Command Prompt (or run `vcvars32.bat` from Command Prompt).
- Go to root folder of WinMerge folder structure.
- Run the batch file.

### Project files

Project file for WinMerge executable (in `/Src`) and other projects like ShellExtension (in `/ShellExtension`) have their own project files. There is no one single project/workspace file to compile all projects.

The Visual Studio project file for MSVC6 comes with the WinMerge sources. Newer versions of Visual Studio can open that file too, they just ask if one wants to convert to the new version. The reason we don't ship project files for all Visual Studio versions is we have no resources to keep all versions up to date. People can't test all versions themselves, and easily forget to update at least one file. So we easily end up in a situation where there is no properly working project file at all...

After opening the project file you need to add the HTML Help Workshop path as additional include- and library-path.

NOTE: There might be problems compiling/debugging with Visual Studio 2003 when using HTML Help WorkShop from the Platform SDK in Visual Studio directory. Download and install HTML Workshop as stand-alone and include headers and libraries from standalone directory. The probable cause is that including files from Platform SDK directories breaks things.

Visual Studio 2003.Net: WinMerge build uses couple of helper batch files (`Src/PreLink.bat` and `Src/PostBuild.bat`) run from project file. Visual Studio adds additional quotation marks to these rules when converting for new version, which makes builds to fail. The error is something like `The system cannot find the batch label specified - ".\..\BuildTmp\MergeUnicodeDebug"` where the path varies depending on compile target.

> Check that rules to call those batch files are like: `PreLink.bat $(IntDir) $(TargetPath)`

> without additional quotation marks, like: `PreLink.bat "$(IntDir)" "$(TargetPath)"`

### Compiling expat

expat is in `/Externals/expat` folder in source tree. To compile expat:

- Open Visual Studio workspace `/Externals/expat/expat.dsw`. If you are using Visual Studio 2003.Net or later you need to convert the file to the new format when Visual Studio opens the file.
- Select from Visual Studio menu Build / Batch Build
- Select either debug or release targets.
- Select Rebuild All

After build finishes, selected (debug or release) lib and dll files are in `/Build/expat`. WinMerge executable's project file picks them from there.

### Compiling scew

scew is in `/Externals/scew` folder in source tree. To compile scew:

- Open Visual Studio project file `/Externals/scew/win32/scew.dsp` If you are using Visual Studio 2003.Net or later you need to convert the file to the new format when Visual Studio opens the file.
- Select from Visual Studio menu Build / Batch Build
- Make sure all targets are selected
- Select Rebuild All

### Compiling PCRE

PCRE is in `/Externals/pcre` folder in source tree. To compile PCRE:

- Open Visual Studio workspace file `/Externals/pcre/pcre.dsw` If you are using Visual Studio 2003.Net or later you need to convert the file to the new format when Visual Studio opens the file.
- Select from Visual Studio menu Build / Batch Build
- Select `config_pcre` and `pcre` projects and build them
- Select Rebuild All
- Or you can also compile those two projects individually, first `config_pcre` and then `pcre` project.

After build finishes, lib and dll files are in `/Build/pcre`. WinMerge executable's project file picks them from there.

### Compiling WinMerge executable targets

There are several targets available for compiling different projects. Targets used for compiling releases are:

- `WinMerge.exe` : Release
- `WinMergeU.exe` : UnicodeRelease
- `ShellExtension.dll` : Release MinDependency
- `ShellExtensionU.dll` : Unicode Release MinDependency
- Plugin dlls : Unicode Release MinDependency

### Shell Extension (64-bit)

This is a bit tricky, and needs some patience to setup.

#### Needed tools

- Visual Studio 2003 or later (Might work for earlier, but I haven't tried it)
- Platform SDK (for Windows 2003 SP1) with at least following components installed:
  - Configuration Options
  - Microsoft Windows Core SDK with tools and build environments
  - Microsoft Web Workshop (IE) SDK
  - Microsoft Data Access Services (MDAC) SDK not sure about this

#### Starting Visual Studio and opening the project

We need to start Visual Studio from Platform SDK's 64-bit environment so that we get all needed environment variables and paths correctly set. So:

1. Start 64-bit Platform SDK environment:
   From Start menu: Platform SDK --> Open Build Environment Window --> Windows XP/2003 64-bit environment --> Release/Debug environment
2. CD to Visual Studio install folder/Common7/IDE
3. Start Visual Studio with command:
   `devenv /USEENV (uses open environment)`
4. Open `ShellExtensionX64.vcproj` from `ShellExtension` project folder.

Make sure you have 64-bit target selected in Project Settings. Then check that paths are OK. You MUST build to separate directory than 32-bit targets so that files don't mix up.

Compiling should now succeed. If not, check that all needed PSDK components are installed and that paths are OK. If you are compiling in 32-bit Windows you get error about registering but that is expected to happen.

64-bit ShellExtension is registered to 64-bit Windows just like counterparts in 32-bit world:
`regsvr ShellExtensionX64.dll`

### Visual Studio 2005 & 2008 Manifest File

When the VC6 project file (.dsp) is converted to a Visual Studio 2005 or 2008 project, the visual styles do not get enabled. The problem is Visual Studio 2005 and 2008 automatically generates and embeds a manifest file for the executable, but that generated manifest does not include all needed properties to enable visual styles. The solution is to add WinMerge's manifest file as additional manifest.

From project properties, set
`Manifest Tool / Input and Output / Additional Manifest Files` -property value to:
`$(InputDir)\res\$(TargetFileName).manifest`

See also Manifests in VS2005-- What are they? -thread in Microsoft forum.