blob: 76a6d9c3e38d747d7f5b6b71d52e25bfad3580bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
|