# retroDE_ps2 — DobieStation headless trace runner build
#
# Links against the libCore.a produced by the DobieStation build in
# third_party/DobieStation/build/. Requires that build to exist first:
#
#   cd ../../../third_party/DobieStation
#   mkdir -p build && cd build && cmake .. && make -j$(nproc)
#
# Then from this directory:
#
#   make
#   ./trace_runner ../../vectors/bios/nop_sled.bin
#
# See also: trace_runner.cpp header comment.

RUNNER_DIR  := $(CURDIR)
REPO_ROOT   := $(abspath $(RUNNER_DIR)/../../..)
DOBIE_ROOT  := $(REPO_ROOT)/third_party/DobieStation
DOBIE_BUILD := $(DOBIE_ROOT)/build

CXX       := g++
CXXFLAGS  := -std=c++17 -O2 -Wall -Wno-unused
INCLUDES  := -I$(DOBIE_ROOT)/src/core -I$(DOBIE_ROOT)/ext
LIBCORE_A := $(DOBIE_BUILD)/src/core/libCore.a
LIBCHDR_A := $(DOBIE_BUILD)/ext/libchdr/liblibchdr.a
LIBLZMA_A := $(DOBIE_BUILD)/ext/lzma/liblzma.a
LIBFLAC_A := $(DOBIE_BUILD)/ext/libFLAC/liblibFLAC.a
LIBZLIB_A := $(DOBIE_BUILD)/ext/zlib/libzlib.a

LDFLAGS   := $(LIBCORE_A) $(LIBCHDR_A) $(LIBLZMA_A) $(LIBFLAC_A) $(LIBZLIB_A) \
             -pthread

.PHONY: all clean check-libcore

all: trace_runner

check-libcore:
	@test -f $(DOBIE_BUILD)/src/core/libCore.a || \
	    (echo "ERROR: $(DOBIE_BUILD)/src/core/libCore.a missing — build DobieStation first" && exit 1)

trace_runner: trace_runner.cpp check-libcore
	$(CXX) $(CXXFLAGS) $(INCLUDES) $< -o $@ $(LDFLAGS)

clean:
	rm -f trace_runner
