|
| 1 | +.PHONY: help build release test clean install uninstall fmt check clippy lint ci demo all |
| 2 | + |
| 3 | +# Detect OS - works on Windows (no uname) and Unix |
| 4 | +UNAME := $(shell uname -s 2>NUL) |
| 5 | +ifneq ($(UNAME),) |
| 6 | + DETECTED_OS := $(UNAME) |
| 7 | + BINARY := target/release/pik |
| 8 | + DEBUG_BINARY := target/debug/pik |
| 9 | + NULL_DEVICE := /dev/null |
| 10 | + WHICH := which |
| 11 | +else |
| 12 | + DETECTED_OS := Windows |
| 13 | + BINARY := target\release\pik.exe |
| 14 | + DEBUG_BINARY := target\debug\pik.exe |
| 15 | + NULL_DEVICE := NUL |
| 16 | + WHICH := where |
| 17 | +endif |
| 18 | + |
| 19 | +# Default target |
| 20 | +help: |
| 21 | + @echo "pik - Makefile targets (OS: $(DETECTED_OS))" |
| 22 | + @echo "" |
| 23 | + @echo "Development:" |
| 24 | + @echo " make build Build debug binary" |
| 25 | + @echo " make release Build optimized binary" |
| 26 | + @echo " make test Run all tests" |
| 27 | + @echo " make fmt Format code" |
| 28 | + @echo " make clippy Run clippy lints" |
| 29 | + @echo " make check Run fmt + clippy + test" |
| 30 | + @echo " make ci Full CI check (fmt check + clippy + test)" |
| 31 | + @echo "" |
| 32 | + @echo "Installation:" |
| 33 | + @echo " make install Install binary to cargo bin" |
| 34 | + @echo " make uninstall Remove installed binary" |
| 35 | + @echo "" |
| 36 | + @echo "Cleanup:" |
| 37 | + @echo " make clean Remove build artifacts" |
| 38 | + @echo "" |
| 39 | + @echo "Demo:" |
| 40 | + @echo " make demo Generate demo.gif (requires VHS)" |
| 41 | + @echo "" |
| 42 | + @echo "Shortcuts:" |
| 43 | + @echo " make all Same as: make check" |
| 44 | + @echo " make lint Same as: make clippy" |
| 45 | + |
| 46 | +# Build debug binary |
| 47 | +build: |
| 48 | + @echo "Building debug binary..." |
| 49 | + @cargo build |
| 50 | + @echo "✓ Debug build complete: $(DEBUG_BINARY)" |
| 51 | + |
| 52 | +# Build optimized release binary |
| 53 | +release: |
| 54 | + @echo "Building release binary..." |
| 55 | + @cargo build --release |
| 56 | + @echo "✓ Release build complete: $(BINARY)" |
| 57 | + |
| 58 | +# Run all tests |
| 59 | +test: |
| 60 | + @echo "Running tests..." |
| 61 | + @cargo test --all-targets |
| 62 | + @echo "✓ All tests passed" |
| 63 | + |
| 64 | +# Format code |
| 65 | +fmt: |
| 66 | + @echo "Formatting code..." |
| 67 | + @cargo fmt |
| 68 | + @echo "✓ Code formatted" |
| 69 | + |
| 70 | +# Check formatting without modifying files |
| 71 | +fmt-check: |
| 72 | + @echo "Checking code format..." |
| 73 | + @cargo fmt -- --check |
| 74 | + @echo "✓ Code format verified" |
| 75 | + |
| 76 | +# Run clippy |
| 77 | +clippy: |
| 78 | + @echo "Running clippy..." |
| 79 | + @cargo clippy --all-targets -- -D warnings |
| 80 | + @echo "✓ Clippy checks passed" |
| 81 | + |
| 82 | +# Alias for clippy |
| 83 | +lint: clippy |
| 84 | + |
| 85 | +# Quick check (format + lint + test) |
| 86 | +check: fmt clippy test |
| 87 | + @echo "" |
| 88 | + @echo "✓✓✓ All checks passed ✓✓✓" |
| 89 | + |
| 90 | +# Full CI check (non-modifying format check + clippy + test) |
| 91 | +ci: fmt-check clippy test |
| 92 | + @echo "" |
| 93 | + @echo "✓✓✓ CI checks passed ✓✓✓" |
| 94 | + |
| 95 | +# Install binary |
| 96 | +install: |
| 97 | + @echo "Installing pik..." |
| 98 | + @cargo install --path . |
| 99 | + @echo "✓ Installed to cargo bin directory" |
| 100 | + @$(WHICH) pik >$(NULL_DEVICE) 2>&1 && $(WHICH) pik || echo "Note: Make sure cargo bin is in PATH" |
| 101 | + |
| 102 | +# Uninstall binary |
| 103 | +uninstall: |
| 104 | + @echo "Uninstalling pik..." |
| 105 | + @cargo uninstall pik |
| 106 | + @echo "✓ Uninstalled" |
| 107 | + |
| 108 | +# Clean build artifacts |
| 109 | +clean: |
| 110 | + @echo "Cleaning build artifacts..." |
| 111 | + @cargo clean |
| 112 | + @echo "✓ Cleaned" |
| 113 | + |
| 114 | +# Generate demo (requires VHS) |
| 115 | +demo: |
| 116 | + @echo "Generating demo.gif..." |
| 117 | +ifdef OS |
| 118 | + ifeq ($(OS),Windows_NT) |
| 119 | + @where vhs >$(NULL_DEVICE) 2>&1 || (echo Error: VHS not found. Install from https://github.com/charmbracelet/vhs && exit 1) |
| 120 | + else |
| 121 | + @command -v vhs >$(NULL_DEVICE) 2>&1 || { echo "Error: VHS not found. Install from https://github.com/charmbracelet/vhs"; exit 1; } |
| 122 | + endif |
| 123 | +else |
| 124 | + @command -v vhs >$(NULL_DEVICE) 2>&1 || { echo "Error: VHS not found. Install from https://github.com/charmbracelet/vhs"; exit 1; } |
| 125 | +endif |
| 126 | + @vhs demo.tape |
| 127 | + @echo "✓ Demo generated: demo.gif" |
| 128 | + |
| 129 | +# Default: run all checks |
| 130 | +all: check |
| 131 | + |
| 132 | +# Development workflow: watch and test (requires cargo-watch) |
| 133 | +watch: |
| 134 | +ifdef OS |
| 135 | + ifeq ($(OS),Windows_NT) |
| 136 | + @where cargo-watch >$(NULL_DEVICE) 2>&1 || (echo Installing cargo-watch... && cargo install cargo-watch) |
| 137 | + else |
| 138 | + @command -v cargo-watch >$(NULL_DEVICE) 2>&1 || { echo "Installing cargo-watch..."; cargo install cargo-watch; } |
| 139 | + endif |
| 140 | +else |
| 141 | + @command -v cargo-watch >$(NULL_DEVICE) 2>&1 || { echo "Installing cargo-watch..."; cargo install cargo-watch; } |
| 142 | +endif |
| 143 | + @cargo watch -x test |
| 144 | + |
| 145 | +# Show binary size |
| 146 | +size: release |
| 147 | + @echo "" |
| 148 | + @echo "Binary size:" |
| 149 | +ifdef OS |
| 150 | + ifeq ($(OS),Windows_NT) |
| 151 | + @powershell -Command "Get-Item $(BINARY) | Select-Object Name, @{Name='Size';Expression={'{0:N2} KB' -f ($_.Length / 1KB)}}" |
| 152 | + else |
| 153 | + @ls -lh $(BINARY) | awk '{print $$5 "\t" $$NF}' |
| 154 | + endif |
| 155 | +else |
| 156 | + @ls -lh $(BINARY) | awk '{print $$5 "\t" $$NF}' |
| 157 | +endif |
| 158 | + |
| 159 | +# Benchmark build time |
| 160 | +bench-build: |
| 161 | + @echo "Benchmarking clean release build..." |
| 162 | + @cargo clean |
| 163 | +ifeq ($(DETECTED_OS),Windows) |
| 164 | + @powershell -Command "Measure-Command { cargo build --release | Out-Default } | Select-Object TotalSeconds" |
| 165 | +else |
| 166 | + @time cargo build --release |
| 167 | +endif |
| 168 | + |
| 169 | +# Run a quick smoke test |
| 170 | +smoke: release |
| 171 | + @echo "Running smoke test..." |
| 172 | + @echo "Note: This requires manual interaction - press Ctrl+C to cancel" |
| 173 | +ifeq ($(DETECTED_OS),Windows) |
| 174 | + @echo option1& echo option2& echo option3 | $(BINARY) || echo "Manual verification needed" |
| 175 | +else |
| 176 | + @echo -e "option1\noption2\noption3" | $(BINARY) || echo "Manual verification needed" |
| 177 | +endif |
| 178 | + @echo "✓ Smoke test setup complete" |
| 179 | + |
0 commit comments