.PHONY: all build test clean format format-check size
all: build test
build:
@echo "๐จ Building..."
@cmake -B build -DCMAKE_BUILD_TYPE=Debug -DV4_BUILD_TESTS=ON
@cmake --build build -j
release:
@echo "๐ Building release..."
@cmake -B build-release -DCMAKE_BUILD_TYPE=Release -DV4_BUILD_TESTS=ON
@cmake --build build-release -j
test: build
@echo "๐งช Running tests..."
@cd build && ctest --output-on-failure
clean:
@echo "๐งน Cleaning..."
@rm -rf build build-release build-debug build-asan build-ubsan
format:
@echo "โจ Formatting C/C++ code..."
@find src include tests -type f \( -name '*.cpp' -o -name '*.hpp' -o -name '*.h' -o -name '*.c' \) \
-not -path "*/vendor/*" -exec clang-format -i {} \;
@echo "โจ Formatting CMake files..."
@find . -name 'CMakeLists.txt' -o -name '*.cmake' | xargs cmake-format -i
@echo "โ
Formatting complete!"
format-check:
@echo "๐ Checking C/C++ formatting..."
@find src include tests -type f \( -name '*.cpp' -o -name '*.hpp' -o -name '*.h' -o -name '*.c' \) \
-not -path "*/vendor/*" | xargs clang-format --dry-run --Werror || \
(echo "โ C/C++ formatting check failed." && exit 1)
@echo "๐ Checking CMake formatting..."
@find . -name 'CMakeLists.txt' -o -name '*.cmake' | xargs cmake-format --check || \
(echo "โ CMake formatting check failed." && exit 1)
@echo "โ
All formatting checks passed!"
asan: clean
@echo "๐ก๏ธ Building with AddressSanitizer..."
@cmake -B build-asan -DCMAKE_BUILD_TYPE=Debug -DV4_BUILD_TESTS=ON \
-DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer -g"
@cmake --build build-asan -j
@echo "๐งช Running tests with AddressSanitizer..."
@cd build-asan && ctest --output-on-failure
ubsan: clean
@echo "๐ก๏ธ Building with UndefinedBehaviorSanitizer..."
@cmake -B build-ubsan -DCMAKE_BUILD_TYPE=Debug -DV4_BUILD_TESTS=ON \
-DCMAKE_CXX_FLAGS="-fsanitize=undefined -fno-omit-frame-pointer -g"
@cmake --build build-ubsan -j
@echo "๐งช Running tests with UndefinedBehaviorSanitizer..."
@cd build-ubsan && ctest --output-on-failure
size:
@echo "๐ฆ Building release with size optimization..."
@cmake -B build-release -DCMAKE_BUILD_TYPE=Release -DV4_BUILD_TESTS=ON -DV4_OPTIMIZE_SIZE=ON
@cmake --build build-release -j
@echo ""
@echo "๐ Stripping and measuring binary sizes..."
@echo ""
@echo "=== Library ==="
@if [ -f build-release/libv4vm.a ]; then \
cp build-release/libv4vm.a build-release/libv4vm.stripped.a && \
strip --strip-debug build-release/libv4vm.stripped.a && \
ls -lh build-release/libv4vm.a build-release/libv4vm.stripped.a | awk '{print $$9 ": " $$5}'; \
fi
@echo ""
@echo "=== Test Executables (stripped) ==="
@for binary in build-release/test_*; do \
if [ -f "$$binary" ] && [ -x "$$binary" ]; then \
cp "$$binary" "$${binary}.stripped" && \
strip "$${binary}.stripped" && \
echo "$$(basename $$binary): $$(ls -lh $${binary}.stripped | awk '{print $$5}')"; \
fi \
done
@echo ""
@echo "โ
Size measurement complete!"