Makefile · 3825 bytes Raw Blame History
1 # Makefile for sultree
2 # A SELinux-aware tree command
3
4 PYTHON = python3
5 PACKAGE = sultree
6 VERSION = 0.0.8
7
8 .PHONY: help build install uninstall test clean dist rpm dev-install check format
9
10 help:
11 @echo "Available targets:"
12 @echo " build - Build the package"
13 @echo " install - Install the package"
14 @echo " uninstall - Uninstall the package"
15 @echo " dev-install - Install in development mode"
16 @echo " test - Run tests"
17 @echo " check - Run code quality checks"
18 @echo " format - Format code"
19 @echo " clean - Clean build artifacts"
20 @echo " dist - Create distribution package"
21 @echo " rpm - Build RPM package"
22
23 build:
24 $(PYTHON) -m build
25
26 install:
27 $(PYTHON) -m pip install .
28
29 uninstall:
30 @echo "Uninstalling $(PACKAGE)..."
31 $(PYTHON) -m pip uninstall $(PACKAGE) -y || echo "Package not installed via pip"
32 @echo "Removing any remaining executables..."
33 @rm -f ~/.local/bin/$(PACKAGE) 2>/dev/null || true
34 @echo "Uninstall complete!"
35
36 dev-install:
37 $(PYTHON) -m pip install -e .[dev]
38
39 test:
40 PYTHONPATH=src $(PYTHON) -m unittest discover tests -v
41
42 check:
43 @echo "Running security checks..."
44 @command -v bandit >/dev/null 2>&1 && bandit -r src/ || echo "bandit not available - install with: pip install bandit"
45 @echo "Running type checking..."
46 @command -v mypy >/dev/null 2>&1 && mypy src/ || echo "mypy not available - install with: pip install mypy"
47 @echo "Running lint checks..."
48 @command -v flake8 >/dev/null 2>&1 && flake8 src/ || echo "flake8 not available - install with: pip install flake8"
49
50 format:
51 @command -v black >/dev/null 2>&1 && black src/ tests/ || echo "black not available - install with: pip install black"
52
53 clean:
54 rm -rf build/
55 rm -rf dist/
56 rm -rf src/$(PACKAGE).egg-info/
57 find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
58 find . -type f -name "*.pyc" -delete
59 find . -type f -name "*.pyo" -delete
60 rm -f $(PACKAGE)-$(VERSION).tar.gz
61
62 dist: clean
63 $(PYTHON) -m build
64 tar czf $(PACKAGE)-$(VERSION).tar.gz \
65 --exclude='.git*' \
66 --exclude='*.pyc' \
67 --exclude='__pycache__' \
68 --exclude='build' \
69 --exclude='dist' \
70 --transform 's,^,$(PACKAGE)-$(VERSION)/,' \
71 src/ tests/ *.py *.toml *.md *.spec Makefile sultree
72
73 rpm: dist
74 @echo "Building RPM package..."
75 @command -v rpmbuild >/dev/null 2>&1 || (echo "rpmbuild not available - install rpm-build package" && exit 1)
76 mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
77 cp $(PACKAGE)-$(VERSION).tar.gz ~/rpmbuild/SOURCES/
78 cp $(PACKAGE).spec ~/rpmbuild/SPECS/
79 rpmbuild -ba ~/rpmbuild/SPECS/$(PACKAGE).spec
80 @echo "RPM packages created in ~/rpmbuild/RPMS/"
81
82 # Performance testing
83 perf-test:
84 @echo "Running performance tests..."
85 @time ./sultree -L 2 /usr >/dev/null
86 @echo "Testing with SELinux filtering..."
87 @time ./sultree -S "*_t" -L 2 /etc >/dev/null
88
89 # Cache performance info
90 cache-info:
91 @$(PYTHON) -c "import sys; sys.path.insert(0, 'src'); from sultree.selinux import get_cache_info; info = get_cache_info(); print('SELinux Context Cache Performance:'); print(f' Hits: {info[\"context_cache\"][\"hits\"]}'); print(f' Misses: {info[\"context_cache\"][\"misses\"]}'); print(f' Hit Rate: {info[\"context_cache\"][\"hit_rate\"]:.2%}'); print(f' Current Size: {info[\"context_cache\"][\"currsize\"]}/{info[\"context_cache\"][\"maxsize\"]}')"
92
93 # Smoke test - basic functionality verification
94 smoke-test:
95 @echo "Running smoke tests..."
96 @./sultree --version
97 @./sultree --help >/dev/null
98 @./sultree -L 1 . >/dev/null && echo "✓ Basic tree functionality works"
99 @./sultree -d -L 1 /etc >/dev/null && echo "✓ Directory-only mode works"
100 @./sultree -S "*_t" -L 1 /etc >/dev/null && echo "✓ SELinux filtering works" || echo "⚠ SELinux filtering may not be available"
101 @echo "All smoke tests passed!"
102
103 all: clean build test check