
PACKAGE	:= $(shell dpkg-parsechangelog | sed -n 's/^Source: //p')
VERSION	:= $(shell dpkg-parsechangelog | sed -n 's/^Version: \(.*:\|\)//p')
DEBARCH	:= $(shell dpkg-architecture -qDEB_HOST_ARCH)

DSC	:= $(PACKAGE)_$(VERSION).dsc
CHANGES	:= $(PACKAGE)_$(VERSION)_$(DEBARCH).changes

# config
PRESULT	:= /work/pbuilder/result


##########################################################
# normal devel builds

default: build lintian

build:
	rm -f .ok
	(time dpkg-buildpackage -nc -us -uc -rfakeroot && touch .ok) \
		2>&1 | tee build.log
	test -f .ok

lintian:
	lintian ../$(CHANGES)

clean:
	fakeroot debian/rules clean
	rm -f build.log .ok


##########################################################
# build releases

source ../$(DSC): clean
	dpkg-buildpackage -S -us -uc -rfakeroot

pbuild: ../$(DSC)
	(time sudo /usr/sbin/pbuilder build ../$(DSC) && touch .ok) \
		2>&1 | tee build.log
	test -f .ok
	-lintian -i $(PRESULT)/$(CHANGES)

release: ../$(DSC)
	#sudo /usr/sbin/pbuilder --debbuildopts '-si' build ../$(DSC)
	sudo /usr/sbin/pbuilder build ../$(DSC)
	debsign $(PRESULT)/$(CHANGES)


##########################################################
# misc

work unpack: clean
	debian/rules work

.PHONY: default build pbuild lintian clean release port
.PHONY: source work unpack

