#!/usr/bin/make -f
# -*- makefile -*-

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

CURVER := $(shell dpkg-parsechangelog | grep ^Version | cut -d\  -f2 | sed -e "s/\(\+.*\)\|\(\-.*\)//")

override_dh_auto_configure:
	python setup.py configure \
		--no-install-acpi \
		--no-install-docs \
		--lib=/usr/share/wicd \
		--share=/usr/share/wicd \
		--wicdgroup=netdev \
		--loggroup=adm \
		--logperms=0640

override_dh_auto_clean:
	dh_auto_clean
	-find . \( -name "*.pyc" -o -name "*.pyo" \) -delete
	-find init/ \( -name "wicd" -o -name "rc.wicd" \) -delete
	-rm -rf build/

	dh_clean wpath.py install.log os wicd/wpath.py \
		man/*.8 man/*.5 scripts/* other/*.sh \
		other/postinst other/55wicd debian/wicd-po/*.mo \
		other/91wicd other/wicd.conf other/WHEREAREMYFILES

	# recreate directories needed during the compilation
	-for i in arch debian default gentoo lunar pld redhat slackware suse; do \
		mkdir -p $(CURDIR)/init/$$i ; \
	done

override_dh_auto_install:
	python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb
	
	find $(CURDIR)/debian/tmp -name "*.png" -exec chmod 644 {} \;
	find $(CURDIR)/debian/tmp/etc/wicd/ -type f -exec chmod 644 {} \;
	find $(CURDIR)/debian/tmp \( -name "*.glade" -o -name "*.conf" -o -name "*.desktop" \) -exec chmod 644 {} \;
	
	find $(CURDIR)/debian/tmp/ -name ".empty_on_purpose" -delete

	-rm -rf $(CURDIR)/debian/tmp/var/run

override_dh_installinit:
	dh_pysupport -i
	dh_installinit -i --name=wicd --restart-after-upgrade

override_dh_bugfiles:
	dh_bugfiles -A

%:
	dh --with quilt $@

get-orig-source:
	uscan --force-download --download-version $(CURVER) --destdir . --rename
	tar xvf wicd_$(CURVER).orig.tar.bz2
	( cd wicd-$(CURVER)/ ; \
	patch -p1 < ../debian/patches/xx-get_translations.patch ; \
	python setup.py get_translations ; \
	rm -rf vcsinfo.pyc )
	tar jcf wicd_$(CURVER)+ds1.orig.tar.bz2 wicd-$(CURVER)/
	rm -rf wicd_$(CURVER).orig.tar.bz2 wicd-$(CURVER)/
