#!/usr/bin/make -f

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

PYVERS=$(shell pyversions -vr debian/control)
PYMOD=smart_notifier
PACKAGE=smart-notifier
DEB_UPSTREAM_VERSION=$(shell dpkg-parsechangelog \
		             | grep ^Version: | cut -d ' ' -f 2 | cut -d '-' -f 1)

build: $(PYVERS:%=build-python%)
	touch $@

build-python%:
	dh_testdir
	python$* setup.py build
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-python?.?
	$(MAKE) -f debian/rules $(PYVERS:%=clean-python%)
	$(MAKE) clean
	dh_clean

clean-python%:
	python$* setup.py clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) -f debian/rules $(PYVERS:%=install-python%)
	# install configuration
	install -D -m 755 scripts/60smart-notifier \
	    debian/smart-notifier/etc/smartmontools/run.d/60smart-notifier
	install -D -m 644 config/smart-notifier.conf \
	    debian/smart-notifier/etc/dbus-1/system.d/smart-notifier.conf
	install -D -m 644 config/smart-notifier.desktop \
	    debian/smart-notifier/etc/xdg/autostart/smart-notifier.desktop

install-python%:
	python$* setup.py install --no-compile --single-version-externally-managed --root=debian/$(PACKAGE)
	install -d debian/$(PACKAGE)/usr/share/smart-notifier/lib/python$*
	# Remove python and module version from .egg-info and move it to the privat modules
	mv debian/$(PACKAGE)/usr/lib/python$*/site-packages/$(PYMOD)-$(DEB_UPSTREAM_VERSION)-py$*.egg-info \
	   debian/$(PACKAGE)/usr/share/smart-notifier/lib/python$*/$(PYMOD).egg-info
	# Move the python module to a private location
	mv debian/$(PACKAGE)/usr/lib/python$*/site-packages/$(PYMOD) \
	   debian/$(PACKAGE)/usr/share/smart-notifier/lib/python$*/$(PYMOD) 

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_pycentral
	dh_python
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch:
	#Nothing to do here!!!

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
