#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

override_dh_auto_build:
	dh_auto_build

	for py in $(shell py3versions -d); do \
		$$py setup.py build --force; \
	done

override_dh_auto_install:
	for py in $(shell py3versions -d); do \
		$$py setup.py install --force --root=$(CURDIR)/debian/tmp --no-compile -O0 --install-layout=deb; \
	done
	mv $(CURDIR)/debian/tmp/usr/bin/bpython \
		$(CURDIR)/debian/tmp/usr/bin/bpython3
	install -m644 -D $(CURDIR)/build/man/bpython.1 $(CURDIR)/debian/tmp/usr/share/man/man1/bpython3.1

	dh_auto_install

	mkdir -p $(CURDIR)/debian/tmp/usr/share/pixmaps/
	find $(CURDIR)/debian/tmp -name "logo.png" -exec mv {} $(CURDIR)/debian/tmp/usr/share/pixmaps/bpython.png \;

override_dh_install:
	dh_install
	dh_buildinfo
	mv $(CURDIR)/debian/bpython-gtk/usr/share/bpython/bpython-gtk \
		$(CURDIR)/debian/bpython-gtk/usr/share/bpython/bpython-gtk.py

	mv $(CURDIR)/debian/bpython-urwid/usr/share/bpython/urwid.py \
		$(CURDIR)/debian/bpython-urwid/usr/share/bpython/urwid_.py

override_dh_python2:
	dh_python2 -pbpython -pbython-urwid -pbpython-gtk
	find $(CURDIR)/debian/bpython/ -name "gtk_.py*" -delete
	find $(CURDIR)/debian/bpython/ -name "urwid.py*" -delete

override_dh_python3:
	dh_python3 -pbpython3 --shebang=/usr/bin/python3

override_dh_auto_clean:
	dh_auto_clean
	rm -rf bpython.egg-info build

	for py in $(shell py3versions -r); do \
		$$py setup.py clean -a; \
	done
	rm -rf bpython/__pycache__

%:
	dh $@ \
		--with python2 \
		--with python3
