#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.
#export DH_VERBOSE = 1

export PYBUILD_NAME=damo

%:
	dh $@ --buildsystem=pybuild

clean:
	rm -rf .pybuild
	[ -f pyproject.toml.orig ] && mv -f pyproject.toml.orig pyproject.toml || :
	rm -f setup.py
	rm -rf src
	rm -f debian/manpage/damo.1
	rm -f debian/damo.substvars
	rm -rf debian/damo/
	rm -rf debian/.debhelper
	rm -f debian/*debhelper*
	rm -f debian/files

execute_before_dh_auto_configure:
	# from packaging/build.sh
	mv pyproject.toml pyproject.toml.orig
	cp -p packaging/pyproject.toml .
	cp -p packaging/setup.py .
	mkdir -p src/damo
	cp -p *.py src/damo
	cp -p damo src/damo/damo.py
	# remove shebang from the newly copied damo.py
	sed -i '1{\@^#!/usr/bin/env python@d}' src/damo/damo.py
	touch -r damo src/damo/damo.py
	touch -r damo src/damo/__init__.py
	# regenerate manpage
	(cd debian/manpage; ./gen-manpage.sh)
