-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
74 lines (58 loc) · 1.84 KB
/
Makefile
File metadata and controls
74 lines (58 loc) · 1.84 KB
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
# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -std=c11 -O2 -g
LDFLAGS = -pthread
# Source files
ALLOCATOR_SRCS = allocator.c allocator_ts.c
ALLOCATOR_OBJS = $(ALLOCATOR_SRCS:.c=.o)
# Targets
LIB = liballocator.a
TEST_PROG = test
BENCH_PROG = benchmark
EXAMPLE_PROG = example
.PHONY: all clean run-test run-bench run-example valgrind
all: $(LIB) $(TEST_PROG) $(BENCH_PROG) $(EXAMPLE_PROG)
# Build static library
$(LIB): $(ALLOCATOR_OBJS)
ar rcs $@ $^
# Build test program
$(TEST_PROG): test.o $(LIB)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# Build benchmark program
$(BENCH_PROG): benchmark.o $(LIB)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# Build example program
$(EXAMPLE_PROG): example.o $(LIB)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
# Compile object files
%.o: %.c allocator.h
$(CC) $(CFLAGS) -c $< -o $@
# Run tests
run-test: $(TEST_PROG)
./$(TEST_PROG)
# Run benchmarks
run-bench: $(BENCH_PROG)
./$(BENCH_PROG)
# Run example
run-example: $(EXAMPLE_PROG)
./$(EXAMPLE_PROG)
# Run with Valgrind
valgrind: $(TEST_PROG)
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(TEST_PROG)
# Run benchmark with Valgrind
valgrind-bench: $(BENCH_PROG)
valgrind --leak-check=full --show-leak-kinds=all ./$(BENCH_PROG)
# Clean build artifacts
clean:
rm -f $(ALLOCATOR_OBJS) test.o benchmark.o example.o $(LIB) $(TEST_PROG) $(BENCH_PROG) $(EXAMPLE_PROG)
# Help
help:
@echo "Custom Memory Allocator - Build Targets"
@echo "======================================="
@echo "make all - Build library and all programs"
@echo "make run-test - Build and run tests"
@echo "make run-bench - Build and run benchmarks"
@echo "make run-example - Build and run example program"
@echo "make valgrind - Run tests with Valgrind"
@echo "make valgrind-bench - Run benchmarks with Valgrind"
@echo "make clean - Remove build artifacts"