# Build Instructions for TWAPI

NOTE: Build instructions for TWAPI 5.0 have changed significantly from
previous versions.

This file primarily describes building TWAPI with the Microsoft and
MingW64 tool chains.

## What you need (or the official build environment):

- A relatively recent Visual Studio environment. Currently tested with
Visual Studio 2022 but VS 2015 and later should suffice.

or

- A relatively recent MingW64 distribution.

## Source code checkout

Fork https://github.com/apnadkarni/twapi on Github or clone the repository
locally as

    git clone https://github.com/apnadkarni/twapi.git

## Building the extension with Visual C++

Building and installing follows the standard pattern for building
Tcl extensions with nmake.

Start a Visual Studio command shell (32- or 64-bit as desired).
The starting from the top directory of repository

    cd twapi\twapi\win
    nmake /s /f makefile.vc INSTALLDIR=c:\path\to\your\tcl\installation
    nmake /s /f makefile.vc INSTALLDIR=c:\path\to\your\tcl\installation test
    nmake /s /f makefile.vc INSTALLDIR=c:\path\to\your\tcl\installation install

This will build, test and install the extension.

Make sure the Tcl installation is the same architecture (32- or 64-bit)
as the Visual Studio command shell.

## Building a full distribution

The above steps are combined into the release.cmd batch file. Edit this file to
match your Tcl installations for Tcl 8.6 and Tcl 9. Running this will build x86
and x64 for both Tcl 8.6 and Tcl 9 as a single distributable directory under
dist/latest.

## Building with MinGW-W64
-----------------------

To build with the MinGW toolchain, start a MINGW64 shell.
Then do something along the lines of (64-bit)

    cd <BUILDDIR>
    TCLDIR=/path/to/target/tcl
    /path/to/twapi/configure --enable-threads --enable-64bit --with-tcl=$TCLDIR/lib --with-tclinclude=$TCLDIR/include --prefix=$TCLDIR
    make
    make install

Note the --with-tclinclude and --prefix are necessary in the presence of a
config.site file when TCLDIR points to a private installation.

For a 32-bit build, do something similar from a 32-bit MINGW32 shell, leaving
off the --enable-64bit option.

IMPORTANT: In this case, the Tcl binaries must also have been built with the
same MinGW-W64 toolchain.