#!/usr/bin/make -f

# The following bundled files break the build process by conflicting
# with system copies. Temporarily move them.
BACKUP_FILES = tweepy/oauth.py
BACKED_UP_FILES = $(BACKUP_FILES:%=%.debian-backup)

%:
	dh $@ --with python2

# tweepy/oauth.py wreaks havoc with setup.py. Move it out of the way first.
override_dh_auto_build: $(BACKED_UP_FILES)
	dh_auto_build
	cd docs && sphinx-build -b html . ../build/html

override_dh_auto_install:
	dh_auto_install
	# delete bundled copy of python-oauth
	find debian/tmp -name oauth.py -delete

override_dh_installdocs:
	dh_installdocs -Xjquery -X.doctrees -X.buildinfo -Xunderscore

override_dh_compress:
	dh_compress -X.py

# The "|" ensures that the dependencies are called in order.
override_dh_auto_clean: | dhac restore
	rm -rf tweepy.egg-info build/html

# tweepy/oauth.py wreaks havoc with setup.py. Move it out of the way first.
dhac: $(BACKED_UP_FILES)
	dh_auto_clean

override_dh_installchangelogs:
	dh_installchangelogs CHANGELOG.md

get-orig-source:
	cd $(dir $(firstword $(MAKEFILE_LIST)))../ && \
	uscan --no-conf --rename --force-download --destdir $(CURDIR)

%.debian-backup:
	@# Move the matching stem, foo, to foo.debian-backup.
	mv -f $* $@

restore:
	for file in $(BACKUP_FILES); do \
            [ ! -f $${file}.debian-backup ] || mv $${file}.debian-backup $${file}; \
        done

.PHONY: restore dhac
