# Makefile — known-answer tests for the OS-backed digest entry points
# (mux_sha1_digest / mux_digest; #1963).
#
# Links against the built libmux (tests/libmux pattern: local prototypes,
# no header chain).  Needs a built tree: `make install` from the repo root
# produces mux/lib/libmux.so.
#
# Build: make
# Run:   make test
#
# The same vectors run on Windows against the CNG backend; see the build
# note at the top of test_digest.cpp.

CXX      = g++
# -MMD -MP: emit header prerequisites next to each object (#1952).
CXXFLAGS = -std=c++17 -g -O2 -Wall -Wextra -fPIC -MMD -MP
LIBDIR   = ../../mux/lib

TARGET   = test_digest

all: $(TARGET)

test_digest.o: test_digest.cpp
	$(CXX) $(CXXFLAGS) -c -o $@ $<

$(TARGET): test_digest.o
	$(CXX) $(CXXFLAGS) -o $@ $^ -L$(LIBDIR) -lmux -Wl,-rpath,$(LIBDIR)

# Prepend LIBDIR so the freshly-built libmux.so wins over any ambient
# LD_LIBRARY_PATH shadow (same rationale as tests/libmux).
test: $(TARGET)
	LD_LIBRARY_PATH=$(LIBDIR):$$LD_LIBRARY_PATH ./$(TARGET)

clean:
	rm -f *.o *.d $(TARGET)

# Generated by -MMD; absent on the first build, hence the leading '-'.
-include $(wildcard *.d)

.PHONY: all test clean
