Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
249 lines (200 loc) · 9.16 KB
/
Copy pathMakefile
File metadata and controls
249 lines (200 loc) · 9.16 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# Makefile for macOS Memory Benchmark
# Compiler and assembler
CXX = clang++
AS = as
# Keep one deployment target for production/test sources, assembly, and final
# links. Exporting the value also preserves it when coverage builds override
# compiler/linker flags. External static archives must not require a newer OS.
export MACOSX_DEPLOYMENT_TARGET ?= 26.0
# Source directory
SRC_DIR = src
# Google Test configuration
GTEST_DIR ?= /opt/homebrew/opt/googletest
GTEST_INCLUDE = $(GTEST_DIR)/include
GTEST_LIB_DIR = $(GTEST_DIR)/lib
GTEST_LIBS = -L$(GTEST_LIB_DIR) -lgtest -lgtest_main -pthread
# Flags for the C++ compiler
# -Wall: Enable most warnings
# -O3: High optimization level
# -std=c++17: Use C++17 standard (or newer, e.g., c++20)
# -arch arm64: Target architecture for Apple Silicon
# -pthread: Link the thread library (needed for std::thread)
# -I$(SRC_DIR): Look for headers in the src directory
CXXFLAGS = -Wall -O3 -std=c++17 -arch arm64 -pthread -I$(SRC_DIR)
# Test-specific flags (less optimization for faster compilation, debug symbols)
TEST_CXXFLAGS = -Wall -g -std=c++17 -arch arm64 -pthread -I$(SRC_DIR) -I$(GTEST_INCLUDE)
# Flags for the assembler
# -arch arm64: Target architecture
ASFLAGS = -arch arm64
# Linker flags (pthread is already in CXXFLAGS, but can be here too)
LDFLAGS = -pthread
# First-party frameworks used by the Objective-C++ platform boundaries.
APPLE_FRAMEWORKS = -framework Metal -framework Foundation
# Generate compiler dependency files next to C++ object files. Keeping this
# separate from CXXFLAGS ensures coverage builds still emit dependencies when
# they override the optimization/instrumentation flags.
DEPFLAGS = -MMD -MP -MF $(@:.o=.d) -MT $@
# Production sources are discovered from the governed source directories so a
# new translation unit cannot be present in the repository but absent from the
# build. The bundled third-party directory currently contains headers only and
# is excluded defensively.
CPP_SRCS_ROOT := main.cpp
CPP_SRCS_SRC := $(sort $(shell find $(SRC_DIR) -type f -name '*.cpp' ! -path '*/third_party/*'))
ALL_CPP_SRCS := $(CPP_SRCS_ROOT) $(CPP_SRCS_SRC)
# Objective-C++ production sources use the same automatic discovery policy.
OBJCXX_SRCS := $(sort $(shell find $(SRC_DIR) -type f -name '*.mm' ! -path '*/third_party/*'))
# Assembly source files (in src/asm)
ASM_SRCS := $(sort $(wildcard $(SRC_DIR)/asm/*.s))
# Object files (derived from source files, maintaining directory structure)
# main.cpp -> main.o
# src/timer.cpp -> src/timer.o
# memory_copy.s / memory_read.s / memory_write.s / memory_latency.s -> *.o
OBJ_FILES := $(ALL_CPP_SRCS:.cpp=.o) $(OBJCXX_SRCS:.mm=.o) $(ASM_SRCS:.s=.o)
# Target executable name
TARGET = memory_benchmark
# Default target: build the executable
all: $(TARGET)
# Recompute provenance before considering objects. A changed source revision,
# dirty state or build flags invalidates every object, avoiding mixed manifests.
export PROVENANCE_CXX = $(CXX)
export PROVENANCE_CXXFLAGS = $(CXXFLAGS)
export PROVENANCE_TEST_CXXFLAGS = $(TEST_CXXFLAGS)
export PROVENANCE_ASFLAGS = $(ASFLAGS)
export PROVENANCE_LDFLAGS = $(LDFLAGS) $(APPLE_FRAMEWORKS)
.build-provenance.h: FORCE
python3 build-support/generate_provenance.py $@
.PHONY: FORCE
FORCE:
# Rule for linking the executable from object files
$(TARGET): $(OBJ_FILES)
@echo "Linking $(TARGET)..."
$(CXX) $(OBJ_FILES) -o $(TARGET) $(LDFLAGS) $(APPLE_FRAMEWORKS)
@echo "$(TARGET) built successfully."
# Test directory and files
TEST_DIR = tests
TEST_SRCS := $(sort $(wildcard $(TEST_DIR)/*.cpp))
TEST_OBJCXX_SRCS := $(sort $(wildcard $(TEST_DIR)/*.mm))
TEST_OBJS := $(TEST_SRCS:.cpp=.o) $(TEST_OBJCXX_SRCS:.mm=.o)
# Dependency files generated by DEPFLAGS. Test dependencies include tests/*.h
# helpers through the compiler's actual include graph rather than a manually
# maintained header list.
PROD_DEP_FILES := $(ALL_CPP_SRCS:.cpp=.d) $(OBJCXX_SRCS:.mm=.d)
TEST_DEP_FILES := $(TEST_OBJS:.o=.d)
DEP_FILES := $(PROD_DEP_FILES) $(TEST_DEP_FILES)
# Test executable name
TEST_TARGET = test_runner
# Source files needed for tests (excluding main.cpp)
TEST_LIB_OBJS := $(filter-out main.o, $(OBJ_FILES))
# Recompile once after a Makefile change so an existing pre-dependency-file
# workspace cannot keep stale objects. Subsequent header changes are tracked by
# the generated .d files.
$(OBJ_FILES) $(TEST_OBJS): Makefile .build-provenance.h
# Rule for compiling test files (must come before generic %.o rule)
$(TEST_DIR)/%.o: $(TEST_DIR)/%.cpp
@echo "Compiling test $< -> $@..."
$(CXX) $(TEST_CXXFLAGS) $(DEPFLAGS) -c $< -o $@
# Objective-C++ tests retain test flags and ARC, including generated dependencies.
$(TEST_DIR)/%.o: $(TEST_DIR)/%.mm
@echo "Compiling Objective-C++ test $< -> $@..."
$(CXX) $(TEST_CXXFLAGS) -fobjc-arc $(DEPFLAGS) -c $< -o $@
# Objective-C++ production boundaries share the normal C++ build settings.
%.o: %.mm
@echo "Compiling Objective-C++ $< -> $@..."
$(CXX) $(CXXFLAGS) -fobjc-arc $(DEPFLAGS) -c $< -o $@
# One production C++ rule covers the root and every src subdirectory.
%.o: %.cpp
@echo "Compiling $< -> $@..."
$(CXX) $(CXXFLAGS) $(DEPFLAGS) -c $< -o $@
# Rule for assembling assembly source files in src/asm into object files
$(SRC_DIR)/asm/%.o: $(SRC_DIR)/asm/%.s
@echo "Assembling $< -> $@..."
$(AS) $(ASFLAGS) $< -o $@
# Test targets: build and run tests
# Unit tests only (excludes integration tests that perform actual system operations)
test: $(TEST_TARGET)
@echo "Running unit tests (excluding integration tests)..."
./$(TEST_TARGET) --gtest_filter=-*Integration*
# Integration tests only (tests that perform actual system operations)
test-integration: $(TARGET) $(TEST_TARGET)
@echo "Running integration tests..."
./$(TEST_TARGET) --gtest_filter=*Integration*
# Current-version bundled script examples (jq coverage is skipped when unavailable)
test-script-examples:
python3 -m unittest -v tests/test_script_examples.py
# Independent LLM artifact contract and mutation tests.
test-llm-verifier:
python3 -m unittest -v tests/test_llm_result_verifier.py
# All tests (unit, integration, bundled examples, and independent LLM verifier)
test-all: $(TARGET) $(TEST_TARGET)
@echo "Running all tests (unit + integration + bundled examples + LLM verifier)..."
./$(TEST_TARGET)
$(MAKE) test-script-examples
$(MAKE) test-llm-verifier
# Reproducible production C++ source coverage in an isolated /tmp build.
coverage-unit:
./coverage.sh unit
coverage-all:
./coverage.sh all
# Build test executable
$(TEST_TARGET): $(TEST_OBJS) $(TEST_LIB_OBJS)
@echo "Linking $(TEST_TARGET)..."
$(CXX) $(TEST_OBJS) $(TEST_LIB_OBJS) -o $(TEST_TARGET) $(GTEST_LIBS) $(LDFLAGS) $(APPLE_FRAMEWORKS)
@echo "$(TEST_TARGET) built successfully."
# Clean test files
clean-test:
@echo "Cleaning test files..."
rm -f $(TEST_TARGET) $(TEST_OBJS) $(TEST_DEP_FILES)
@echo "Test cleanup complete."
# Clean target: remove object files (from root and src/) and the executable
clean: clean-test
@echo "Cleaning up object files and target..."
rm -f $(TARGET) $(OBJ_FILES) $(PROD_DEP_FILES)
@echo "Cleanup complete."
# Documentation directory
DOCS_DIR = docs
# Doxygen configuration file
DOXYFILE = Doxyfile
# Generate Doxygen configuration file
$(DOXYFILE):
@echo "Generating $(DOXYFILE)..."
doxygen -g $(DOXYFILE)
@echo "Configuring $(DOXYFILE)..."
@sed -i '' 's|^PROJECT_NAME[[:space:]]*=.*|PROJECT_NAME = "macOS-memory-benchmark"|' $(DOXYFILE)
@sed -i '' 's|^PROJECT_BRIEF[[:space:]]*=.*|PROJECT_BRIEF = "Apple silicon memory benchmark console-tool."|' $(DOXYFILE)
@sed -i '' 's|^INPUT[[:space:]]*=.*|INPUT = $(SRC_DIR)|' $(DOXYFILE)
@sed -i '' 's|^RECURSIVE[[:space:]]*=.*|RECURSIVE = YES|' $(DOXYFILE)
@sed -i '' 's|^EXTRACT_ALL[[:space:]]*=.*|EXTRACT_ALL = YES|' $(DOXYFILE)
@sed -i '' 's|^GENERATE_HTML[[:space:]]*=.*|GENERATE_HTML = YES|' $(DOXYFILE)
@sed -i '' 's|^GENERATE_LATEX[[:space:]]*=.*|GENERATE_LATEX = NO|' $(DOXYFILE)
@sed -i '' 's|^OUTPUT_DIRECTORY[[:space:]]*=.*|OUTPUT_DIRECTORY = $(DOCS_DIR)|' $(DOXYFILE)
@echo "$(DOXYFILE) generated and configured."
# Generate documentation
docs: $(DOXYFILE)
@echo "Generating documentation..."
doxygen $(DOXYFILE)
@echo "Documentation generated in $(DOCS_DIR)/html/"
# Clean documentation
clean-docs:
@echo "Cleaning documentation..."
rm -rf $(DOCS_DIR) $(DOXYFILE)
@echo "Documentation cleanup complete."
# Installation prefix (can be overridden: make install PREFIX=/opt/local)
PREFIX = /usr/local
# Install target: install the executable to $(PREFIX)/bin
install: $(TARGET)
@echo "Installing $(TARGET) to $(PREFIX)/bin..."
@mkdir -p $(PREFIX)/bin
@cp $(TARGET) $(PREFIX)/bin/$(TARGET)
@chmod 755 $(PREFIX)/bin/$(TARGET)
@echo "$(TARGET) installed successfully to $(PREFIX)/bin/$(TARGET)"
# Uninstall target: remove the installed executable
uninstall:
@echo "Removing $(PREFIX)/bin/$(TARGET)..."
@rm -f $(PREFIX)/bin/$(TARGET)
@echo "$(TARGET) uninstalled successfully."
# Define targets that don't correspond to files
.PHONY: all clean test test-integration test-script-examples test-llm-verifier test-all \
coverage-unit coverage-all clean-test docs clean-docs install uninstall
# Missing dependency files are expected on a clean tree. Existing files carry
# the exact source and project/test-header prerequisites emitted by clang++.
-include $(DEP_FILES)