|
| 1 | +.PHONY: all build build-release test clean fmt fmt-check clippy check doc doc-open ci help pkgconfig install |
| 2 | + |
| 3 | +# Default target |
| 4 | +all: build |
| 5 | + |
| 6 | +# Build the project in debug mode |
| 7 | +build: |
| 8 | + cd rust_accumulator && cargo build |
| 9 | + |
| 10 | +# Build the project in release mode |
| 11 | +build-release: |
| 12 | + cd rust_accumulator && cargo build --release |
| 13 | + |
| 14 | +# Run tests |
| 15 | +test: |
| 16 | + cd rust_accumulator && cargo test |
| 17 | + |
| 18 | +# Format code using rustfmt |
| 19 | +fmt: |
| 20 | + cd rust_accumulator && cargo fmt |
| 21 | + |
| 22 | +# Check formatting |
| 23 | +fmt-check: |
| 24 | + cd rust_accumulator && cargo fmt --check |
| 25 | + |
| 26 | +# Run clippy linter |
| 27 | +clippy: |
| 28 | + cd rust_accumulator && cargo clippy -- -D warnings |
| 29 | + |
| 30 | +# Clean build artifacts |
| 31 | +clean: |
| 32 | + cd rust_accumulator && cargo clean |
| 33 | + |
| 34 | +# Check the project (quick verification without building) |
| 35 | +check: |
| 36 | + cd rust_accumulator && cargo check |
| 37 | + |
| 38 | +# Build documentation |
| 39 | +doc: |
| 40 | + cd rust_accumulator && cargo doc --no-deps |
| 41 | + |
| 42 | +# Open documentation in browser |
| 43 | +doc-open: |
| 44 | + cd rust_accumulator && cargo doc --no-deps --open |
| 45 | + |
| 46 | +# Run all checks (format, clippy, test) |
| 47 | +ci: fmt-check clippy test |
| 48 | + |
| 49 | +# Generate pkg-config file |
| 50 | +pkgconfig: build-release |
| 51 | + @if [ -z "$$INSTALL" ]; then \ |
| 52 | + echo "Error: INSTALL environment variable is not set."; \ |
| 53 | + echo "Please set INSTALL to the installation directory, e.g.: export INSTALL=/usr/local"; \ |
| 54 | + exit 1; \ |
| 55 | + fi |
| 56 | + @mkdir -p rust_accumulator/target/pkgconfig |
| 57 | + @VERSION=$$(grep '^version' rust_accumulator/Cargo.toml | head -1 | cut -d'"' -f2); \ |
| 58 | + sed -e "s|@PREFIX@|$$INSTALL|g" -e "s|@VERSION@|$$VERSION|g" \ |
| 59 | + librust_accumulator.pc.in > rust_accumulator/target/pkgconfig/librust_accumulator.pc |
| 60 | + @echo "pkg-config file created at rust_accumulator/target/pkgconfig/librust_accumulator.pc" |
| 61 | + |
| 62 | +# Install library and pkg-config file |
| 63 | +install: build-release pkgconfig |
| 64 | + @if [ -z "$$INSTALL" ]; then \ |
| 65 | + echo "Error: INSTALL environment variable is not set."; \ |
| 66 | + echo "Please set INSTALL to the installation directory, e.g.: export INSTALL=/usr/local"; \ |
| 67 | + exit 1; \ |
| 68 | + fi |
| 69 | + @echo "Installing to: $$INSTALL" |
| 70 | + install -d $$INSTALL/lib |
| 71 | + install -m 644 rust_accumulator/target/release/librust_accumulator.a $$INSTALL/lib/ |
| 72 | + install -d $$INSTALL/lib/pkgconfig |
| 73 | + install -m 644 rust_accumulator/target/pkgconfig/librust_accumulator.pc $$INSTALL/lib/pkgconfig/ |
| 74 | + @echo "Installation complete. Library installed to $$INSTALL/lib/" |
| 75 | + |
| 76 | +# Show help |
| 77 | +help: |
| 78 | + @echo "Available targets:" |
| 79 | + @echo " all - Build the project in debug mode (default)" |
| 80 | + @echo " build - Build the project in debug mode" |
| 81 | + @echo " build-release - Build the project in release mode" |
| 82 | + @echo " test - Run tests" |
| 83 | + @echo " fmt - Format code using rustfmt" |
| 84 | + @echo " fmt-check - Check if code is formatted correctly" |
| 85 | + @echo " clippy - Run clippy linter" |
| 86 | + @echo " check - Quick check without building" |
| 87 | + @echo " clean - Clean build artifacts" |
| 88 | + @echo " doc - Build documentation" |
| 89 | + @echo " doc-open - Build and open documentation in browser" |
| 90 | + @echo " ci - Run all checks (format, clippy, test)" |
| 91 | + @echo " pkgconfig - Generate pkg-config file (requires INSTALL env var)" |
| 92 | + @echo " install - Install library and pkg-config file (requires INSTALL env var)" |
| 93 | + @echo " help - Show this help message" |
0 commit comments