# Compiling Apache for Microsoft Windows

There are many important points before you begin compiling Apache. See Using Apache with Microsoft Windows before you begin.

### Requirements

Compiling Apache requires the following environment to be properly installed;

- Disk Space
  Make sure you have at least 50 MB of free disk space available. After installation Apache requires approximately 10 MB of disk space, plus space for log and cache files, which can grow rapidly. The actual disk space requirements will vary considerably based on your chosen configuration and any third-party modules or libraries.
- Microsoft Visual C++ 5.0 or higher.
  Apache can be built using the command line tools, or from within the Visual Studio IDE Workbench. the command line tools are configured with the vcvars32 batch file:

        "c:\Program Files\DevStudio\VC\Bin\vcvars32.bat"

- The Windows Platform SDK.
  Visual C++ 5.0 need the updated Microsoft Windows Platform SDK to enable some Apache features. For command line builds, the Platform SDK environment is prepared by the setenv batch file:

        "c:\Program Files\Platform SDK\setenv.bat"

  The Platform SDK files distributed with Visual C++ 6.0 and later are sufficient, so those users may skip this requirement.
  Note that the Windows Platform SDK update is required to enable all supported mod_isapi features. Without a recent update, Apache will issue warnings under MSVC++ 5.0 that some mod_isapi features will be disabled. Look for the update at http://msdn.microsoft.com/downloads/sdks/platform/platform.asp.
- The awk utility (awk, gawk or similar.)
  To install Apache within the build system, several files are modified using the awk utility. awk was chosen since it is a very small download (compared with Perl or WSH/VB) and accomplishes the task. Brian Kernighan's http://cm.bell-labs.com/cm/cs/who/bwk/ site has a compiled native Win32 binary, http://cm.bell-labs.com/cm/cs/who/bwk/awk95.exe which you should name awk.exe rather than awk95.exe.
  Note that Developer Studio IDE will only find awk.exe from the Tools menu Options... Directories settings for the Executable files. Add the path for awk.exe to this list, as needed.

### Command-Line Build

First, unpack the Apache distribution into an appropriate directory. Open a command-line prompt and cd to that directory.

The master Apache makefile instructions are contained in the `Makefile.win` file. To compile Apache on Windows NT, simply use one of the following commands to compiled the release or debug build, respectively:

        nmake /f Makefile.win _apacher

        nmake /f Makefile.win _apached

Either command will compile Apache. The latter will include debugging information in the resulting files, making it easier to find bugs and track down problems.

### Developer Studio Workspace IDE Build

Apache can also be compiled using VC++'s VisualStudio development environment. To simplify this process, a VisualStudio workspace, Apache.dsw, is provided. This workspace exposes the entire list of working .dsp projects that are required for the complete Apache binary release. It includes dependencies between the projects to assure that they are built in the appropriate order.

Open the Apache.dsw workspace, and choose InstallBin (Release or Debug build, as desired) as the Active Project. InstallBin causes all related project to be build, and then invokes Makefile.win to move the compiled executables and dlls. You may personalize the INSTDIR= choice by changing InstallBin's Settings, General tab, Build command line entry. INSTDIR defaults to the /Apache2 directory.

The .dsp project files are distributed in Visual C++ 6.0 format. Visual C++ 5.0 (97) will recognize them with the single exception of the /ZI flag (which corresponds to the VC 5.0 /Zi flag for debugging symbols.) To quickly prepare the .dsp files for the Visual Studio 5.0 (97), you can run this command from the top-level httpd-2.0 directory:

         perl srclib\apr\build\cvtdsp.pl -5

You must type this command from the top level directory of the httpd source tree. Every VC6 .dsp project file within the current directory and below will be listed as it is converted. If you contribute back a patch that revises project files, please convert them back with the the -6 option instead of -5, which returns the project files to Visual Studio 6.0 format.

### Project Components

The Apache.dsw workspace and makefile.win nmake script both build the .dsp projects of the Apache server in the following sequence:

1. `srclib\apr\apr.dsp`
2. `srclib\apr\libapr.dsp`
3. `srclib\apr-util\uri\gen_uri_delims.dsp`
4. `srclib\apr-util\aprutil.dsp`
5. `srclib\apr-util\libaprutil.dsp`
6. `srclib\pcre\dftables.dsp`
7. `srclib\pcre\pcre.dsp`
8. `srclib\pcre\pcreposix.dsp`
9. `srclib\expat-lite\libexpat.dsp`
10. `server\gen_test_char.dsp`
11. `libhttpd.dsp`
12. `Apache.dsp`

In addition, the `os\win32` subdirectory contains project files for the optional modules.

1. `modules\aaa\mod_auth_dbm.dsp`
2. `modules\aaa\mod_auth_anon.dsp`
3. `modules\aaa\mod_auth_digest.dsp`
4. `modules\cache\mod_file_cache.dsp`
5. `modules\dav\fs\mod_dav_fs.dsp`
6. `modules\dav\main\mod_dav.dsp`
7. `modules\generators\mod_info.dsp`
8. `modules\generators\mod_status.dsp`
9. `modules\mappers\mod_rewrite.dsp`
10. `modules\mappers\mod_speling.dsp`
11. `modules\metadata\mod_usertrack.dsp`
12. `modules\metadata\mod_cern_meta.dsp`
13. `modules\metadata\mod_headers.dsp`
14. `modules\metadata\mod_expires.dsp`
15. `modules\ssl\mod_ssl.dsp`
16. `modules\tls\mod_tls.dsp`

The `support\` folder contains project files for additional programs that are not part of the Apache runtime, but are used by the administrator to test Apache and maintain password and log files.

1. `support\ab.dsp`
2. `support\htdigest.dsp`
3. `support\htpasswd.dsp`
4. `support\logresolve.dsp`
5. `support\rotatelogs.dsp`
6. `support\win32\wintty.dsp`

Once Apache has been compiled, it needs to be installed in its server root directory. The default is the `\Apache2` directory, of the same drive.

To build and install all the files into the desired folder dir automatically, use one the following nmake commands:

        nmake /f Makefile.win installr INSTDIR=dir

        nmake /f Makefile.win installd INSTDIR=dir

The dir argument to INSTDIR gives the installation directory; it can be omitted if Apache is to be installed into `\Apache2`.

This will install the following:

- `dir\bin\Apache.exe` - Apache executable
- `dir\bin\htdigest.exe` - Digest auth password file utility
- `dir\bin\htpasswd.exe` - Basic auth password file utility
- `dir\bin\logresolve.exe` - Log file dns name lookup utility
- `dir\bin\rotatelogs.exe` - Log file cycling utility
- `dir\bin\wintty.exe` - Console window utility
- `dir\bin\libapr.dll` - Apache Portable Runtime shared library
- `dir\bin\libaprutil.dll` - Apache Utility Runtime shared library
- `dir\bin\libhttpd.dll` - Apache Core library
- `dir\modules\mod_*.so` - Loadable Apache modules
- `dir\conf` - Configuration directory
- `dir\logs` - Empty logging directory
- `dir\include` - C language header files
- `dir\lib` - Static Link library files
- `dir\libexec` - DLL link library files

Warning about building Apache from the development tree

Only the .dsp files are maintained between release builds. The .mak files are NOT regenerated, due to the tremendous waste of reviewer's time. Therefore, you cannot rely on the NMAKE commands above to build revised .dsp project files unless you then export all .mak files yourself from the project. This is unnecessary if you build from within the Microsoft DeveloperStudio environment.