# How to set up a SeaMonkey tinderbox with Microsoft Visual C++ 2005 Express Edition

#### by Robert Kaiser <kairo@kairo.at>

This document tries to describe all I have done to build the tpol tinderbox (as seen in the Mozilla1.8-SeaMonkey tree). I hope I didn't forget anything important in this doc...

1. Install Windows XP Professional SP2 and all available updates
2. Install the Microsoft Platform SDK ("PSDK") with the following components:
• Windows Core SDK
• Tools - also select the subcomponent "Intel 64-bit"
• Build Environment - also select the subcomponent "x86 32-bit"
• Redistributable Components
• Web Workshop (IE) SDK
• Tools
• Build Environment
3. Go to the `\include\atl` folder under the PSDK directory, and:
• in `atlbase.h` around line 300 change the block around "`#pragma include atlthunk.lib`" to:
```[...]
};
#pragma pack(pop)

/*
PVOID __stdcall __AllocStdCallThunk(VOID);
VOID  __stdcall __FreeStdCallThunk(PVOID);

#define AllocStdCallThunk() __AllocStdCallThunk()
#define FreeStdCallThunk(p) __FreeStdCallThunk(p)

#pragma comment(lib, "atlthunk.lib")
*/

// workaround for not having atlthunk.lib in PSDK or VC++ 2005 Express Edition
#define AllocStdCallThunk() HeapAlloc(GetProcessHeap(),0,sizeof(_stdcallthunk))
#define FreeStdCallThunk(p) HeapFree(GetProcessHeap(), 0, p)

#elif defined (_M_AMD64)
#pragma pack(push,2)
[...]```
• in `atlwin.h` around line 1753, replace "`for(i = 0;`" with "`for(int i = 0;`"
Now the PSDK should be fixed in a way that we can build ATL stuff using it. Unfortunately MFC still doesn't work (see below).
NOTE: This step might not be needed if you use the `--disable-activex` build option instead, as ATL should only be needed for ActiveX.
4. Install Visual C++ 2005 Express Edition ("VC8"): Leave default installation settings (only IDE selected)
5. Install MSASM32.
6. Install Cygwin:
• Set the package location to a location that won't be overwritten. The location is irrelevant to getting a working build, but it'll make updating your Cygwin environment easier in the future should you choose to do so.
• Install for "All Users" with a default text file type of "Unix" (both should be default options).
• In the package list dialog, click on "View" once to enter View All mode.
• Select the following packages (click a line in the "New" column to chenge your selection):
• `ash`, `cvs`, `coreutils`, `diffutils`, `findutils`, `gawk`, `grep`, `patch`, `perl`, `sed`, `unzip`, `zip` (as provided)
• `make`: select version 3.79.1-7, because make 3.80 may break the build (?)
• `openssh`, `rsync` (needed by tinderbox)
NOTE: You may use ActiveState perl instead of the perl package in cygwin if you prefer, but I had problems getting tinderbox to run with that, so I went back to cygwin perl.
7. Install moztools ("Netscape wintools") and compiler-specific libraries:
• Unzip moztools to a temporary directory, open a Windows command prompt and enter the following:
```SET MOZ_TOOLS=C:\moztools
cd buildtools\windows
install.bat```
• Extract the VC8-compiled versions of `glib`, `libIDL` and `pthreads` from our fellow mozillazine building folks (see also bug 315929) directly on `C:\` so that they end up in a `C:\vc8` directory.
8. In a new `C:\moz` directory, create a `buildsetup.bat` with the following content:
```@ECHO OFF
SET MOZ_TOOLS=C:\moztools
SET VCMOZTOOLS=C:\vc8
SET MASM=C:\masm32
SET VSTUDIO=%ProgramFiles%\Microsoft Visual Studio 8
SET VCPATH=%VSTUDIO%\VC
SET NETSDK=%VSTUDIO%\SDK\v2.0
SET NETFW=%SystemRoot%Microsoft.NET\Framework\v2.0.50727
SET PSDK=%ProgramFiles%\Microsoft Platform SDK

SET PATH=%VCMOZTOOLS%;%VCMOZTOOLS%\bin
SET PATH=%PATH%;%VCPATH%\bin;%PSDK%\Bin;%NETSDK%\Bin
SET PATH=%PATH%;%MOZ_TOOLS%\bin;C:\cygwin\bin
SET PATH=%PATH%;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\wbem
SET PATH=%PATH%;%VSTUDIO%\Common7\IDE
SET PATH=%PATH%;%PSDK%\Bin\win64
SET PATH=%PATH%;%NETFW%
SET PATH=%PATH%;%MASM%\BIN

SET LIB=%VCPATH%\lib;%PSDK%\Lib;%NETSDK%\Lib
SET LIB=%LIB%;%MASM%\LIB

SET INCLUDE=%VCPATH%\include;%PSDK%\Include;%NETSDK%\Include
SET INCLUDE=%INCLUDE%;%MASM%\INCLUDE
SET INCLUDE=%INCLUDE%;%PSDK%\Include\atl
SET INCLUDE=%INCLUDE%;%PSDK%\Include\crt
SET INCLUDE=%INCLUDE%;%PSDK%\Include\mfc

SET GLIB_PREFIX=%VCMOZTOOLS%
SET LIBIDL_PREFIX=%VCMOZTOOLS%
SET CVSROOT=:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot
SET HOME=C:\moz
SET CVS_RSH=ssh
ECHO Installation environment variables set!
@ECHO ON```
9. Install Blat (needed by tinderbox):
• Copy the Blat executable files into `C:\moztools\bin`
• Configure Blat:
`blat -install <mailserver> <sender's addr> 5`
10. Install tinderbox in `C:\tinderbox\SeaMonkey` and set up a fitting `tinder-config.pl` there:
• Create a `C:\tinderbox` directory, open a command prompt there and run
```C:\moz\buildsetup.bat
cvs co mozilla/tools/tinderbox
cvs co mozilla/tools/performance/startup/startup-test.html```
NOTE: you might get a note about a missing .cvspass file. In this case, run `touch C:\moz\.cvspass`.
• Create a `C:\tinderbox\SeaMonkey` directory and copy the following files from `C:\tinderbox\mozilla\tools\tinderbox` in there: `bloatdiff.pl`, `build-seamonkey-util.pl`, `build-seamonkey.pl`, `gettime.pl`, `post-mozilla-rel.pl`, `post-mozilla.pl`, `reportdata.pl`, `tinder-config.pl`, `tinder-defaults.pl`, `tinderbox`
• Copy the `startup-test.html` you checked out into that dir as well.
• Edit `tinder-config.pl`, with the following non-default options (adjust as wanted/needed):
```\$BuildAdministrator = "yourname\@yourdomain.tld";
\$CleanProfile             = 1;
\$ProductName              = "SeaMonkey";
\$DHTMLPerformanceTest     = 1;  # Tdhtml
\$XULWindowOpenTest        = 1;  # Txul
\$StartupPerformanceTest   = 1;  # Ts
\$Make          = 'make';       # Must be GNU make
\$use_blat       = 1;
\$ObjDir = '../build/';
\$BuildNameExtra = 'SeaMonkey-1.0';
\$BuildName = 'mymachine';
\$BuildTag = 'MOZILLA_1_8_BRANCH';
\$BinaryName = 'seamonkey.exe';
\$ReleaseBuild  = 0;
\$clean_objdir = 1; # remove objdir when starting release cycle?
\$clean_srcdir = 0; # remove srcdir when starting release cycle?
\$milestone     = "mozilla1.8";
\$ENV{MOZILLA_OFFICIAL} = 1;
\$ENV{BUILD_OFFICIAL} = 1;
\$ENV{NO_MFC} = 1;
```
NOTE: it's important you use `make` and the correct `\$BinaryName` ending in "`.exe`". The `\$ENV{}` statements are needed as it seems that tinderbox doesn't use the `export`s made by the `mozconfig` (see below).
• If your Windows has a different language than English, edit `build-seamonkey-util.pl` line 1116 from "`if (\$ENV{USERPROFILE}) {`" to "`if (\$ENV{USERPROFILE} && -d \$ENV{USERPROFILE}."\\Application Data") {`" (see bug 318403)
11. Create a `mozconfig` in `C:\tinderbox\SeaMonkey` with the following content:
```# tpol tinderbox config

# these are done in tinder-config.pl since this doesn't seem to work:
export MOZILLA_OFFICIAL=1
export BUILD_OFFICIAL=1

# disable embedding's MFC tests (don't build with free tools)
export NO_MFC=1

# SVG and canvas
Especially care that `--enable-optimize="-Zc:wchar_t-"` and `export NO_MFC=1` are in there, both are needed to successfully build with your VC8 environment.
12. Run a checkout of the code, best with the tinderbox start command noted below (terminated by `Ctrl+C` once it has checked out the whole source).
13. Apply patch(es) for `.manifest` embedding (see bug 249782)
14. Run tinderbox: Go to `C:\tinderbox\SeaMonkey` in a command prompt and run
```c:\moz\buildsetup.bat
perl build-seamonkey.pl --depend --mozconfig mozconfig```
NOTE: Instead of the perl command, you can also use the tinderbox start script to run it, which needs to be run through bash, but completely runs tinderbox in the background. For this, run the following command after loading `buildsetup.bat`:
`  bash -c "./tinderbox depend start"`

## Redistributable builds

The generated builds run fine on the build machine, but for redistributing, all included `.exe` and `.dll` files need to find the VC8 libraries. Actually, only `msvcr80.dll` is needed. Interestingly, even if the EULA grants the permission to redistribute the libraries (from how I read it), the Express Edition creates no `redist` folder that would contain them for redistribution. Of couse, it installs them on your system though.

NOTE: With the full Visual C++ 2005, you get not only the `redist` folder, but also a `vcredist_x86.exe` that can be installed on the target system. Once that's done, all VC8 builds run out-of-the-box there.

So, you need to get your build to have and find `msvcr80.dll` on the target system. It's harder to find out how to do that than one would expect, but it's possible. First, find your `msvcr80.dll`, which should be in a folder called "`C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd`", and copy this file into the application's main directory (next to `seamonkey.exe` in our case). With luck, the build should run with Windows versions up to Windows 2000 now. Windows XP makes use of so-called "Side-by-side" Assemblies, and uses much tighter versioning of binaries, which makes deployment of our packages more complicated unfortunately, as the VC8 linker writes a requirement for different versions of the libraries into our files than the versions distributed with VC8.

To make it short, you need to add a `Microsoft.VC80.CRT.manifest` next to `msvcr80.dll`. This is a simple XML file with the following content:

```<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable></noInheritable>
<assemblyIdentity type="win32" name="Microsoft.VC80.CRT" version="8.0.50608.0" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
<file name="msvcr80.dll" hash="2a0d797a8c5eac76e54e98db9682e0938c614b45" hashalg="SHA1"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>phRUExlAeZ8BwmlD8VlO5udAnRE=</dsig:DigestValue></asmv2:hash></file>
<file name="msvcp80.dll" hash="cc4ca55fb6aa6b7bb8577ab4b649ab77e42f8f91" hashalg="SHA1"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>7AY1JqoUvK3u/6bYWbOagGgAFbc=</dsig:DigestValue></asmv2:hash></file>
<file name="msvcm80.dll" hash="55e8e87bbde00d1d96cc119ccd94e0c02c9a2768" hashalg="SHA1"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>hWq8zazTsMeKVxWFBa6bnv4hEOw=</dsig:DigestValue></asmv2:hash></file>
</assembly>```
SeaMonkey has a quite big set of `.dll` files in the `components` folder as well, we have to direct them to the VC library as well, so copy our `.manifest` in there, but with one slight change: the `name="msvc*80.dll"` attributes get changed to `name="..\msvc*80.dll"` so that we can trick modern Windows versions into loading only one copy of the libraries. Note that older Windows version might need another copy of `msvcr80.dll` in the `components` folder, we haven't tested that (yet).

With those changes, you should actually be able to run your builds on a computer that doesn't have VC8 installed.
From what I've heard, Windows NT 3.51 or Windows 95 still can't run the builds however...