Merge pull request #294 from pret/makefile
Some checks are pending
build / build (push) Waiting to run

Collapse shell scripts into a Makefile; update INSTALL and CONTRIBUTING docs
This commit is contained in:
Rachel 2024-11-08 10:02:09 -08:00 committed by GitHub
commit d8e9bab13a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 455 additions and 274 deletions

View File

@ -10,6 +10,7 @@ env:
CALCROM_DISCORD_WEBHOOK_AVATAR_URL: "https://i.imgur.com/38BQHdd.png"
CALCROM_DISCORD_WEBHOOK_USERNAME: "OK"
CALCROM_WEBHOOK_URL: "${{ secrets.WEBHOOKURL }}"
BUILD: /var/tmp/pokeplatinum
jobs:
build:
@ -30,15 +31,15 @@ jobs:
uses: actions/checkout@v2
- name: Configure Repo
run: ./config.sh /var/tmp/pokeplatinum
run: make configure
- name: Build Repo
run: meson test -C /var/tmp/pokeplatinum
run: make check
- name: Webhook
if: ${{ github.event_name == 'push' }}
env:
arm9name: /var/tmp/pokeplatinum/
arm9name: ${{ vars.BUILD }}
run: |
.github/calcrom/webhook.sh "$CALCROM_WEBHOOK_URL"
continue-on-error: true
@ -46,7 +47,7 @@ jobs:
- name: Post error archive
if: failure()
continue-on-error: true
run: tar czf failure.tar.gz /var/tmp/pokeplatinum
run: tar czf failure.tar.gz "$BUILD"
- name: Post error upload
if: failure()
@ -55,21 +56,21 @@ jobs:
name: pokeplatinum-failure-${{ github.run_id }}
path: failure.tar.gz
retention-days: 1
- name: Checkout xMAP
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v4
with:
path: 'xmap'
ref: 'xmap'
- name: Move xMAP
if: ${{ github.event_name == 'push' }}
run: |
mkdir -p xmap
cp /var/tmp/pokeplatinum/*.xMAP xmap/platinumus.xMAP
cp "$BUILD/*.xMAP" xmap/platinumus.xMAP
echo "XMAP_COMMIT_MSG=$( git log --format=%s ${GITHUB_SHA} )" >> $GITHUB_ENV
- name: Update xMAP
if: ${{ github.event_name == 'push' }}
uses: EndBug/add-and-commit@v9

View File

@ -1,59 +1,74 @@
# Contributing to pret/pokeplatinum
<!--toc:start-->
- [My Build is Failing After Merging from Main](#my-build-is-failing-after-merging-from-main)
- [Editor Enhancements](#editor-enhancements)
- [Code Formatting](#code-formatting)
- [Contributing to pret/pokeplatinum](#contributing-to-pretpokeplatinum)
- [Preliminaries](#preliminaries)
- [Editor Enhancements](#editor-enhancements)
- [Code Formatting](#code-formatting)
<!--toc:end-->
This document provides a synopsis and loose guidelines for how to contribute to this project. It is a work in progress. Maintainers should expand this document.
This document provides a synopsis and loose guidelines for how to contribute to
this project. It is a work in progress. Maintainers should expand this document.
## My Build is Failing After Merging from Main
## Preliminaries
It is likely that your subprojects are out of date; update them with the following command and re-build:
We contribute using a fork-model rather than committing branches directly to the
repository. Please make a fork before starting work on your contribution.
Any and all pull requests to the repository *must* produce a ROM which matches
`sha1: ce81046eda7d232513069519cb2085349896dec7` by default. To verify this
locally, a `check` target is included in the `Makefile`:
```bash
make check
```
meson subprojects update
```
This target is run automatically as part of the default `make` command defined
in the provided `Makefile`.
> [!IMPORTANT]
> If your pull request does not produce a matching ROM, then it will not be
> considered for merge until it has been updated to do so.
## Editor Enhancements
This repository includes a script to generate a `compile_commands.json` that is
compatible with C language servers such as `clangd`.
This repository includes a script to generate a `compile_commands.json` that is compatible with C language servers such as `clangd`.
### Requirements
The following dependencies are required:
- `python3.8` or newer
- `gcc-arm-none-eabi`
- `clangd`
### Usage
To run the script:
```bash
./gen_compile_commands.py
```
This will create a file named `compile_commands.json` in the project root, overwriting the previous copy.
This will create a file named `compile_commands.json` in the project root,
overwriting any previous copy.
## Code Formatting
This repository includes an opinionated `clang-format` specification to ensure that we maintain a common code style. For convenience, a pre-commit hook is also provided in `.githooks` which will run `clang-format` against any staged changes prior to executing a commit.
This repository includes an opinionated `clang-format` specification to ensure that
we maintain a common code style. For convenience, a pre-commit hook is also
provided in `.githooks` which will run `clang-format` against any staged changes
prior to executing a commit.
### Requirements
The following dependencies are required:
- `clang-format@17` or newer
### Usage
- `clang-format@18` or newer
To set up the pre-commit hook:
```sh
```bash
git config --local core.hooksPath .githooks/
```
To run the formatter on the full source tree:
```bash
./format.sh
make format
```

View File

@ -1,36 +1,56 @@
This doc details the steps necessary to build a copy of Pokemon Platinum (EN-US) from the sources contained in this repository.
# Installation Instructions
# 1. Setting up a dev environment
<!--toc:start-->
- [Installation Instructions](#installation-instructions)
- [0. Preliminaries](#0-preliminaries)
- [1. Setting Up Your Development Environment](#1-setting-up-your-development-environment)
- [Windows with MSYS2](#windows-with-msys2)
- [Windows Subsystem for Linux](#windows-subsystem-for-linux)
- [New Installs](#new-installs)
- [Existing Installs](#existing-installs)
- [Install Build Dependencies](#install-build-dependencies)
- [MacOS](#macos)
- [Linux](#linux)
- [Ubuntu (and other Debian derivatives)](#ubuntu-and-other-debian-derivatives)
- [Arch Linux (and derivatives)](#arch-linux-and-derivatives)
- [Fedora (and derivatives)](#fedora-and-derivatives)
- [Docker](#docker)
- [2. Downloading the Repository](#2-downloading-the-repository)
- [3. Specifying a Compiler License](#3-specifying-a-compiler-license)
- [Windows (including WSL 1)](#windows-including-wsl-1)
- [Unix Systems](#unix-systems)
- [4. Building the Repository](#4-building-the-repository)
- [5. Debugger Support](#5-debugger-support)
- [Troubleshooting FAQ](#troubleshooting-faq)
- [My Build is Failing After Merging from Main](#my-build-is-failing-after-merging-from-main)
<!--toc:end-->
## Windows
This document details the steps necessary to build a copy of Pokémon Platinum
(EN-US) using this repository.
First, create an environment variable called `LM_LICENSE_FILE` with its value as the planned path to the license file in the repository, at `tools/cw/license.dat`. For example, if you plan to store the repository at **C:\\Users\\_\<user>_\\Desktop\\pokeplatinum**, where _\<user>_ is your Windows username, then the value of `LM_LICENSE_FILE` should be `C:\Users\<user>\Desktop\pokeplatinum\tools\cw\license.dat`.
## 0. Preliminaries
To add an environment variable:
1. Search for "environment variables" in Windows 10's Start Search, and click the option that says "Edit the system environment variables".
2. In the window that opens, click the button that says "Environment Variables..." on the bottom right.
3. In the window that opens, click "New..." on the bottom right.
4. Input in the environment variable name and value, then click "OK".
## 1. Setting Up Your Development Environment
You will need to restart your computer for the changes to take effect, but if you plan to use Windows Subsystem for Linux (WSL), then you can restart later as part of the required restart when installing WSL, if you choose so.
### Windows with MSYS2
You now have the choice between two different environments to use to build the project.
1. Download the MSYS2 installer from [the official website](https://www.msys2.org/)
and install it on your system.
### MSYS2 (Recommended)
2. Once the installation is complete, a terminal should automatically pop up.
To update your package registry, enter the following command:
1. Download the MSYS2 installer from the official website: https://www.msys2.org/ and install it on your system.
2. Once the installation is complete, a terminal should automatically pop up. To update the package registry, type the following command:
```
```bash
pacman -Syu
```
Press 'Y' when prompted to confirm the update. The update process may take a few minutes. Once completed, the terminal will automatically close.
Press 'Y' when prompted to confirm the update. This process may take a few
minutes. Once completed, the terminal will automatically close.
3. Reopen an MSYS terminal (pink icon) and enter the following commands to install the necessary packages:
3. Re-open an MSYS terminal (the pink icon) from your Start Menu, then enter
the following commands to install necessary build dependencies:
```
```bash
echo 'export PATH=${PATH}:/mingw64/bin' >> ~/.bashrc
source ~/.bashrc
pacman -S git meson gcc flex bison mingw-w64-x86_64-arm-none-eabi-{binutils,gcc}
@ -38,177 +58,319 @@ You now have the choice between two different environments to use to build the p
Press 'Y' when prompted to confirm the installation.
4. Continue with the [building instructions](#2-downloading-the-repository). Make sure to always use the plain MSYS environment, other environments will not work.
4. [Download the repository](#2-downloading-the-repository).
### Windows Subsystem for Linux
***NOTE***: These instructions are written for WSL version 1; if you are using WSL version 2, follow the instructions below for [Linux](#linux).
> [!IMPORTANT]
> If you intend to store your project on the Windows file system (or do not know
> what that means), then use these instructions, which will guide you through
> installing WSL version 1. If you intend to use WSL version 2, then instead
> follow the instructions for [Linux](#linux).
1. Open [Windows Powershell **as Administrator**](https://i.imgur.com/QKmVbP9.png), and run the following command (Right Click or Shift+Insert is paste in the Powershell).
#### New Installs
Follow these instructions if you do not have an existing install of WSL.
1. Open [Windows PowerShell as Administrator](https://i.imgur.com/QKmVbP9.png).
Paste (Right Click or Shift+Insert) the following command:
```powershell
wsl --install -d Ubuntu
```
2. Once the process finishes, you will be prompted to restart your machine. Accept.
2. Once the process finishes, you will be prompted to restart your machine.
Accept.
3. After rebooting, reopen PowerShell and run the following commmand to downgrade to WSL1
3. After rebooting, reopen PowerShell and run the following command to downgrade
WSL to version 1:
```powershell
wsl --set-version Ubuntu 1
```
This is necessary because WSL2 has very slow access to the Windows file drive, which is where we need to store the repository.
WSL version 1 is preferred for most WSL users due to its increased performance
when accessing files in the Windows file system.
4. Open **Ubuntu** (e.g. using Search).
4. Open `Ubuntu` from your Start menu.
5. WSL/Ubuntu will set up its own installation when it runs for the first time. Once WSL/Ubuntu finishes installing, it will ask for a username and password (to be input in).
<details>
<summary><i>Note...</i></summary>
5. `Ubuntu` will set up its own installation when it runs for the first time. Once
finished, it will ask for a username and password as input.
> When typing in the password, there will be no visible response, but the terminal will still read in input.
</details>
> [!NOTE]
> When typing the password, there will be no visible response; this is normal,
> and the terminal is still reading your input.
6. Update WSL/Ubuntu before continuing. Do this by running the following command. These commands will likely take a long time to finish:
6. Update `Ubuntu`'s package registry:
```bash
sudo apt update && sudo apt upgrade
```
7. Certain packages are required to build the repository. Install these packages by running the following command:
7. [`Install build dependencies`](#install-build-dependencies).
#### Existing Installs
Follow these instructions if you have an existing install of WSL, specifically
`Ubuntu`.
Older versions of `Ubuntu` (e.g., `20.04`) ship with an outdated version of
Python, which is not supported. To remedy this, you can upgrade your existing
install to a more recent version of `Ubuntu`:
1. Run the following inside `Ubuntu`:
```bash
sudo apt upgrade && sudo apt full-upgrade
```
2. Open PowerShell and run the following commands to restart `Ubuntu`:
```powershell
wsl -t Ubuntu
wsl -d Ubuntu
```
3. Re-open `Ubuntu` and run the following to start a system upgrade:
```bash
sudo do-release-upgrade
```
This process may take a long time.
4. Once `Ubuntu` is done upgrading, update `Ubuntu`'s package registry:
```bash
sudo apt update && sudo apt upgrade
```
5. [`Install build dependencies`](#install-build-dependencies).
#### Install Build Dependencies
1. Run the following to install build dependencies from the `Ubuntu` package
registry:
```bash
sudo apt install git flex bison build-essential binutils-arm-none-eabi gcc-arm-none-eabi ninja-build
```
We are not done yet, the 'meson' package is also necessary, but the version provided by apt is too outdated. To get the most recent meson version, run:
2. Run the following to install additional dependencies via `pip`:
```
sudo apt-get install pip
```bash
sudo apt install pip
pip install --user meson
```
You may see `pip` respond with a warning saying `"The script meson is installed in '/home/<YOUR_USER>/.local/bin', which is not on PATH."` To resolve
such an issue, run the following commands:
You may see `pip` respond with a warning saying `"The script meson is
installed in '/home/<YOUR_USER>/.local/bin', which is not on PATH.` To resolve
this issue, run the following commands, filling `<path/to/install/directory>`
with the path reported by `pip` above:
```bash
echo 'export PATH="<path/to/install/directory>:$PATH"' >> ~/.bashrc
source ~/.bashrc
```
Replacing `<path/to/install/directory>` with the path mentioned above in the `pip` warning.
3. [Download the repository](#2-downloading-the-repository).
9. Change to a directory accessible from Windows where you'll store the files, for example:
```bash
cd /mnt/c/Users/$USER/Desktop
### MacOS
1. Apple bundles a number of the requisite utilities into Xcode Command Line Tools;
to install these, run:
```zsh
xcode-select --install
```
Continue with the [building instructions](#2-downloading-the-repository).
2. Additional packages can be installed using Homebrew; if you do not already have
Homebrew installed, [do so](https://brew.sh/). Once Homebrew is installed, run
the following commands:
## macOS
```zsh
brew update
brew install gcc@14 meson libpng pkg-config arm-none-eabi-binutils arm-none-eabi-gcc
brew install --cask wine-stable
```
Apple bundles a number of the requisite utilities into Xcode Command Line Tools; to install these, run:
3. If your MacOS installation is Monterey (12) or earlier, then you may also need
GNU `coreutils` installed to run the build scripts:
```
xcode-select --install
```
```zsh
brew install coreutils
```
You will also need the following packages:
4. [Download the repository](#2-downloading-the-repository).
* gcc (14.x.x)
* meson (>= 1.3.0)
* flex
* bison
* wine (to run the mwcc executables)
* libpng
* pkg-config
### Linux
These can be installed using Homebrew; if you do not have Homebrew installed, refer to the instructions [here](https://brew.sh/). Once Homebrew is installed, run:
> [!NOTE]
> Precise packages to be installed will vary by Linux distribution and
> package registry. A handful of common distributions are listed below for
> convenience.
>
> [!IMPORTANT]
> This project requires `meson` version `1.3.0` or higher. If the version of
> `meson` provided by your package manager is out of date, then follow
> [these instructions](https://mesonbuild.com/Getting-meson.html) to get the
> most recent version.
```
brew update
brew install gcc@14 meson libpng pkg-config arm-none-eabi-binutils arm-none-eabi-gcc
brew install --cask wine-stable
```
Once you have installed all the above dependencies, proceed to [downloading
the repository](#2-downloading-the-repository).
On macOS Monterey (12) or earlier, you may also need GNU Coreutils installed to run the build script.
```
brew install coreutils
```
#### Ubuntu (and other Debian derivatives)
Finally, export the variable `LM_LICENSE_FILE` with value `/path/to/pokeplatinum/tools/cw/license.dat`, e.g.:
1. Install `wine`:
```bash
sudo dpkg --add-architecture i386
sudo mkdir -pm755 /etc/apt/keyrings
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
sudo apt update
sudo apt install --install-recommends winehq-stable
```
2. Install the following packages via `apt`:
```bash
sudo apt install git flex bison ninja-build build-essential binutils-arm-none-eabi gcc-arm-none-eabi pkg-config
```
3. Install `meson` via `pip`:
```bash
pip3 install --user meson
echo "export PATH=~/.local/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
```
#### Arch Linux (and derivatives)
Install dependencies via `pacman`:
```bash
echo 'export LM_LICENSE_FILE="/path/to/pokeplatinum/tools/cw/license.dat"' >> ~/.zshrc
source ~/.zshrc
sudo pacman -S git flex bison build-essentials arm-none-eabi-binutils arm-none-eabi-gcc pkg-config wine meson
```
## Linux
#### Fedora (and derivatives)
Building the ROM requires the following packages. If you cannot find one or more of these using your package distribution, it may be under a different name.
* git
* meson (>= 1.3.0)
* flex
* bison
* build-essentials (build-essential on Ubuntu)
* binutils-arm-none-eabi (arm-none-eabi-binutils on Arch Linux)
* gcc-arm-none-eabi (arm-none-eabi-gcc on Arch Linux)
* wine (to run the mwcc executables)
* pkg-config
NOTE: On some distros, the meson package provided by the package manager will be out of date. To check your meson version, run:
```
meson --version
```bash
sudo yum install git flex bison gcc make arm-none-eabi-bintuils-cs arm-none-eabi-gcc-cs pkg-config wine meson ninja-build
```
If your mesion version is older than 1.2.0, follow the instructions at: https://mesonbuild.com/Getting-meson.html to get the most recent version of Meson.
### Docker
Finally, export the variable `LM_LICENSE_FILE` with value `/path/to/pokeplatinum/tools/cw/license.dat`, e.g.:
A `Dockerfile` is provided with the repository should you choose to build the
project as a container. If you do not have `docker` installed on your machine
and wish to make use of this feature, follow the instructions [here](https://docs.docker.com/desktop/).
Once `docker` is installed, to the build environment, run:
```bash
make clean # only if you have an existing development environment
docker build . -t pret/pokeplatinum
```
Then, run the following to build the ROM:
```bash
docker run -u $USER -w /rom -v .:/rom pret/pokeplatinum make
```
If you wish to stop using the `docker` build feature and switch back to a native
build environment, then run the following:
```bash
docker run -u $USER -w /rom -v .:/rom pret/pokeplatinum make clean
```
## 2. Downloading the Repository
From your terminal, navigate to the path in which you will store the repository.
Users of WSL 1 should ensure that their target is on the Windows file drive.
```bash
git clone https://github.com/pret/pokeplatinum
cd pokeplatinum
```
## 3. Specifying a Compiler License
Before building the repository, some final setup is required for the compiler.
Create an environment variable called `LM_LICENSE_FILE` with its value as the
path to which you cloned the repository, plus `/tools/cw/license.dat`. For
example, if you cloned your repository to `C:\Users\myuser\Desktop\pokeplatinum`,
then the value would be `C:\Users\myuser\Desktop\pokeplatinum\tools\cw\license.dat`.
### Windows (including WSL 1)
1. Search for "environment variables" in the Start menu. Click the option which
says "Edit the system environment variables".
2. In the window that opens, click the button that says "Environment Variables..."
in the lower right corner.
3. In the window that opens, click "New..." in the lower right corner.
4. Input the environment variable name and value as above, then click "OK".
5. Restart your computer.
### Unix Systems
Export the environment variable as above to your terminal profile:
```bash
echo 'export LM_LICENSE_FILE="/path/to/pokeplatinum/tools/cw/license.dat"' >> ~/.bashrc
source ~/.bashrc
```
# 2. Downloading the repository
Users of MacOS should replace `~/.bashrc` above with `~/.zshrc`.
In your terminal of choice, navigate to the path you would like to store the repository in. If you are using WSL, make sure to clone the repo under the Windows file drive. Clone the repository with:
```
git clone https://github.com/pret/pokeplatinum
cd pokeplatinum
```
## 4. Building the Repository
# 3. Building
To set up the build system, run:
```
./config.sh
```
To build the ROM, run:
This is only required once. If the process is successful, you will see a new 'build' folder in the repository.
To build the rom, run:
```
./build.sh
```bash
make
```
If everything works, then the following ROM should be built:
- [build/pokeplatinum.us.nds](https://datomatic.no-intro.org/index.php?page=show_record&s=28&n=3541) `sha1: ce81046eda7d232513069519cb2085349896dec7`
If you want to make modifications to the ROM, you can instead run:
```
./build.sh rom
If you need further assistance, feel free to ask a question in the `#pokeplatinum`
channel of the `pret` Discord (see `README.md` for contact information) or [open
an issue](https://github.com/pret/pokeplatinum/issues/new).
## 5. Debugger Support
This step is optional, but useful. `pokeplatinum` ships with support for GDB
debugging and a target to build a debug-enabled ROM:
```bash
make debug
```
After which, you should see the built ROM `pokeplatinum.us.nds` in the `build` folder.
For convenience, a template `launch.json` configuration for VS Code is provided
in the `.vscode` folder of the repository.
# 4. Docker
Due to the nature of the Nintendo DS, use of standard builds of GDB for debugging
is insufficient. A fork of `binutils-gdb` which supports the overlay system
employed by the console is available [here](https://github.com/joshua-smith-12/binutils-gdb-nds).
A Dockerfile is provided for your convenience. To begin, setup docker on your local machine following the instructions at https://docs.docker.com/desktop/. Then, run
For installation instructions, refer to [the `README.md`](https://github.com/joshua-smith-12/binutils-gdb-nds/blob/master/README.md).
./clean.sh # because we are switching environments
docker build . -t pret/pokeplatinum
docker run -u $USER -w /rom -v .:/rom pret/pokeplatinum ./config.sh # first time only
docker run -u $USER -w /rom -v .:/rom pret/pokeplatinum ./build.sh
docker run -u $USER -w /rom -v .:/rom pret/pokeplatinum ./clean.sh # before switching environments
## Troubleshooting FAQ
### My Build is Failing After Merging from Main
It is likely that your subprojects are out of date; update them with the following
command:
```bash
make update
```
And then try rebuilding.

132
Makefile Normal file
View File

@ -0,0 +1,132 @@
.PHONY: all release debug check rom target format clean distclean setup_release setup_debug configure
MESON ?= meson
NINJA ?= ninja
WINELOADER ?= wine
BUILD ?= build
ROOT_INI := $(BUILD)/root.ini
DOT_MWCONFIG := $(BUILD)/.mwconfig
TOOLS := tools
WRAP := $(TOOLS)/cw
WRAP_BUILD := $(WRAP)/build
MWRAP := $(WRAP)/mwrap
UNAME_R := $(shell uname -r)
UNAME_S := $(shell uname -s)
CWD := $(shell pwd)
ifneq (,$(findstring Microsoft,$(UNAME_R)))
ifneq (,$(filter /mnt/%,$(CWD)))
WSL_ACCESSING_WINDOWS := 0
else
WSL_ACCESSING_WINDOWS := 1
endif
else
WSL_ACCESSING_WINDOWS := 1
endif
WRAP_CONFIG := 0
ifneq (,$(findstring Linux,$(UNAME_S)))
ifeq (0,$(WSL_ACCESSING_WINDOWS))
NATIVE := native.ini
CROSS := cross_unix.ini
else
NATIVE := native_unix.ini
CROSS := cross_unix.ini
endif
else
ifneq (,$(findstring Darwin,$(UNAME_S)))
NATIVE := native_macos.ini
CROSS := cross_unix.ini
else
NATIVE := native.ini
CROSS := cross.ini
endif
endif
export LM_LICENSE_FILE ?= $(WRAP)/license.dat
export NINJA_STATUS := [%p %f/%t]
all: release check
.NOTPARALLEL: release
release: setup_release rom
.NOTPARALLEL: debug
debug: setup_debug rom
$(MESON) compile -C $(BUILD) debug.nef overlay.map
check: rom
$(MESON) test -C $(BUILD)
rom: $(BUILD)/build.ninja
$(MESON) compile -C $(BUILD) pokeplatinum.us.nds
target: $(BUILD)/build.ninja
$(MESON) compile -C $(BUILD) $(MESON_TARGET)
format: $(BUILD)/build.ninja
$(MESON) compile -C $(BUILD) clang-format
clean: $(BUILD)/build.ninja
$(MESON) compile -C $(BUILD) --clean
update: $(BUILD)/build.ninja
$(MESON) subprojects update
distclean:
rm -rf $(BUILD) $(MWRAP)
setup_release: $(BUILD)/build.ninja
$(MESON) configure build -Dgdb_debugging=false
setup_debug: $(BUILD)/build.ninja
$(MESON) configure build -Dgdb_debugging=true
configure: $(BUILD)/build.ninja
$(BUILD)/build.ninja: $(ROOT_INI) $(DOT_MWCONFIG) | $(BUILD)
MWCONFIG=$(abspath $(DOT_MWCONFIG)) $(MESON) setup \
--wrap-mode=nopromote \
--native-file=meson/$(NATIVE) \
--native-file=$(ROOT_INI) \
--cross-file=meson/$(CROSS) \
--cross-file=$(ROOT_INI) \
-- $(BUILD)
$(ROOT_INI): | $(BUILD)
echo "[constants]" > $@
echo "root = '$$PWD'" >> $@
$(DOT_MWCONFIG): $(MWRAP) | $(BUILD)
ifneq (,$(filter native_%.ini,$(NATIVE)))
WINE="$$(command -v $(WINELOADER))"; \
BUILD="$(BUILD)"; \
MWCONFIG=$(abspath $(DOT_MWCONFIG)) $(MWRAP) -conf \
-wine "$$WINE" \
-path_unx "$$PWD" \
-path_win "$$("$$WINE" winepath -w "$$PWD")" \
-path_build_unx "$$BUILD" \
-path_build_win "$$("$$WINE" winepath -w "$$BUILD")"
else ifeq (0,$(WSL_ACCESSING_WINDOWS))
BUILD="$(BUILD)"; \
MWCONFIG=$(abspath $(DOT_MWCONFIG)) $(MWRAP) -conf \
-path_unx "$$PWD" \
-path_win "$$(wslpath -w "$$PWD")" \
-path_build_unx "$$BUILD" \
-path_build_win "$$(wslpath -w "$$PWD")"
else
touch $(DOT_MWCONFIG)
endif
$(BUILD):
mkdir -p -- $(BUILD)
$(MWRAP):
rm -rf $(MWRAP) $(WRAP_BUILD)
$(MESON) setup $(WRAP_BUILD) $(WRAP)
$(MESON) compile -C $(WRAP_BUILD)
install -m755 $(WRAP_BUILD)/$(@F) $@
rm -rf $(WRAP_BUILD)

View File

@ -1,31 +0,0 @@
#!/bin/sh
set -e
target="test"
if [ "$#" -ge 1 ]; then
target="$1"
shift
fi
# Set up env variable to show % of completion during ninja build
export NINJA_STATUS="[%p %f/%t] "
# Explicitly set the Response File threshold to half of Wine's limit
# Must be here in addition to in config.sh for when Meson automatically triggers a reconfigure
# Ref: https://github.com/mesonbuild/meson/blob/8e89a38737281f7618a1284fe9e68eb6bb1fe99d/mesonbuild/backend/ninjabackend.py#L108
# Ref: https://github.com/wine-mirror/wine/blob/34b1606019982b71818780bc84b76460f650af31/dlls/ntdll/unix/env.c#L1579
# TODO: https://github.com/mesonbuild/meson/issues/13414
export MESON_RSP_THRESHOLD=16387
# Build the project
"${MESON:-meson}" configure build "-Dgdb_debugging=false"
if [ "$target" = test ]; then
"${MESON:-meson}" test -C build "$@"
elif [ "$target" = rom ]; then
"${MESON:-meson}" compile -C build "pokeplatinum.us.nds"
elif [ "$target" = debug ]; then
"${MESON:-meson}" configure build "-Dgdb_debugging=true"
"${MESON:-meson}" compile -C build "pokeplatinum.us.nds" "debug.nef" "overlay.map"
else
"${MESON:-meson}" compile -C build "$target" "$@"
fi

View File

@ -1,2 +0,0 @@
#!/bin/sh
"${MESON:-meson}" compile -C build --clean

View File

@ -1,92 +0,0 @@
#!/bin/sh
set -e
build="build"
if [ "$#" -ge 1 ]; then
build="$1"
shift
fi
wrap=tools/cw
# Build the wrapper
if ! "$wrap/mwrap" -test 2> /dev/null; then
rm -rf "$wrap/mwrap" "$wrap/build"
"${MESON:-meson}" setup "$wrap/build" "$wrap"
"${MESON:-meson}" compile -C "$wrap/build"
install -m755 "$wrap/build/mwrap" "$wrap/mwrap"
rm -rf "$wrap/build"
fi
is_wsl_accessing_windows() {
kernel=$(uname -r)
script_path=$(realpath "$0")
if echo "$kernel" | grep -q Microsoft && echo "$script_path" | grep -qE '^/mnt/'; then
return 0
else
return 1
fi
}
mkdir -p -- "$build"
root="$PWD"
if [ -n "$MSYSTEM" -a "$MSYSTEM" != MSYS ]; then
root="$(cygpath -w "$root")"
fi
# Bootstrap machine file pointing to the repo
echo "[constants]" > "$build/root.ini"
echo "root = '$root'" >> "$build/root.ini"
# Select toolchain
if [ "$(uname -s)" = "Linux" ]; then
if is_wsl_accessing_windows; then
native_file="native.ini"
cross_file="cross_unix.ini"
else
native_file="native_unix.ini"
cross_file="cross_unix.ini"
fi
elif [ "$(uname -s)" = "Darwin" ]; then
native_file="native_macos.ini" # using gcc-14/g++-14 to avoid apple clang
cross_file="cross_unix.ini"
else
native_file="native.ini"
cross_file="cross.ini"
fi
touch "$build/.mwconfig"
export MWCONFIG="$(realpath -- "$build/.mwconfig")"
if [ "$native_file" = "native_unix.ini" ] || [ "$native_file" = "native_macos.ini" ]; then
wrap_wine="$(command -v "${WINELOADER:-wine}")"
wrap_path_unx="$PWD"
wrap_path_win="$("$wrap_wine" winepath -w "$wrap_path_unx")"
wrap_path_build_unx="$build"
wrap_path_build_win="$("$wrap_wine" winepath -w "$wrap_path_build_unx")"
"$wrap/mwrap" -conf -wine "$wrap_wine" \
-path_unx "$wrap_path_unx" \
-path_win "$wrap_path_win" \
-path_build_unx "$wrap_path_build_unx" \
-path_build_win "$wrap_path_build_win"
elif is_wsl_accessing_windows; then
wrap_path_unx="$PWD"
wrap_path_win="$(wslpath -w "$wrap_path_unx")"
wrap_path_build_unx="$build"
wrap_path_build_win="$(wslpath -w "$wrap_path_build_unx")"
"$wrap/mwrap" -conf -wine "$wrap_wine" \
-path_unx "$wrap_path_unx" \
-path_win "$wrap_path_win" \
-path_build_unx "$wrap_path_build_unx" \
-path_build_win "$wrap_path_build_win"
fi
# Explicitly set the Response File threshold to half of Wine's limit
# Ref: https://github.com/mesonbuild/meson/blob/8e89a38737281f7618a1284fe9e68eb6bb1fe99d/mesonbuild/backend/ninjabackend.py#L108
# Ref: https://github.com/wine-mirror/wine/blob/34b1606019982b71818780bc84b76460f650af31/dlls/ntdll/unix/env.c#L1579
# TODO: https://github.com/mesonbuild/meson/issues/13414
export MESON_RSP_THRESHOLD=16387
# Launch meson
"${MESON:-meson}" setup --wrap-mode=nopromote --native-file=meson/"$native_file" --native-file="$build/root.ini" --cross-file=meson/"$cross_file" --cross-file="$build/root.ini" "$@" -- "$build"

View File

@ -1,4 +0,0 @@
#!/bin/sh
set -e
"${NINJA:-ninja}" -C build clang-format