-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
60 lines (46 loc) · 1.82 KB
/
Copy pathMakefile
File metadata and controls
60 lines (46 loc) · 1.82 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
CXX = clang++
STD_VERSION = -std=c++2a
COMMON_FLAGS = -Wall -Wextra -I..
TEST_DEBUG_FLAGS = -g
TEST_SANITIZE_FLAGS = -fsanitize=address -fno-omit-frame-pointer
TEST_OPTIMIZE_FLAGS = -O1
TEST_CXXFLAGS = $(STD_VERSION) $(COMMON_FLAGS) $(TEST_DEBUG_FLAGS) $(TEST_SANITIZE_FLAGS) $(TEST_OPTIMIZE_FLAGS)
TEST_LDFLAGS = $(TEST_SANITIZE_FLAGS) # Sanitizer flags often needed at link time too
TEST_LIBS = -pthread # For std::thread, std::atomic
# Performance-specific flags
PERF_OPTIMIZE_FLAGS = -O3 -DNDEBUG # -DNDEBUG to disable asserts and other debug code
PERF_CXXFLAGS = $(STD_VERSION) $(COMMON_FLAGS) $(PERF_OPTIMIZE_FLAGS)
PERF_LDFLAGS =
PERF_LIBS = -pthread
TEST_RUNNER = test_runner
PERF_RUNNER = perf_runner
TEST_SOURCES = test/index.cxx
PERF_SOURCES = perf/index.cxx # Assuming your perf tests are here
.PHONY: all test perf clean
all: test perf
### Build and run tests
test: $(TEST_RUNNER)
@echo "Running tests..."
./$(TEST_RUNNER)
### Build the test runner
$(TEST_RUNNER): $(TEST_SOURCES) index.hxx
@echo "Building test runner..."
$(CXX) $(TEST_CXXFLAGS) $(TEST_SOURCES) -o $(TEST_RUNNER) $(TEST_LDFLAGS) $(TEST_LIBS)
### Build and run performance benchmarks
perf: $(PERF_RUNNER)
@echo "Running performance benchmarks..."
./$(PERF_RUNNER)
### Build the performance runner
$(PERF_RUNNER): $(PERF_SOURCES) index.hxx
@echo "Building performance runner..."
$(CXX) $(PERF_CXXFLAGS) $(PERF_SOURCES) -o $(PERF_RUNNER) $(PERF_LDFLAGS) $(PERF_LIBS)
### Clean up build artifacts
clean:
@echo "Cleaning up..."
rm -f $(TEST_RUNNER) $(PERF_RUNNER)
# Add any other object files or build artifacts if necessary: rm -f *.o
### Usage:
# make -> builds and runs tests, then builds and runs perf benchmarks
# make test -> builds and runs only tests
# make perf -> builds and runs only perf benchmarks
# make clean -> removes executables