.PHONY: all build release run test clean fmt help install # Project configuration PROJECT_NAME := jormundb ODIN := odin BUILD_DIR := build SRC_DIR := . # Docker configuration for test SDK TEST_SDK_IMAGE := your-dockerhub-username/odin-python-test-sdk TEST_SDK_TAG := latest JORMUN_PORT ?= 8002 # Build the test SDK Docker image .PHONY: build-test-sdk build-test-sdk: @echo "Building test SDK Docker image..." docker build -f Dockerfile_test_sdk -t $(TEST_SDK_IMAGE):$(TEST_SDK_TAG) . @echo "Test SDK image built successfully" # Push the test SDK image to registry .PHONY: push-test-sdk push-test-sdk: build-test-sdk @echo "Pushing test SDK image to registry..." docker push $(TEST_SDK_IMAGE):$(TEST_SDK_TAG) @echo "Test SDK image pushed successfully" # Pull the test SDK image from registry .PHONY: pull-test-sdk pull-test-sdk: @echo "Pulling test SDK image from registry..." docker pull $(TEST_SDK_IMAGE):$(TEST_SDK_TAG) # Run SDK tests in the consolidated container .PHONY: test-sdk test-sdk: @echo "Running SDK tests..." docker run --rm \ --network host \ -v $(PWD):/workspace \ -w /workspace \ -e JORMUN_ENDPOINT=http://localhost:$(JORMUN_PORT) \ -e AWS_ACCESS_KEY_ID=local \ -e AWS_SECRET_ACCESS_KEY=local \ -e AWS_DEFAULT_REGION=us-east-1 \ $(TEST_SDK_IMAGE):$(TEST_SDK_TAG) \ sh -c "make build && python tests/sdk/test_sdk.py" # Run SDK tests with live rebuild (for development) .PHONY: test-sdk-dev test-sdk-dev: @echo "Running SDK tests with live rebuild..." docker run --rm -it \ --network host \ -v $(PWD):/workspace \ -w /workspace \ -e JORMUN_ENDPOINT=http://localhost:$(JORMUN_PORT) \ -e AWS_ACCESS_KEY_ID=local \ -e AWS_SECRET_ACCESS_KEY=local \ -e AWS_DEFAULT_REGION=us-east-1 \ $(TEST_SDK_IMAGE):$(TEST_SDK_TAG) \ /bin/bash # One-time setup: build and push test SDK image .PHONY: setup-test-sdk setup-test-sdk: build-test-sdk push-test-sdk @echo "Test SDK setup complete" # C++ shim (WAL replication helpers via RocksDB C++ API) SHIM_DIR := rocksdb_shim SHIM_LIB := $(BUILD_DIR)/libjormun_rocksdb_shim.a SHIM_SRCS := $(SHIM_DIR)/rocksdb_shim.cc SHIM_HDRS := $(SHIM_DIR)/rocksdb_shim.h CXX := g++ AR := ar CXXFLAGS := -O2 -fPIC -std=c++20 $(INCLUDE_PATH) # name of the docker compose file for the python tests SDK_TEST_COMPOSE := docker-compose-python-sdk-test.yaml # RocksDB and compression libraries ROCKSDB_LIBS := -lrocksdb -lstdc++ -lsnappy -llz4 -lzstd -lz -lbz2 # Platform-specific library paths UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) # macOS (Homebrew) LIB_PATH := -L/usr/local/lib -L/opt/homebrew/lib INCLUDE_PATH := -I/usr/local/include -I/opt/homebrew/include else ifeq ($(UNAME_S),Linux) # Linux LIB_PATH := -L/usr/local/lib -L/usr/lib INCLUDE_PATH := -I/usr/local/include endif # Build flags DEBUG_FLAGS := -debug -o:none RELEASE_FLAGS := -o:speed -disable-assert -no-bounds-check COMMON_FLAGS := -vet -strict-style # Linker flags EXTRA_LINKER_FLAGS := $(LIB_PATH) $(SHIM_LIB) $(ROCKSDB_LIBS) # Runtime configuration PORT ?= 8002 HOST ?= 0.0.0.0 DATA_DIR ?= ./data VERBOSE ?= 0 # Colors for output BLUE := \033[0;34m GREEN := \033[0;32m YELLOW := \033[0;33m RED := \033[0;31m NC := \033[0m # No Color $(SHIM_LIB): $(SHIM_SRCS) $(SHIM_HDRS) | $(BUILD_DIR) @echo "$(BLUE)Building RocksDB C++ shim...$(NC)" $(CXX) $(CXXFLAGS) -c $(SHIM_SRCS) -o $(BUILD_DIR)/rocksdb_shim.o $(AR) rcs $(SHIM_LIB) $(BUILD_DIR)/rocksdb_shim.o @echo "$(GREEN)✓ Built: $(SHIM_LIB)$(NC)" $(BUILD_DIR): @mkdir -p $(BUILD_DIR) # Default target all: build # Build debug version build: $(SHIM_LIB) @echo "$(BLUE)Building $(PROJECT_NAME) (debug)...$(NC)" @mkdir -p $(BUILD_DIR) $(ODIN) build $(SRC_DIR) \ $(COMMON_FLAGS) \ $(DEBUG_FLAGS) \ -out:$(BUILD_DIR)/$(PROJECT_NAME) \ -extra-linker-flags:"$(EXTRA_LINKER_FLAGS)" @echo "$(GREEN)✓ Build complete: $(BUILD_DIR)/$(PROJECT_NAME)$(NC)" # Build optimized release version release: $(SHIM_LIB) @echo "$(BLUE)Building $(PROJECT_NAME) (release)...$(NC)" @mkdir -p $(BUILD_DIR) $(ODIN) build $(SRC_DIR) \ $(COMMON_FLAGS) \ $(RELEASE_FLAGS) \ -out:$(BUILD_DIR)/$(PROJECT_NAME) \ -extra-linker-flags:"$(EXTRA_LINKER_FLAGS)" @echo "$(GREEN)✓ Release build complete: $(BUILD_DIR)/$(PROJECT_NAME)$(NC)" # Run the server run: build @echo "$(BLUE)Starting $(PROJECT_NAME)...$(NC)" @mkdir -p $(DATA_DIR) @JORMUN_PORT=$(PORT) \ JORMUN_HOST=$(HOST) \ JORMUN_DATA_DIR=$(DATA_DIR) \ JORMUN_VERBOSE=$(VERBOSE) \ $(BUILD_DIR)/$(PROJECT_NAME) # Run with custom port run-port: build @echo "$(BLUE)Starting $(PROJECT_NAME) on port $(PORT)...$(NC)" @mkdir -p $(DATA_DIR) @JORMUN_PORT=$(PORT) $(BUILD_DIR)/$(PROJECT_NAME) # Run tests test: @echo "$(BLUE)Running tests...$(NC)" $(ODIN) test $(SRC_DIR) \ $(COMMON_FLAGS) \ $(DEBUG_FLAGS) \ -extra-linker-flags:"$(EXTRA_LINKER_FLAGS)" @echo "$(GREEN)✓ Tests passed$(NC)" # Format code fmt: @echo "$(BLUE)Formatting code...$(NC)" @find $(SRC_DIR) -name "*.odin" -exec odin-format -w {} \; @echo "$(GREEN)✓ Code formatted$(NC)" # Clean build artifacts clean: @echo "$(YELLOW)Cleaning build artifacts...$(NC)" @rm -rf $(BUILD_DIR) @rm -rf $(DATA_DIR) @echo "$(GREEN)✓ Clean complete$(NC)" # Install to /usr/local/bin (requires sudo) install: release @echo "$(BLUE)Installing $(PROJECT_NAME)...$(NC)" @sudo cp $(BUILD_DIR)/$(PROJECT_NAME) /usr/local/bin/ @sudo chmod +x /usr/local/bin/$(PROJECT_NAME) @echo "$(GREEN)✓ Installed to /usr/local/bin/$(PROJECT_NAME)$(NC)" # Uninstall from /usr/local/bin uninstall: @echo "$(YELLOW)Uninstalling $(PROJECT_NAME)...$(NC)" @sudo rm -f /usr/local/bin/$(PROJECT_NAME) @echo "$(GREEN)✓ Uninstalled$(NC)" # Check dependencies check-deps: @echo "$(BLUE)Checking dependencies...$(NC)" @which $(ODIN) > /dev/null || (echo "$(RED)✗ Odin compiler not found$(NC)" && exit 1) @pkg-config --exists rocksdb || (echo "$(RED)✗ RocksDB not found$(NC)" && exit 1) @echo "$(GREEN)✓ All dependencies found$(NC)" # AWS CLI test commands aws-test: run & @sleep 2 @echo "$(BLUE)Testing with AWS CLI...$(NC)" @echo "\n$(YELLOW)Creating table...$(NC)" @aws dynamodb create-table \ --endpoint-url http://localhost:$(PORT) \ --table-name TestTable \ --key-schema AttributeName=pk,KeyType=HASH \ --attribute-definitions AttributeName=pk,AttributeType=S \ --billing-mode PAY_PER_REQUEST || true @echo "\n$(YELLOW)Listing tables...$(NC)" @aws dynamodb list-tables --endpoint-url http://localhost:$(PORT) @echo "\n$(YELLOW)Putting item...$(NC)" @aws dynamodb put-item \ --endpoint-url http://localhost:$(PORT) \ --table-name TestTable \ --item '{"pk":{"S":"test1"},"data":{"S":"hello world"}}' @echo "\n$(YELLOW)Getting item...$(NC)" @aws dynamodb get-item \ --endpoint-url http://localhost:$(PORT) \ --table-name TestTable \ --key '{"pk":{"S":"test1"}}' @echo "\n$(YELLOW)Scanning table...$(NC)" @aws dynamodb scan \ --endpoint-url http://localhost:$(PORT) \ --table-name TestTable @echo "\n$(GREEN)✓ AWS CLI test complete$(NC)" # Development workflow dev: clean build run # Quick rebuild and run quick: @$(MAKE) build run # Show help help: @echo "$(BLUE)JormunDB - DynamoDB-compatible database$(NC)" @echo "" @echo "$(GREEN)Build Commands:$(NC)" @echo " make build - Build debug version" @echo " make release - Build optimized release version" @echo " make clean - Remove build artifacts" @echo "" @echo "$(GREEN)Run Commands:$(NC)" @echo " make run - Build and run server (default: localhost:8002)" @echo " make run PORT=9000 - Run on custom port" @echo " make dev - Clean, build, and run" @echo " make quick - Fast rebuild and run" @echo "" @echo "$(GREEN)Test Commands:$(NC)" @echo " make test - Run unit tests" @echo " make aws-test - Test with AWS CLI commands" @echo "" @echo "$(GREEN)Utility Commands:$(NC)" @echo " make fmt - Format source code" @echo " make check-deps - Check for required dependencies" @echo " make install - Install to /usr/local/bin (requires sudo)" @echo " make uninstall - Remove from /usr/local/bin" @echo "" @echo "$(GREEN)Configuration:$(NC)" @echo " PORT=$(PORT) - Server port" @echo " HOST=$(HOST) - Bind address" @echo " DATA_DIR=$(DATA_DIR) - RocksDB data directory" @echo " VERBOSE=$(VERBOSE) - Enable verbose logging (0/1)" @echo "" @echo "$(GREEN)Examples:$(NC)" @echo " make run PORT=9000" @echo " make run DATA_DIR=/tmp/jormun VERBOSE=1" @echo " make dev"