# Host-side checks of Space Taxi's front-end screens (the parts tools/stsim
# cannot reach: they live in spacetaxi.c, above the simulation). Builds the
# game on the BLANK port with spacetaxi.c INCLUDED into the harness so its
# statics are reachable, and wraps the keyboard queue and the save file
# with scripted stand-ins.
#
#   make -C tools/staxiharness        build + run

REPO   := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../..)
ST     := $(REPO)/examples/spacetaxi
OUT    := $(REPO)/build/tools/staxiharness
SRCS   := $(filter-out $(ST)/spacetaxi.c,$(wildcard $(ST)/*.c)) \
          $(wildcard $(REPO)/src/core/*.c) $(wildcard $(REPO)/src/generic/*.c) \
          $(REPO)/src/blank/blank.c
CFLAGS := -O0 -g -w -DJOEYLIB_PLATFORM_BLANK -I$(REPO)/include -I$(REPO)/src/core \
          -I$(REPO)/src/codegen -I$(ST)
WRAPS  := -Wl,--wrap=jlInputGetChar -Wl,--wrap=jlSaveWrite -Wl,--wrap=jlSaveRead

.PHONY: all run clean

all: run

$(OUT)/harness: harness.c $(ST)/spacetaxi.c $(SRCS)
	@mkdir -p $(OUT)
	$(CC) $(CFLAGS) harness.c $(SRCS) $(WRAPS) -o $@

# The title screen's level file is read through DATA/levels (the DOS bake
# is the cross-platform STL4 form), so run from a directory that has one.
run: $(OUT)/harness
	@mkdir -p $(OUT)/DATA
	@ln -sfn $(ST)/generated/dos/levels $(OUT)/DATA/levels
	@ln -sfn $(ST)/generated/dos/speech.bin $(OUT)/DATA/speech.bin
	cd $(OUT) && ./harness

clean:
	rm -rf $(OUT)
