= A note on Windows/MinGW support

Now you can compile Gauche to use MinGW runtime library.  It is
the recommended way to build Gauche on Windows.  (You may still be
able to build with Cygwin but it has a few quirks that interfere
with Gauche that may surprise you.)

Because of the difference of the underlying system, not all
system-related procedures are available on MinGW port.
The reference manual tells whether a particular procedure
is supported on "`Windows native`".

As of 0.9.5, the official Windows binaries are built with
mingw-w64 (see link:http://mingw-w64.org/[]).  It may still be
built with the original MinGW, but our support efforts are
prioritized in favor of mingw-w64.  By '`MinGW version`' in
the following sections, we mean Gauche built with mingw-w64.

If you just want to use Gauche on Windows, you can use the binary
installer.  Below, we describe what you need to build Gauche
from the source.


== Prerequisites

You need the following software:

=== link:http://msys2.github.io[MSYS2]

Download the installer and follow the instruction.  I recommend
to leave the installation folder default (`C:\msys64`, for x86_64).
After setup wizard finished, do not forget to follow the instruction
in the above site to update packages.

Once MSYS2 is in place, you can get mingw-w64 toolchain using
`pacman`.  Fire MSYS2 shell and type `+pacman -S <package> ...+`.
For +mingw-w64-***+ packages, choose suitable architecture.

NOTE: If you want to build x86_64 and i686 binary installers
on x86_64 machine, you have to install both architecture versions.

The following packages are needed:

- mingw-w64-x86_64-gcc / mingw-w64-i686-gcc
- autoconf
- automake
- libtool
- pkg-config
- make

The following packages are strongly recommended.  Gauche can be built
without them, but some features will not be available.

- mingw-w64-x86_64-zlib / mingw-w64-i686-zlib
- mingw-w64-x86_64-libiconv / mingw-w64-i686-libiconv
- mingw-w64-x86_64-mbedtls / mingw-w64-i686-mbedtls
- texinfo

The following packages are only used for testing (`make check`).  You
don't need them just to build and use Gauche:

- openssl
- winpty


[NOTE]
====
`pacman` tries to install packages under `C:/msys64/mingw64` etc,
but sometimes the first attempt fails saying:

----
error: failed to commit transaction (conflicting files)
....  /mingw64 exists in filesystem
----

There is `/mingw64.exe` and `/mingw64.bat` (in msys2 filesystem) and
the installer gets confused.  Manually creating directory `/mingw64`
will solve the problem.
====

=== Gauche

You need the latest release version of Gauche in order to build
Gauche from git source.  Install it using binary installer, or,
get a tarball and build it with MSYS2.

Make sure that `gosh` is visible from the `PATH` of your MSYS shell.


=== link:http://wixtoolset.org[Wix toolset]

(Optional) This is used to create installer.   If you just want
to build just for your machine, you don't need this.


== Build

You can build it just like on any other Unix systems; but for your
convenience, there's a script `src/mingw-dist.sh` which builds Gauche
in a way that you can zip and copy the resulting binary elsewhere,
or build a binary installer.

If you start from git repo clone (instead of source tarball), you
have to run `./DIST gen` first to generate configure scripts.

Once configure scripts are in place, run the `mingw-dist.sh` on the
MSYS shell as follows:

[source,sh]
----
# For x86_64 build:
MSYSTEM=MINGW64 src/mingw-dist.sh

# For i686 build:
MSYSTEM=MINGW32 src/mingw-dist.sh
----

The compiled binaries are in `../Gauche-mingw-dist/Gauche-x86_64` or
`../Gauche-mingw-dist/Gauche-i686`, respectively.  It includes DLLs
needed to run `gosh`, so you can just zip the directory and copy
to whatever machine you like.


== Build with Gauche-gl

If you have link:https://github.com/shirok/Gauche-gl[Gauche-gl] source
tree aside of Gauche source tree
(that is, from Gauche's `$top_srcdir`, you have `../Gauche-gl`),
you can build Gauche-gl as well.  Give `--with-gl` option:

[source,sh]
----
MSYSTEM=MINGW64 src/mingw-dist.sh --with-gl
----


== Build with MbedTLS

If you've installed MinGW mbedtls library, you can build Gauche with it.

By default, mingw version includes AxTLS as the TLS support.  Unfortunately
AxTLS doesn't support all ciphers, and sometimes fail to connect to the
peer which doesn't employ ciphers AxTLS supports.  Using MbedTLS enables
much wider connectively.

To include MbedTLS support, give `--with-mbedtls` option:

[source,sh]
----
MSYSTEM=MINGW64 src/mingw-dist.sh --with-mbedtls
----

Note: If you build a Gauche binary, it includes mbedtls libarary which
is covered by Apache License 2.0.  Distributing the binary will be covered
by that license, as well as BSDL.


== Build installer

Make sure `candle.exe` and `light.exe` (WiX toolset) are in the `PATH`.

Run `src/mingw-dist.sh` with `--with-installer` option, for example:

[source,sh]
----
MSYSTEM=MINGW64 src/mingw-dist.sh --with-gl --with-installer
----

This creates installer file `../Gauche-mingw-X.X.X-{32|64}bit.msi`.
