It's possible to build a Windows executable on Linux using cross compiling. For
a script which will do this for you, see `linux-windows-crosscompile.sh`.

# Removing the dependency on apt
The `linux-windows-crosscompile.sh` script uses a custom apt repo in order to
install the build tools. This avoids having to compile the compiler and speeds
up the process by hours.

However, there are several reasons one may not want to use this apt repo. It
could be that the apt repo is down, or doesn't work with the latest version of
Debian, or perhaps you want to build it on a Linux distribution that is not
apt-based. Whatever your reason, we have instructions on how to build the
toolchain from source here.

## Dependencies

There are tools that you need to build the toolchain. These are documented on
the [mxe website](https://mxe.cc/#requirements). That is the official source of
information on dependencies and it includes information on Fedora, FreeBSD,
macOS, and others.

For those using an apt-based distro, here's what you will need to install:

`sudo apt-get install -y autoconf automake autopoint bash bison bzip2 flex g++ g++-multilib gettext git gperf intltool libc6-dev-i386 libgdk-pixbuf2.0-dev libltdl-dev libgl-dev libpcre3-dev libssl-dev libtool-bin libxml-parser-perl lzip make openssl p7zip-full patch perl python3 python3-distutils python3-mako python3-packaging python3-pkg-resources python3-setuptools python-is-python3 ruby sed sqlite3 unzip wget xz-utils`

## Building the toolchain

You will have to decide if you want to build the toolchain for i686 (32-bit
Intel/AMD CPUs), x86_64 (64-bit Intel/AMD CPUs), or both. The mxe website has
[a tutorial](https://mxe.cc/#tutorial) which documents how to do this. For
quick reference, the commands are included below.

```sh
git clone https://github.com/mxe/mxe.git
cd mxe
# build i686 tooling (32-bit, intel)
make qtwebsockets libwebsockets libgcrypt libusb1 qtbase qt MXE_TARGETS="i686-w64-mingw32.static"
# build AMD64 tooling (64-bit, intel)
make qtwebsockets libwebsockets libgcrypt libusb1 qtbase qt MXE_TARGETS="x86_64-w64-mingw32.static"
# build both i686 and AMD64 tooling
make qtwebsockets libwebsockets libgcrypt libusb1 qtbase qt MXE_TARGETS="x86_64-w64-mingw32.static i686-w64-mingw32.static"
# build
MXE_DIR=`pwd`
cd ..
```

Note that we set a variable named `MXE_DIR` here. This will be important in
subsequent steps.

## Checking out Signet

Signet can be checked out in the typical fashion.

```sh
git clone --recursive https://gitlab.hax0rbana.org/signet/signet-client.git
cd signet-client
```

## Obtaining a header from the Windows SDK

The license for the Windows SDK does not allow us to include the header in our
repository. As such, you'll need to download that from them in order to compile
Signet for Windows. Below is a command that will do so. It's expected that you
will run this from the `signet-client` directory.

```sh
curl https://github.com/microsoft/win32metadata/raw/refs/heads/main/generation/WinSDK/RecompiledIdlHeaders/shared/usbiodef.h > client/Usbiodef.h
```

## Building Signet

The general process is the same whether you want to compile Signet as a 32- or
64-bit executable. The 32-bit one will run on all Intel/AMD CPUs. The 64-bit
version will only run on 64-bit Intel/AMD CPUs.

If you're unsure, build the 32-bit version since that is more compatible.

In either case, you'll need to add the tools in the `MXE_DIR` to your PATH.
This assumes you set `MXE_DIR` as described above.

```
export PATH=$MXE_DIR/usr/bin:$PATH
```

Then, with `MXE_DIR` set and your PATH updated, run the commands in the
following subsections from the `signet-client` directory. If you want to
compile both, you'll want to copy `signet.exe` somewhere else so it is not
overwritten.

### 32-bit


```sh
$MXE_DIR/usr/i686-w64-mingw32.static/qt5/bin/qmake client/client.pro
make -f Makefile.Release
file release/signet.exe
```

### 64-bit

```sh
$MXE_DIR/usr/x86_64-w64-mingw32.static/qt5/bin/qmake client/client.pro
make -f Makefile.Release
file release/signet.exe
```
