# Regenerate the C++ reference data the Kotlin codec is tested against.
# Run from CMSDK/:  make -C kotlin/tools     (after `make` or `make ssl` built lib/<platform>/libCMSDK.a)
# Then:             cd kotlin && ./gradlew test
CMSDK  := ../..
OUT    := ../fixtures
UNAME  := $(shell uname -s)
ifeq ($(UNAME),Darwin)
  PLAT := macosx
  LIBS := -lpthread -lssl -lcrypto
else
  PLAT := linux64
  LIBS := -lpthread -lssl -lcrypto -ldl -lrt
endif
CXX    ?= g++
FLAGS  := -std=c++17 -w -DLINUX -I$(CMSDK)/include

all: $(OUT)/layout.json fixtures

$(OUT)/layout.json: layout.cpp $(CMSDK)/include/DataMessage.h
	@mkdir -p $(OUT)
	$(CXX) $(FLAGS) -o /tmp/cmsdk_dm_layout layout.cpp
	/tmp/cmsdk_dm_layout > $(OUT)/layout.json

fixtures: gen_fixtures.cpp $(CMSDK)/lib/$(PLAT)/libCMSDK.a
	@mkdir -p $(OUT)
	$(CXX) $(FLAGS) -o /tmp/cmsdk_dm_fixtures gen_fixtures.cpp $(CMSDK)/lib/$(PLAT)/libCMSDK.a $(LIBS)
	/tmp/cmsdk_dm_fixtures $(OUT)

.PHONY: all fixtures
