synta 0.2.1

ASN.1 parser, decoder, and encoder library with DER/BER support and C FFI
Documentation
# Makefile for Synta C integration tests
#
# Usage:
#   make                  # Build all tests
#   make test             # Build and run all tests
#   make valgrind         # Run tests under Valgrind
#   make asan             # Build and run with AddressSanitizer

# Compiler settings
CC ?= gcc
CFLAGS = -Wall -Wextra -std=c99 -O2 -g
LDFLAGS =

# Detect platform
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
    LIB_EXT = dylib
    LIB_PATH_VAR = DYLD_LIBRARY_PATH
else ifeq ($(UNAME_S),Linux)
    LIB_EXT = so
    LIB_PATH_VAR = LD_LIBRARY_PATH
else
    $(error Unsupported platform: $(UNAME_S))
endif

# Paths
SYNTA_ROOT = ../..
INCLUDE_DIR = $(SYNTA_ROOT)/include
LIB_DIR = $(SYNTA_ROOT)/target/release

# Library settings
LIBS = -lcsynta -lpthread -ldl -lm
INCLUDES = -I$(INCLUDE_DIR)

# Tests
TESTS = test_roundtrip test_errors test_memory
TEST_BINS = $(TESTS)

# Default target
all: check-lib $(TEST_BINS)

# Check that library exists
check-lib:
	@if [ ! -f "$(LIB_DIR)/libcsynta.$(LIB_EXT)" ]; then \
		echo "Error: Synta FFI library not found. Build it first with:"; \
		echo "  cd $(SYNTA_ROOT) && cargo build --release -p synta-ffi"; \
		exit 1; \
	fi
	@cd $(LIB_DIR) && ln -sf libcsynta.$(LIB_EXT) libcsynta.$(LIB_EXT).0 2>/dev/null || true

# Build tests
test_roundtrip: test_roundtrip.c $(INCLUDE_DIR)/synta.h
	$(CC) $(CFLAGS) $(INCLUDES) -o $@ $< -L$(LIB_DIR) $(LIBS)

test_errors: test_errors.c $(INCLUDE_DIR)/synta.h
	$(CC) $(CFLAGS) $(INCLUDES) -o $@ $< -L$(LIB_DIR) $(LIBS)

test_memory: test_memory.c $(INCLUDE_DIR)/synta.h
	$(CC) $(CFLAGS) $(INCLUDES) -o $@ $< -L$(LIB_DIR) $(LIBS)

# Run tests
test: all
	@echo "=== Running test_roundtrip ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) ./test_roundtrip || exit 1
	@echo ""
	@echo "=== Running test_errors ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) ./test_errors || exit 1
	@echo ""
	@echo "=== Running test_memory ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) ./test_memory || exit 1
	@echo ""
	@echo "=== All tests passed! ==="

# Run with Valgrind
valgrind: all
	@echo "=== Valgrind: test_roundtrip ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./test_roundtrip
	@echo ""
	@echo "=== Valgrind: test_errors ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./test_errors
	@echo ""
	@echo "=== Valgrind: test_memory ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./test_memory
	@echo ""
	@echo "=== Valgrind: All tests passed with no leaks! ==="

# Build and run with AddressSanitizer
asan: CFLAGS += -fsanitize=address -fno-omit-frame-pointer
asan: LDFLAGS += -fsanitize=address
asan: clean all
	@echo "=== ASAN: test_roundtrip ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) ./test_roundtrip || exit 1
	@echo ""
	@echo "=== ASAN: test_errors ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) ./test_errors || exit 1
	@echo ""
	@echo "=== ASAN: test_memory ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) ./test_memory || exit 1
	@echo ""
	@echo "=== ASAN: All tests passed! ==="

# Build and run with UndefinedBehaviorSanitizer
ubsan: CFLAGS += -fsanitize=undefined -fno-omit-frame-pointer
ubsan: LDFLAGS += -fsanitize=undefined
ubsan: clean all
	@echo "=== UBSAN: test_roundtrip ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) ./test_roundtrip || exit 1
	@echo ""
	@echo "=== UBSAN: test_errors ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) ./test_errors || exit 1
	@echo ""
	@echo "=== UBSAN: test_memory ==="
	$(LIB_PATH_VAR)=$(LIB_DIR) ./test_memory || exit 1
	@echo ""
	@echo "=== UBSAN: All tests passed! ==="

# Clean
clean:
	rm -f $(TEST_BINS)

.PHONY: all check-lib test valgrind asan ubsan clean