.PHONY: all clean test build-lib build-tools build-api install help dev coverage memcheck CC := gcc CFLAGS := -Wall -Wextra -pedantic -std=c11 -O2 -I./src/third_party -I./src/libtikker/include DEBUG_FLAGS := -g -O0 -DDEBUG RELEASE_FLAGS := -O3 COVERAGE_FLAGS := -fprofile-arcs -ftest-coverage LDFLAGS := -lsqlite3 -lm INSTALL_PREFIX ?= /usr/local BUILD_DIR := ./build BIN_DIR := $(BUILD_DIR)/bin LIB_DIR := $(BUILD_DIR)/lib all: build-lib build-tools build-api @echo "✓ Complete build finished" help: @echo "Tikker Enterprise Build System" @echo "" @echo "Targets:" @echo " make all - Build everything (lib, tools, API)" @echo " make build-lib - Build libtikker static library" @echo " make build-tools - Build all CLI tools" @echo " make build-api - Setup Python API environment" @echo " make test - Run all tests" @echo " make coverage - Generate code coverage report" @echo " make memcheck - Run memory leak detection" @echo " make clean - Remove all build artifacts" @echo " make install - Install binaries" @echo " make dev - Build with debug symbols" @echo "" @echo "Environment Variables:" @echo " CC - C compiler (default: gcc)" @echo " CFLAGS - Compiler flags" @echo " INSTALL_PREFIX - Installation directory (default: /usr/local)" $(BIN_DIR): @mkdir -p $(BIN_DIR) $(LIB_DIR): @mkdir -p $(LIB_DIR) build-lib: $(LIB_DIR) @echo "Building libtikker library..." @cd src/libtikker && make LIB_DIR=../../$(LIB_DIR) CC="$(CC)" CFLAGS="$(CFLAGS)" @echo "✓ libtikker built" build-tools: build-lib $(BIN_DIR) @echo "Building CLI tools..." @cd src/tools/decoder && make BIN_DIR=../../$(BIN_DIR) LIB_DIR=../../$(LIB_DIR) CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" @cd src/tools/indexer && make BIN_DIR=../../$(BIN_DIR) LIB_DIR=../../$(LIB_DIR) CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" @cd src/tools/aggregator && make BIN_DIR=../../$(BIN_DIR) LIB_DIR=../../$(LIB_DIR) CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" @cd src/tools/report_gen && make BIN_DIR=../../$(BIN_DIR) LIB_DIR=../../$(LIB_DIR) CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" @echo "✓ All CLI tools built" build-api: @echo "Setting up Python API environment..." @if [ -f src/api/requirements.txt ]; then \ python3 -m pip install --quiet -r src/api/requirements.txt 2>/dev/null || true; \ echo "✓ Python dependencies installed"; \ else \ echo "⚠ No API requirements.txt found"; \ fi test: build-lib @echo "Running tests..." @cd tests && make CC="$(CC)" CFLAGS="$(CFLAGS)" @echo "✓ Tests completed" coverage: clean @echo "Building with coverage instrumentation..." @$(MAKE) CFLAGS="$(CFLAGS) $(COVERAGE_FLAGS)" test @echo "Generating coverage report..." @gcov src/libtikker/src/*.c 2>/dev/null || true @lcov --capture --directory . --output-file coverage.info 2>/dev/null || true @genhtml coverage.info --output-directory coverage_html 2>/dev/null || true @echo "✓ Coverage report generated in coverage_html/" memcheck: build-lib @echo "Running memory leak detection..." @valgrind --leak-check=full --show-leak-kinds=all \ ./$(BIN_DIR)/tikker-aggregator --help 2>&1 | tail -20 @echo "✓ Memory check completed" dev: CFLAGS += $(DEBUG_FLAGS) dev: clean all @echo "✓ Debug build completed" install: all @echo "Installing to $(INSTALL_PREFIX)..." @mkdir -p $(INSTALL_PREFIX)/bin @mkdir -p $(INSTALL_PREFIX)/lib @mkdir -p $(INSTALL_PREFIX)/include @install -m 755 $(BIN_DIR)/tikker-decoder $(INSTALL_PREFIX)/bin/ @install -m 755 $(BIN_DIR)/tikker-indexer $(INSTALL_PREFIX)/bin/ @install -m 755 $(BIN_DIR)/tikker-aggregator $(INSTALL_PREFIX)/bin/ @install -m 755 $(BIN_DIR)/tikker-report $(INSTALL_PREFIX)/bin/ @install -m 644 $(LIB_DIR)/libtikker.a $(INSTALL_PREFIX)/lib/ @install -m 644 src/libtikker/include/*.h $(INSTALL_PREFIX)/include/ @echo "✓ Installation complete" clean: @echo "Cleaning build artifacts..." @rm -rf $(BUILD_DIR) @find . -name "*.o" -delete @find . -name "*.a" -delete @find . -name "*.gcov" -delete @find . -name "*.gcda" -delete @find . -name "*.gcno" -delete @find . -name "gmon.out" -delete @rm -rf coverage.info coverage_html/ @echo "✓ Clean completed" .PHONY: help $(BIN_DIR) $(LIB_DIR)