diff --git a/.gitignore b/.gitignore index 22a4d8f..b81556f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ gen/ *.elf __pycache__/ *.pyc +.toolchains/ diff --git a/Makefile b/Makefile index 31f44f9..e16893d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ PS5_HOST ?= ps5 PS5_PORT ?= 9021 PATCHDL_HTTP_PORT ?= 12880 +ETAHEN_SOURCE_DIR ?= ../Source Code ifdef PS5_PAYLOAD_SDK include $(PS5_PAYLOAD_SDK)/toolchain/prospero.mk @@ -16,9 +17,8 @@ SRCS := src/main.c src/patchdl_assets.c src/patchdl_websrv.c WEB_ASSETS := web/index.html web/styles.css web/app.js GEN_SRCS := $(patsubst web/%,gen/web/%.c,$(WEB_ASSETS)) -CFLAGS := -g -O2 -Wall -Werror -Isrc -DPATCHDL_HTTP_PORT=$(PATCHDL_HTTP_PORT) -LDADD := -lkernel_sys -LDADD += `$(PS5_PAYLOAD_SDK)/bin/prospero-pkg-config libmicrohttpd --libs` +CFLAGS := -g -O2 -Wall -Werror -Isrc -I"$(ETAHEN_SOURCE_DIR)/include" -DPATCHDL_HTTP_PORT=$(PATCHDL_HTTP_PORT) +LDADD := -L"$(ETAHEN_SOURCE_DIR)/lib" -lmicrohttpd -lkernel_sys all: $(BIN) diff --git a/README.md b/README.md index 721708b..65a1a58 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,40 @@ argv: ```sh patchdl-ps5.elf 12881 ``` + +## Building + +PatchDL builds against `ps5-payload-dev/sdk` and reuses etaHEN's checked-in +`libmicrohttpd.a` plus header files. By default, the Makefile expects etaHEN's +source tree next to this repository: + +```text +../Source Code/include +../Source Code/lib +``` + +If the SDK is unpacked into `.toolchains/ps5-payload-sdk/ps5-payload-sdk`, the +helper script sets the required environment automatically: + +```sh +scripts/build_ps5.sh clean all +``` + +For a system-wide SDK install, set `PS5_PAYLOAD_SDK` yourself: + +```sh +export PS5_PAYLOAD_SDK=/opt/ps5-payload-sdk +make clean all +``` + +Override paths and ports as needed: + +```sh +make ETAHEN_SOURCE_DIR="/path/to/etaHEN/Source Code" PATCHDL_HTTP_PORT=12881 +``` + +Deploy with an ELF loader listening on the PS5: + +```sh +PS5_HOST=ps5 PS5_PORT=9021 scripts/build_ps5.sh test +``` diff --git a/scripts/build_ps5.sh b/scripts/build_ps5.sh new file mode 100755 index 0000000..42365ce --- /dev/null +++ b/scripts/build_ps5.sh @@ -0,0 +1,30 @@ +#!/bin/sh +set -eu + +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) + +if [ -z "${PS5_PAYLOAD_SDK:-}" ]; then + LOCAL_SDK="$ROOT_DIR/.toolchains/ps5-payload-sdk/ps5-payload-sdk" + if [ -d "$LOCAL_SDK" ]; then + PS5_PAYLOAD_SDK="$LOCAL_SDK" + export PS5_PAYLOAD_SDK + else + echo "PS5_PAYLOAD_SDK is unset and no local SDK exists at $LOCAL_SDK" >&2 + exit 1 + fi +fi + +if [ -z "${LLVM_CONFIG:-}" ] && [ -x /opt/homebrew/opt/llvm@18/bin/llvm-config ]; then + LLVM_CONFIG=/opt/homebrew/opt/llvm@18/bin/llvm-config + export LLVM_CONFIG +fi + +if [ -n "${LLVM_CONFIG:-}" ]; then + LLVM_BIN=$(dirname -- "$LLVM_CONFIG") + PATH="$PS5_PAYLOAD_SDK/bin:$LLVM_BIN:$PATH" +else + PATH="$PS5_PAYLOAD_SDK/bin:$PATH" +fi +export PATH + +exec make -C "$ROOT_DIR" "$@"