diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..76a6d9c --- /dev/null +++ b/Makefile @@ -0,0 +1,117 @@ +# WMAP Parser Makefile +# ANSI C compatible library with clean build structure + +CC = gcc +CFLAGS_RELEASE = -ansi -pedantic -Wall -Wextra -O2 -fomit-frame-pointer +CFLAGS_DEBUG = -ansi -pedantic -Wall -Wextra -g -DDEBUG + +# Build configuration +CONFIGURATION ?= release +BUILD_DIR = ./build/$(CONFIGURATION) + +# Set CFLAGS based on build type +ifeq ($(CONFIGURATION),debug) + CFLAGS = $(CFLAGS_DEBUG) +else + CFLAGS = $(CFLAGS_RELEASE) +endif + +TARGET = $(BUILD_DIR)/wmap_test +SOURCES = src/test.c src/wmap_parser.c +OBJECTS = $(BUILD_DIR)/test.o $(BUILD_DIR)/wmap_parser.o +HEADERS = src/wmap_parser.h +EXAMPLE_FILE = doc/example.wmap +ITERATIONS ?= 100 + +# Default target +all: $(TARGET) + +# Create build directory if it doesn't exist +$(BUILD_DIR): + @mkdir -p $(BUILD_DIR) + +# Build the test program +$(TARGET): $(BUILD_DIR) $(OBJECTS) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS) + +# Object files +$(BUILD_DIR)/test.o: src/test.c $(HEADERS) + $(CC) $(CFLAGS) -c src/test.c -o $(BUILD_DIR)/test.o + +$(BUILD_DIR)/wmap_parser.o: src/wmap_parser.c $(HEADERS) + $(CC) $(CFLAGS) -c src/wmap_parser.c -o $(BUILD_DIR)/wmap_parser.o + +# Debug build (use CONFIGURATION=debug) +debug: + @$(MAKE) CONFIGURATION=debug + +# Release build (explicit) +release: + @$(MAKE) CONFIGURATION=release + +# Test the parser with the example file +test: $(TARGET) + @echo "=== Running parser test ===" + ./$(TARGET) $(EXAMPLE_FILE) + +# Run performance benchmark +benchmark: $(TARGET) + @echo "=== Running performance benchmark ===" + ./$(TARGET) $(EXAMPLE_FILE) benchmark $(ITERATIONS) + +# Memory test using valgrind (if available) +memtest: + @$(MAKE) CONFIGURATION=debug + @echo "=== Running memory test ===" + @if command -v valgrind >/dev/null 2>&1; then \ + valgrind --leak-check=full --show-leak-kinds=all ./build/debug/wmap_test $(EXAMPLE_FILE); \ + else \ + echo "Valgrind not available, running regular test"; \ + ./build/debug/wmap_test $(EXAMPLE_FILE); \ + fi + +# Profile the parser (if gprof available) +profile: + @$(MAKE) CFLAGS="$(CFLAGS_RELEASE) -pg" + @echo "=== Running profiling test ===" + ./$(TARGET) $(EXAMPLE_FILE) benchmark 100 + @if [ -f gmon.out ]; then \ + gprof $(TARGET) gmon.out > profile_report.txt; \ + echo "Profile report saved to profile_report.txt"; \ + else \ + echo "No profiling data generated"; \ + fi + +# Clean build artifacts +clean: + rm -rf ./build + rm -f gmon.out profile_report.txt + +# Show parser capabilities +info: + @echo "=== WMAP Parser Information ===" + @echo "Build type: $(CONFIGURATION)" + @echo "Build directory: $(BUILD_DIR)" + @echo "Max components: $(shell grep WMAP_MAX_COMPONENTS src/wmap_parser.h | cut -d' ' -f3)" + @echo "Max dependencies: $(shell grep WMAP_MAX_DEPENDENCIES src/wmap_parser.h | cut -d' ' -f3)" + @echo "Max name length: $(shell grep WMAP_MAX_NAME_LEN src/wmap_parser.h | cut -d' ' -f3)" + @echo "Compiler: $(CC)" + @echo "Flags: $(CFLAGS)" + @echo "" + @echo "Available targets:" + @echo " all - Build the parser (default: release)" + @echo " debug - Build debug version" + @echo " release - Build release version (explicit)" + @echo " test - Test with example.wmap" + @echo " benchmark - Performance benchmark" + @echo " memtest - Memory leak test (uses debug build)" + @echo " clean - Remove all build artifacts" + @echo "" + @echo "Build types:" + @echo " make # Release build -> ./build/release/" + @echo " make -e CONFIGURATION=debug # Debug build -> ./build/debug/" + +# Help target +help: info + +.PHONY: all debug release test benchmark memtest profile clean info help |