engine-psx/Makefile

205 lines
5.9 KiB
Makefile
Raw Permalink Normal View History

2024-07-11 00:58:18 -03:00
export PATH := /opt/psn00bsdk/bin:$(PATH)
export PSN00BSDK_LIBS := /opt/psn00bsdk/lib/libpsn00b
CHD := ./SONICXA.chd
CUESHEET := ./build/SONICXA.cue
2024-08-18 17:41:45 -03:00
MAP16SRC := $(shell ls ./assets/levels/**/map16.json)
COL16SRC := $(shell ls ./assets/levels/**/tiles16.tsx)
MAP128SRC := $(shell ls ./assets/levels/**/tilemap128.tmx)
LVLSRC := $(shell ls ./assets/levels/**/Z*.tmx)
MDLSRC := $(shell ls ./assets/models/**/*.rsd)
PRLSRC := $(shell ls ./assets/levels/**/parallax.toml)
2025-01-12 03:26:23 -03:00
XASRC := $(shell ls ./assets/bgm/*.txt)
2025-01-12 03:38:28 -03:00
VAGSRC := $(shell ls ./assets/sfx/*.ogg)
2024-08-18 17:41:45 -03:00
MAP16OUT := $(addsuffix MAP16.MAP,$(dir $(MAP16SRC)))
COL16OUT := $(addsuffix MAP16.COL,$(dir $(COL16SRC)))
MAP128OUT := $(addsuffix MAP128.MAP,$(dir $(COL16SRC)))
LVLOUT := $(addsuffix .LVL,$(basename $(LVLSRC)))
2024-10-01 00:13:59 -03:00
OMPOUT := $(addsuffix .OMP,$(basename $(LVLSRC)))
MDLOUT := $(addsuffix .mdl,$(basename $(MDLSRC)))
PRLOUT := $(addsuffix PRL.PRL,$(dir $(PRLSRC)))
2025-01-12 03:26:23 -03:00
XAOUT := $(addsuffix .XA,$(basename $(XASRC)))
2025-01-12 03:38:28 -03:00
VAGOUT := $(addsuffix .VAG,$(basename $(VAGSRC)))
2024-08-18 17:41:45 -03:00
.PHONY: clean ${CUESHEET} run configure chd cook iso elf debug cooktest purge rebuild repack packrun
2024-07-11 00:58:18 -03:00
# Final product is CUE+BIN files
all: iso
# Targets for producing ELF, CUE+BIN and CHD files
elf: ./build/sonic.elf
iso: ${CUESHEET}
chd: ${CHD}
2024-07-11 00:58:18 -03:00
# Target for running the image
run: ${CUESHEET}
pcsx-redux-appimage \
-run -interpreter -fastboot -stdout \
2025-01-12 03:26:23 -03:00
-iso "$<"
# Target for running the image on Mednafen
run-mednafen: ${CUESHEET}
2025-01-12 09:11:24 -03:00
mednafen -force_module psx "$<"
# Target for running the image on PCSX-ReARMed
run-rearmed: ${CUESHEET}
2025-01-12 09:11:24 -03:00
pcsx -cdfile "$<"
2025-01-11 23:54:20 -03:00
run-duckstation: ${CUESHEET}
2025-01-12 09:11:24 -03:00
duckstation "$<"
2025-01-11 23:54:20 -03:00
# Run debugger
debug:
gdb-multiarch
# =======================================
# Targets for executable building
# =======================================
2024-07-11 00:58:18 -03:00
# Target directory
./build: configure
# ELF PSX executable
./build/sonic.elf: ./build
cd build && make sonic
2024-07-11 00:58:18 -03:00
# .CUE + .BIN (needs ELF and cooked assets)
${CUESHEET}: cook ./build/sonic.elf
cd build && make iso
# .CHD file (single-file CD image)
${CHD}: ${CUESHEET}
tochd -d . -- "$<"
2024-07-22 18:18:21 -03:00
2024-07-21 19:43:49 -03:00
# =======================================
# Utilitary targets
# =======================================
# Create build directory and generate CMake config from preset
2024-07-21 19:43:49 -03:00
configure:
2024-11-02 15:18:40 -03:00
# cmake --preset default .
cmake --preset release .
2024-07-11 00:58:18 -03:00
# Clean build directory
2024-07-11 00:58:18 -03:00
clean:
2024-08-18 17:41:45 -03:00
rm -rf ./build
# Clean build directory and purge cooked assets
2024-08-18 22:29:51 -03:00
purge: clean cleancook
2024-08-25 14:50:26 -03:00
rm -rf *.chd
2024-08-18 22:29:51 -03:00
2024-10-03 00:32:02 -03:00
# Clean everything and recreate iso
rebuild: purge cook elf iso
2024-10-03 00:32:02 -03:00
# Clean binaries and recreate iso
repack: clean cook elf iso
# Repack and run
packrun: repack run
2024-10-03 00:32:02 -03:00
2024-08-18 17:41:45 -03:00
# =======================================
# ASSET COOKING TARGETS
# =======================================
mdls: $(MDLOUT)
2024-08-18 17:41:45 -03:00
map16: $(MAP16OUT) $(COL16OUT)
map128: $(MAP128OUT)
lvl: $(LVLOUT)
2025-01-12 03:38:28 -03:00
prl: $(PRLOUT)
2024-10-01 00:13:59 -03:00
objs: $(OMPOUT)
2025-01-12 03:26:23 -03:00
xa: $(XAOUT)
2025-01-12 03:38:28 -03:00
vag: $(VAGOUT)
2024-08-18 17:41:45 -03:00
2025-01-12 03:38:28 -03:00
cook: mdls map16 map128 lvl objs prl vag xa
2024-08-18 17:41:45 -03:00
cleancook:
rm -rf assets/models/**/*.mdl \
assets/levels/**/*.COL \
assets/levels/**/*.MAP \
assets/levels/**/*.LVL \
2024-10-01 00:13:59 -03:00
assets/levels/**/*.OMP \
assets/levels/**/*.OTD \
assets/levels/**/*.PRL \
assets/levels/**/collision16.json \
assets/levels/**/tilemap128.csv \
assets/levels/**/tilemap128_solid.csv \
assets/levels/**/tilemap128_oneway.csv \
2025-01-12 03:26:23 -03:00
assets/levels/**/tilemap128_front.csv \
2025-01-12 03:38:28 -03:00
assets/sfx/*.WAV \
assets/sfx/*.VAG \
2025-01-12 03:26:23 -03:00
assets/bgm/*.XA \
assets/bgm/*.xa
2024-08-18 03:07:15 -03:00
2025-01-12 03:38:28 -03:00
# =========== Object models ===========
%.mdl: %.rsd %.ply %.mat
./tools/convrsd/convrsd.py $<
2025-01-12 03:38:28 -03:00
# =========== 16x16 tile mapping ===========
2024-08-18 17:41:45 -03:00
# (Depends on mapping generated on Aseprite)
%/MAP16.MAP: %/map16.json
./tools/framepacker.py --tilemap $< $@
2025-01-12 03:38:28 -03:00
# =========== 16x16 collision ===========
2024-08-18 17:41:45 -03:00
# (Depends on tiles16.tsx tile map with collision data, generated on Tiled).
%/MAP16.COL: %/tiles16.tsx
tiled --export-tileset $< "$(dir $<)collision16.json"
./tools/cookcollision.py "$(dir $<)collision16.json" $@
rm "$(dir $@)collision16.json"
2025-01-12 03:38:28 -03:00
# =========== 128x128 tile mapping ===========
2024-08-18 17:41:45 -03:00
# Also generates 128.png to create a 128x128 tileset (should be done manually)
# (Depends on tilemap128.tmx map generated on Tiled)
%/MAP128.MAP: %/tilemap128.tmx
tiled --export-map $< "$(basename $<).cnk"
2024-08-18 17:41:45 -03:00
tmxrasterizer $< "$(dir $<)128.png"
./tools/chunkgen.py "$(basename $<).cnk" $@
rm -f "$(basename $<).cnk"
rm -f "$(basename $<)_solid.cnk"
rm -f "$(basename $<)_oneway.cnk"
rm -f "$(basename $<)_none.cnk"
rm -f "$(basename $<)_front.cnk"
2024-08-18 17:41:45 -03:00
2025-01-12 03:38:28 -03:00
# =========== Level maps ===========
2024-08-18 17:41:45 -03:00
# These maps should use a tileset generated from "128.png".
# (Depends on files such as Z1.tmx, Z2.tmx, etc., generated on Tiled)
%.LVL: %.tmx
tiled --export-map $< "$(basename $@).psxlvl"
./tools/cooklvl.py "$(basename $@).psxlvl" $@
rm "$(basename $@).psxlvl"
2025-01-12 03:38:28 -03:00
# =========== Object level placement ===========
2024-10-01 00:13:59 -03:00
# (Depends on files such as Z1.tmx, Z2.tmx, etc., generated on Tiled)
%.OMP: %.tmx
./tools/cookobj/cookobj.py $<
2025-01-12 03:38:28 -03:00
# =========== Level parallax data ===========
# (Depends on a specific file named parallax.toml within level directory)
%/PRL.PRL: %/parallax.toml
./tools/buildprl/buildprl.py $<
2025-01-12 03:26:23 -03:00
2025-01-12 03:38:28 -03:00
# =========== VAG audio encoding ===========
%.VAG: %.ogg
ffmpeg -loglevel quiet -y -i "$<" -acodec pcm_s16le -ac 1 -ar 22050 "$(basename $<).WAV"
wav2vag "$(basename $<).WAV" "$@"
@rm "$(basename $<).WAV"
# =========== XA audio encoding ===========
2025-01-12 03:26:23 -03:00
# Individual file XA songs
%.xa: %.flac
psxavenc -f 37800 -t xa -b 4 -c 2 -F 1 -C 0 $< $@
# Dynamic rule for generating dependencies for a given .XA file.
# These dependencies are then .xa files that are generated for individual .flac songs.
define XA_RULE
$T: $(shell cat "$(T:.XA=.txt)" | awk '{print $$3}' | awk 'NF {print "./assets/bgm/"$$1}' | paste -s -d ' ')
endef
$(foreach T,$(XAOUT),$(eval $(XA_RULE)))
# Interleaved XA songs
%.XA: %.txt
cd $(dir $<) && xainterleave 1 $(notdir $<) $(notdir $@)