# Makefile — unit tests for utf8_normalize_nfc (Unicode NFC normalization).
#
# Nothing in tests/ covered normalization before this: the combining-character
# smoke cases reach the code, but only incidentally, and none of them assert
# that a decomposed sequence composes or that marks are reordered by canonical
# combining class.  #1998 moved this routine's 512 KB code-point table off the
# stack and had to be reviewed against that incidental coverage.
#
# Links against libmux, which supplies utf8_normalize_nfc.
# Needs a built tree:  make install   (from the repo root)
#
# Build: make
# Run:   make test

CXX      = g++
# -MMD -MP: emit header prerequisites next to each object (#1952).  Without
# them the .o depends only on the .cpp, so editing a header this harness
# compiles against rebuilds nothing and the suite reports green against the
# previous header.
CXXFLAGS = -std=c++17 -g -O2 -Wall -Wextra -fPIC -MMD -MP
INCDIR   = ../../mux/include
LIBDIR   = ../../mux/lib

TARGET   = test_nfc

all: $(TARGET)

test_nfc.o: test_nfc.cpp
	$(CXX) $(CXXFLAGS) -DHAVE_CONFIG_H -I$(INCDIR) -c -o $@ $<

$(TARGET): test_nfc.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/netaddr).
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
