1PYTHON=python3
2LCOV_INFO=build/lcov.info
3LCOV_REPORT=build/lcov_report
4LCOV_REPORT_OPTIONS=--show-details -no-branch-coverage \
5	--title "python-ldap LCOV report"
6SCAN_REPORT=build/scan_report
7PYTHON_SUPP=/usr/share/doc/python3-devel/valgrind-python.supp
8
9
10.NOTPARALLEL:
11
12.PHONY: all
13all:
14
15Modules/constants_generated.h: Lib/ldap/constants.py
16	$(PYTHON) $^ > $@
17	indent Modules/constants_generated.h
18	rm -f Modules/constants_generated.h~
19
20.PHONY: clean
21clean:
22	rm -rf build dist *.egg-info .tox MANIFEST
23	rm -f .coverage .coverage.*
24	find . \( -name '*.py[co]' -or -name '*.so*' -or -name '*.dylib' \) \
25	    -delete
26	find . -depth -name __pycache__ -exec rm -rf {} \;
27
28build:
29	mkdir -p build
30
31# LCOV report (measuring test coverage for C code)
32.PHONY: lcov-clean lcov-coverage lcov-report lcov-open lcov
33lcov-clean:
34	rm -rf $(LCOV_INFO) $(LCOV_REPORT)
35	if [ -d build ]; then find build -name '*.gc??' -delete; fi
36
37lcov-coverage:
38	WITH_GCOV=1 tox -e py36
39
40$(LCOV_INFO): build
41	lcov --capture --directory build --output-file $(LCOV_INFO)
42
43$(LCOV_REPORT): $(LCOV_INFO)
44	genhtml --output-directory $(LCOV_REPORT) \
45		$(LCOV_REPORT_OPTIONS) $(LCOV_INFO)
46
47lcov-report: $(LCOV_REPORT)
48
49lcov-open: $(LCOV_REPORT)
50	xdg-open $(LCOV_REPORT)/index.html
51
52lcov: lcov-clean
53	$(MAKE) lcov-coverage
54	$(MAKE) lcov-report
55
56# clang-analyzer for static C code analysis
57.PHONY: scan-build
58scan-build:
59	scan-build -o $(SCAN_REPORT) --html-title="python-ldap scan report" \
60		-analyze-headers --view \
61		$(PYTHON) setup.py clean --all build
62
63# valgrind memory checker
64.PHONY: valgrind
65$(PYTHON_SUPP):
66	@ >&2 echo "valgrind-python.supp not found"
67	@ >&2 echo "install Python development files and run:"
68	@ >&2 echo "    $(MAKE) valgrind PYTHON_SUPP=/your/path/to/valgrind-python.supp"
69	exit 1;
70
71valgrind: build $(PYTHON_SUPP)
72	valgrind \
73	    --leak-check=full \
74	    --track-fds=yes \
75	    --suppressions=$(PYTHON_SUPP) \
76	    --suppressions=Misc/python-ldap.supp \
77	    --gen-suppressions=all \
78	    --log-file=build/valgrind.log \
79	    $(PYTHON) setup.py test
80
81	@grep -A7 "blocks are definitely lost" build/valgrind.log; \
82	if [ $$? == 0 ]; then \
83	    echo "Found definitive leak, see build/valgrind.log"; \
84	    exit 1; \
85	fi
86
87# Code autoformatter
88.PHONY: autoformat indent black black-check
89autoformat: indent black
90
91indent:
92	indent Modules/*.c Modules/*.h
93	rm -f Modules/*.c~ Modules/*.h~
94
95black:
96	$(PYTHON) -m black $(CURDIR)
97
98black-check:
99	$(PYTHON) -m black $(CURDIR) --check
100