DISTRIB=lenny
DISTRIB=unstable
DEBUG=--debug
DEBUG=
MIRROR=--mirror http://athlonfreesos.bayle.eu/debian
FULLUPLOAD=
FULLUPLOAD=--debbuildopts "-sa" 
LOCALREPO=/var/www/debian-eeepc
SRCDIR=../../trunk
WICDVERS=$(shell grep 'version =' $(SRCDIR)/wicd/wicd-daemon.py | cut -d\' -f2)
WICDVERS=1.5.2
DEBMINOR=1$(DISTRIB)0
DEBMINOR=1

wicdbuild:
	make PACKAGE=wicd PKGVERS=$(WICDVERS) DEBVERS=$(WICDVERS)-$(DEBMINOR) DISTRIB=$(DISTRIB) pkgbuild

lintian:
	make PACKAGE=wicd PKGVERS=$(WICDVERS) DEBVERS=$(WICDVERS)-$(DEBMINOR) DISTRIB=$(DISTRIB) _lintian_

deploy:
	make PACKAGE=wicd PKGVERS=$(WICDVERS) DEBVERS=$(WICDVERS)-$(DEBMINOR) DISTRIB=$(DISTRIB) _deploy_

pkgbuild: ../pbuilder/base-$(DISTRIB).tgz ../build-result $(PACKAGE)-$(PKGVERS)
	cd $(PACKAGE)-$(PKGVERS) ; cp debian/changelog debian/changelog.sov
	cd $(PACKAGE)-$(PKGVERS) ; dch -v $(DEBVERS) -D UNRELEASED "Debian $(DISTRIB) build" 
	perl -pi -e "s/UNRELEASED/$(DISTRIB)/" $(PACKAGE)-$(PKGVERS)/debian/changelog
	cd $(PACKAGE)-$(PKGVERS) ; pdebuild --buildresult $(CURDIR) $(FULLUPLOAD) -- $(DEBUG) --distribution $(DISTRIB) $(MIRROR) --basetgz $(CURDIR)/../pbuilder/base-$(DISTRIB).tgz 
	mv $(PACKAGE)-$(PKGVERS)/debian/changelog.sov $(PACKAGE)-$(PKGVERS)/debian/changelog

_lintian_:
	lintian $(PACKAGE)_$(DEBVERS)_i386.changes

_deploy_:
	debsign -m$$DEBEMAIL $(PACKAGE)_$(DEBVERS)_i386.changes
	reprepro -Vb $(LOCALREPO) include $(DISTRIB) $(PACKAGE)_$(DEBVERS)_i386.changes

../pbuilder/base-$(DISTRIB).tgz: ../pbuilder 
	sudo /usr/sbin/pbuilder create $(DEBUG) --distribution $(DISTRIB) $(MIRROR) --basetgz $(CURDIR)/../pbuilder/base-$(DISTRIB).tgz
	@echo "Ready for $(DISTRIB)"

../build-result:
	mkdir ../build-result

../pbuilder:
	mkdir ../pbuilder

$(PACKAGE)-$(PKGVERS):
	cp -r $(SRCDIR) $(PACKAGE)-$(PKGVERS)
	find $(PACKAGE)-$(PKGVERS) -type d -name ".svn" | xargs rm -rf 
	tar cvzf $(PACKAGE)_$(PKGVERS).orig.tar.gz $(PACKAGE)-$(PKGVERS)
	mkdir $(PACKAGE)-$(PKGVERS)/debian
	cp changelog clean_out.py compat control copyright Makefile postinst postrm rules $(PACKAGE)-$(PKGVERS)/debian

clean:
	rm -f *.build *.deb *.upload
