#!/usr/bin/make -f

%:
	dh $@ --with=python2,python3

PY3REQUESTED := $(shell py3versions -r)
PY3DEFAULT := $(shell py3versions -d)
# Run setup.py with the default python3 last so that the scripts use
# #!/usr/bin/python3 and not #!/usr/bin/python3.X.
PY3 := $(filter-out $(PY3DEFAULT),$(PY3REQUESTED)) python3

override_dh_auto_build:
	dh_auto_build
	set -e; for python in $(PY3); do \
		$$python setup.py build; \
	done
	# build the binary database
	(cd UnifiedDataExtractor;  \
	 ./create-binary-database; \
	  mv *.db ../data/programs.d/)

override_dh_auto_clean:
	rm -rf build
	find -name __pycache__ -print0 | xargs -0r rm -rf

override_dh_auto_install:
	dh_auto_install
	set -e; for python in $(PY3); do \
		$$python setup.py install --force --root=$(CURDIR)/debian/tmp \
			--no-compile -O0 --install-layout=deb; \
	done

override_dh_install: 
	dh_install
ifneq (,$(filter command-not-found,$(shell dh_listpackages)))
	# Move our script from /usr/bin to /usr/lib (not meant for end-users)
	install -d $(CURDIR)/debian/command-not-found/usr/lib
	mv $(CURDIR)/debian/command-not-found/usr/bin/command-not-found $(CURDIR)/debian/command-not-found/usr/lib/command-not-found
	rmdir --ignore-fail-on-non-empty $(CURDIR)/debian/command-not-found/usr/bin
	# Get rid of bash integration script, got merged to bash
	rm $(CURDIR)/debian/command-not-found/etc/bash_command_not_found
endif

override_dh_auto_test:
	python3 -m unittest discover
