#!/usr/bin/make -f

export PYBUILD_NAME=xsdata

%:
	dh $@ --with python3,sphinxdoc --buildsystem=pybuild

execute_after_dh_clean:
	rm -rf .pytest_cache
	rm -rf docs/api/reference/*
	rm -f $(PYBUILD_NAME).1

execute_before_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=$(CURDIR) python3 -m sphinx -b html -N docs $(CURDIR)/debian/python-xsdata-doc/usr/share/doc/python-xsdata-doc/html
endif

execute_after_dh_auto_install:
	PYTHONPATH=. help2man debian/python3-$(PYBUILD_NAME)/usr/bin/$(PYBUILD_NAME) \
	  --no-info \
	  --section 1 \
	  --name "$(shell grep '^Description' debian/control | head -n 1 | cut -d: -f2)" \
	  > $(PYBUILD_NAME).1
	# Not sure why help2man generate broken file here
	sed -i 's!xsdata,!xsdata!g' xsdata.1
	sed -i 's!XSDATA,!XSDATA!g' xsdata.1

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_PROFILES)),)
	dh_auto_test
endif
