#!/usr/bin/make -f

%:
	dh $@

stubs ?= $(shell ls -1 stubs/)

execute_before_dh_auto_install:
	# Avoid using ~= relationship, which is later unable to be correctly processed.
	# There are two possibilities: '~= x.y.z' and '~=x.y.z'. Change them to 'x.y.z'.
	find stubs/ -name METADATA.toml -exec sed -i -e 's/~= //g' {} \;
	find stubs/ -name METADATA.toml -exec sed -i -e 's/~=//g' {} \;

override_dh_auto_install:
	dh_auto_install
	python3 debian/install_stubs.py $(stubs)
	find debian/python3-typeshed/ -name METADATA.toml -delete
	find debian/python3-typeshed/ -name direct_url.json -delete
	find debian/python3-typeshed/ -name RECORD -exec sed -i -e /direct_url.json/d '{}' ';'
	find debian/python3-typeshed/usr/lib/python3/dist-packages \
		-type f -executable -exec chmod -x '{}' ';'

override_dh_auto_clean:
	dh_auto_clean
	find . -name py.typed -delete

execute_before_dh_gencontrol:
	echo 'Now inserting the following substvars file:'
	@cat debian/python3-typeshed.substvars
