#!/usr/bin/make -f

%:
	dh $@ --with=python3 --buildsystem=pybuild

override_dh_auto_build:
	dh_auto_build
	# strip off version information - this will be outdated anyway
	# (this entire thing goes away once Commands-* is stored on the
	#  archive server)
	find CommandNotFound/db/dists -name "Commands-*" -exec sed -i '/^version:/d' {} \;

	# build the binary database for the current architecture
	(cd CommandNotFound/db;  \
	 ./creator.py commands.db ./dists/*/*/*/Commands-*; \
	  mv commands.db ../../data/)

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
	mv $(CURDIR)/debian/command-not-found/usr/bin/cnf-update-db $(CURDIR)/debian/command-not-found/usr/lib/cnf-update-db
	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
