> For the complete documentation index, see [llms.txt](https://roza-gb.gitbook.io/mkxp-z/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://roza-gb.gitbook.io/mkxp-z/compilation.md).

# Building with Meson

## Compilation

First, install the tools necessary to build all the dependencies:

{% tabs %}
{% tab title="Windows" %}
You must install [**MSYS2**](https://www.msys2.org). Afterwards:

1. Launch any of the MSYS2 command prompts from your Start Screen.
2. Type `pacman -Syuu` to begin updating MSYS. When the process is over, it will ask you to close the window.
3. Open the **MSYS2 MinGW 64-bit** command prompt from your Start Screen. Type `pacman -Syuu` again, and allow it to finish updating.

```bash
pacman -S git ruby vim base-devel \
          mingw-w64-x86_64-cmake \
          mingw-w64-x86_64-meson \
          mingw-w64-x86_64-autotools \
          mingw-w64-x86_64-gcc
```

{% endtab %}

{% tab title="Ubuntu 18.04" %}

```bash
sudo apt install git build-essential cmake autoconf automake libtool pkg-config ruby bison zlib1g-dev libbz2-dev xorg-dev lib32z1 libgl1-mesa-dev libasound2-dev python3-pip libpulse-dev

# Meson from apt is too old, but also be sure not to get one too new
sudo python3 -m pip install meson==0.57.2 ninja==1.10.2
```

{% endtab %}

{% tab title="Ubuntu 20.04" %}

```bash
sudo apt install git build-essential cmake meson autoconf automake libtool pkg-config ruby bison zlib1g-dev libbz2-dev xorg-dev libgl1-mesa-dev libasound2-dev libpulse-dev
```

{% endtab %}
{% endtabs %}

Next, clone mkxp-z's git repository, `cd` into your platform-specific directory, and run the build script:

{% tabs %}
{% tab title="Windows" %}

```bash
git clone https://gitlab.com/mkxp-z/mkxp-z --recursive
cd mkxp-z/windows
make
```

{% endtab %}

{% tab title="Linux" %}

```bash
git clone https://gitlab.com/mkxp-z/mkxp-z --recursive
cd mkxp-z/linux
make
```

{% endtab %}
{% endtabs %}

All you should need to do now is build mkxp-z itself.

{% tabs %}
{% tab title="Windows" %}

```bash
# Export the variables necessary to find the stuff we built
source vars.sh

# Configure the build
cd ..; meson build

# Build the thing
cd build && ninja

# Copy dependent libraries to the same folder
# for fun and profit
cp ${MKXPZ_PREFIX}/bin/x64-msvcrt-ruby310.dll $PWD
cp /mingw64/bin/zlib1.dll $PWD

# Strip it to save space
strip mkxp-z.exe

# Feast your eyes upon your work
start .
```

{% endtab %}

{% tab title="Linux" %}

```bash
# Export the variables necessary to find the stuff we built
source vars.sh

# Configure the build
cd ..; meson build

# Build the thing
cd build && ninja

# Feast your eyes upon your work
xdg-open .
```

{% endtab %}
{% endtabs %}

## Packaging (Linux)

You have two options for grouping everything together to distribute: loose files or AppImage.

{% tabs %}
{% tab title="Loose Files" %}
This will set up the executable to load dependencies from an adjacent `lib`/`lib64` folder, so that it is easier to distribute.

```bash
# Set up the build to install everything locally
meson configure --bindir=. --prefix=$PWD/local

# Do the thing
ninja install

# See the thing
xdg-open $PWD/local
```

{% endtab %}

{% tab title="AppImage" %}
This will package everything into an AppImage, making it so that the executable and all of its dependencies are contained within a single file (imagine if you had a completely static executable).

Firstly, you need to download [**AppImageTool**](https://github.com/AppImage/AppImageKit/releases/tag/12). Keep note of where you stored it. Afterwards:

```bash
# Mark AppImageTool as executable
chmod +x PATH_TO_APPIMAGETOOL

# I wanna make an AppImage
meson configure --prefix=`mktemp -d` --bindir=usr/bin \
    -Dappimage=true -Dappimagekit_path=PATH_TO_APPIMAGETOOL

# Do the thing
ninja install

# See the thing
xdg-open .
```

{% endtab %}
{% endtabs %}
