# Makefile for the ProjectName OCaml SDK (generated by @voxgig/sdkgen).
#
# The SDK is dependency-free: it compiles with the stock bytecode compiler
# (ocamlc) — no opam packages, no dune. Two test executables are built:
#   run_sdk_test        — the SDK pipeline + feature suite (Testutil harness)
#   run_struct_corpus   — the shared voxgig/struct JSON corpus
#
# Entity modules (sdk_entity_*.ml) and per-entity tests are discovered by
# wildcard; they are mutually independent so their relative order is free.

OCAMLC = ocamlc
INC = -I utility -I . -I test

# The shared JSON corpus lives in the sibling .sdk workspace.
CORPUS = ../.sdk/test/test.json

RUNTIME = utility/vregex.ml utility/voxgig_struct.ml \
  sdk_types.ml sdk_helpers.ml sdk_runtime.ml sdk_features.ml

ENTITIES = $(sort $(wildcard sdk_entity_*.ml))

SDK = $(RUNTIME) sdk_config.ml $(ENTITIES) sdk_client.ml sdk_error.ml

ENTITY_TESTS = $(sort $(wildcard test/*_entity_test.ml) $(wildcard test/*_direct_test.ml))

# Fixed test order: harness deps first, generated/behaviour tests, summary last.
SDK_TEST = $(RUNTIME) sdk_config.ml $(ENTITIES) sdk_client.ml sdk_error.ml \
  test/testutil.ml test/harness.ml \
  test/t_pipeline.ml test/t_feature.ml test/custom_utility.ml \
  $(ENTITY_TESTS) test/t_main.ml

CORPUS_SRC = utility/vregex.ml utility/voxgig_struct.ml test/struct_corpus.ml

.PHONY: test test-sdk test-corpus build lint clean

test: test-sdk test-corpus

test-sdk: run_sdk_test
	./run_sdk_test

test-corpus: run_struct_corpus
	./run_struct_corpus $(CORPUS)

run_sdk_test: $(SDK_TEST)
	$(OCAMLC) $(INC) $(SDK_TEST) -o run_sdk_test

run_struct_corpus: $(CORPUS_SRC)
	$(OCAMLC) -I utility $(CORPUS_SRC) -o run_struct_corpus

# Type-check the SDK library (a clean compile means it is sound).
build: lint
lint:
	$(OCAMLC) $(INC) -c $(SDK)
	@echo ok

clean:
	rm -f *.cmi *.cmo test/*.cmi test/*.cmo utility/*.cmi utility/*.cmo \
	  run_sdk_test run_struct_corpus a.out
