#!/usr/bin/make -f

export PYBUILD_NAME = gunicorn
export PYBUILD_AFTER_TEST=rm -f {build_dir}/coverage.xml
#
# Skip signal test if not run by autopkgtest and skipp tests that are flaky on
# slower archtictures.
ifeq ($(origin PYBUILD_AUTOPKGTEST),undefined)
export PYBUILD_TEST_ARGS=--ignore=tests/test_signal_integration.py --ignore=tests/test_control_socket_integration.py --deselect 'tests/test_http2_live.py::test_plain_request[gevent]' --deselect 'tests/test_http2_live.py::test_control_frame_flood_does_not_wedge_the_connection'
else
export PYBUILD_TEST_ARGS=--deselect 'tests/test_http2_live.py::test_plain_request[gevent]' --deselect 'tests/test_http2_live.py::test_control_frame_flood_does_not_wedge_the_connection'
endif

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_auto_install:
	mkdir -p $(CURDIR)/debian/gunicorn/usr/bin
	mv $(CURDIR)/debian/python3-gunicorn/usr/bin/gunicorn* $(CURDIR)/debian/gunicorn/usr/bin

execute_after_dh_installexamples:
	find \
		$(CURDIR)/debian/gunicorn-examples/usr/share/doc/gunicorn-examples/examples \
		-type f \
		-name ".gitignore" \
		-delete
	find \
		$(CURDIR)/debian/gunicorn-examples/usr/share/doc/gunicorn-examples/examples \
		-type f \
		-executable \
		-print0 | xargs -0r chmod -x

override_dh_mkdocs:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=$$(pybuild --print build_dir --name gunicorn -p $$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")') | awk -F ': ' 'NR==1{print $$2}') mkdocs build -d $(CURDIR)/debian/python-gunicorn-doc/usr/share/doc/python-gunicorn-doc/html
	$(RM) -f $(CURDIR)/debian/python-gunicorn-doc/usr/share/doc/python-gunicorn-doc/html/sitemap.xml.gz
endif
	dh_mkdocs --theme-package mkdocs-material

execute_before_dh_installman:
	PYTHONPATH=$$(pybuild --print build_dir --name gunicorn -p $$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")') | awk -F ': ' 'NR==1{print $$2}') help2man --no-discard-stderr -n "HTTP/WSGI/ASGI server" $(CURDIR)/debian/gunicorn/usr/bin/gunicorn >gunicorn.1
	PYTHONPATH=$$(pybuild --print build_dir --name gunicorn -p $$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")') | awk -F ': ' 'NR==1{print $$2}') help2man --no-discard-stderr -n "gunicorn control client" $(CURDIR)/debian/gunicorn/usr/bin/gunicornc >gunicornc.1
