#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

LANG = $(shell ls doc | grep -v Makefile)
LIB_DESTDIR = $(CURDIR)/debian/python-expeyes

%:
	dh $@ --with python2

override_dh_auto_build:
	python setup.py build
	make -C $(CURDIR)/doc all
	cd firmware; ./compile.sh eyes

override_dh_auto_clean:
	rm -rf *~ *.pyc build/ expeyes/*~ expeyes/*.pyc
	cd firmware;  rm -f  eyes *.hex *~
	make -C $(CURDIR)/doc clean
	make -C $(CURDIR)/po clean
	dh_clean

THIS_PYTHON = python2.7
DIRPYPKG = $(CURDIR)/debian/python-expeyes/usr/local/lib/$(THIS_PYTHON)/dist-packages/expeyes

override_dh_auto_install:
	# for python-expeyes
	python setup.py install --root=debian/python-expeyes --prefix=/usr
	echo 'ATTR{idVendor}=="03eb", ATTR{idProduct}=="21ff", MODE="666"' > $(LIB_DESTDIR)/lib/udev/rules.d/99-phoenix.rules
	echo 'ATTR{idVendor}=="0403", ATTR{idProduct}=="6001", MODE="666"' >> $(LIB_DESTDIR)/lib/udev/rules.d/99-phoenix.rules
	# for expeyes
	pyfiles=$$(ls $(CURDIR)/*.py); \
	install -m644 $${pyfiles} $(CURDIR)/debian/expeyes/usr/share/expeyes
	install -m 755 expEYES $(CURDIR)/debian/expeyes/usr/bin
	install -m 644 logo.svg $(CURDIR)/debian/expeyes/usr/share/icons/expeyes.svg
	install -m 644 expeyes.desktop $(CURDIR)/debian/expeyes/usr/share/applications
	make -C $(CURDIR)/po install DESTDIR=$(CURDIR)/debian/expeyes
	# firmware stuff
	cd firmware; \
	for f in go set_fuse.sh test.py upload.sh eyes.hex; do \
	  install -m 644 $$f $(CURDIR)/debian/expeyes-firmware-dev/usr/share/expeyes/firmware; \
	done
	# install pictures
	install -m 644 $(CURDIR)/pics/* $(CURDIR)/debian/expeyes/usr/share/expeyes/pics
	# install the documentation
	for l in $(LANG); do \
	  destdir=$(CURDIR)/debian/expeyes-doc-$$l; \
	  install -d $${destdir}/usr/share/expeyes/doc; \
	  make -C $(CURDIR)/doc install DESTDIR=$${destdir} LANG=$$l; \
	done

