-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
104 lines (81 loc) · 2.42 KB
/
Makefile
File metadata and controls
104 lines (81 loc) · 2.42 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
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
# C Profiler Makefile
# Builds the profiling library and example programs
CC = gcc
CFLAGS = -Wall -Wextra -O2 -std=c11
LDFLAGS = -lrt
# Library files
LIB_SRC = profiler.c
LIB_OBJ = profiler.o
LIB_STATIC = libprofiler.a
LIB_SHARED = libprofiler.so
# Example files
EXAMPLES = example1_basic example2_scoped example3_stats example4_logging example5_comprehensive
TESTS = test_overhead
# Default target
all: static examples tests
# Build static library
static: $(LIB_STATIC)
$(LIB_STATIC): $(LIB_OBJ)
ar rcs $@ $^
# Build shared library
shared: $(LIB_SHARED)
$(LIB_SHARED): $(LIB_SRC)
$(CC) $(CFLAGS) -fPIC -shared -o $@ $< $(LDFLAGS)
# Build object file
$(LIB_OBJ): $(LIB_SRC) profiler.h
$(CC) $(CFLAGS) -c -o $@ $<
# Build examples
examples: $(EXAMPLES)
# Build tests
tests: $(TESTS)
example1_basic: example1_basic.c $(LIB_STATIC)
$(CC) $(CFLAGS) -o $@ $< $(LIB_STATIC) $(LDFLAGS)
example2_scoped: example2_scoped.c $(LIB_STATIC)
$(CC) $(CFLAGS) -o $@ $< $(LIB_STATIC) $(LDFLAGS)
example3_stats: example3_stats.c $(LIB_STATIC)
$(CC) $(CFLAGS) -o $@ $< $(LIB_STATIC) $(LDFLAGS)
example4_logging: example4_logging.c $(LIB_STATIC)
$(CC) $(CFLAGS) -o $@ $< $(LIB_STATIC) $(LDFLAGS)
example5_comprehensive: example5_comprehensive.c $(LIB_STATIC)
$(CC) $(CFLAGS) -o $@ $< $(LIB_STATIC) $(LDFLAGS)
test_overhead: test_overhead.c $(LIB_STATIC)
$(CC) $(CFLAGS) -o $@ $< $(LIB_STATIC) $(LDFLAGS)
# Run all examples
run: examples
@echo "=== Running Example 1 ==="
./example1_basic
@echo ""
@echo "=== Running Example 2 ==="
./example2_scoped
@echo ""
@echo "=== Running Example 3 ==="
./example3_stats
@echo ""
@echo "=== Running Example 4 ==="
./example4_logging
@echo ""
@echo "=== Running Example 5 ==="
./example5_comprehensive
# Clean build artifacts
clean:
rm -f $(LIB_OBJ) $(LIB_STATIC) $(LIB_SHARED)
rm -f $(EXAMPLES) $(TESTS)
rm -f *.log
# Clean everything including logs
distclean: clean
rm -f profiler.log performance.log
# Install library (requires root)
install: static shared
install -d /usr/local/include
install -m 644 profiler.h /usr/local/include/
install -d /usr/local/lib
install -m 644 $(LIB_STATIC) /usr/local/lib/
install -m 755 $(LIB_SHARED) /usr/local/lib/
ldconfig
# Uninstall library (requires root)
uninstall:
rm -f /usr/local/include/profiler.h
rm -f /usr/local/lib/$(LIB_STATIC)
rm -f /usr/local/lib/$(LIB_SHARED)
ldconfig
.PHONY: all static shared examples tests run clean distclean install uninstall