#!/usr/bin/make -f
# -*- makefile -*-
#
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
	dh $@

PACKAGE := libzabbix-api-perl
VER := $(shell dpkg-parsechangelog | perl -ne 'print $$1 if m/Version:\s*([\d\.+git]+)/')
UVER := $(shell echo $(VER) | perl -ne 'print $$1 if m/\+git(\d+)/')
UVER_DATE := $(shell echo '$(UVER)' | perl -ne 'print $$1 if m/^(\d{8})/')
UVER_TIME := $(shell echo '$(UVER)' | perl -ne 'print $$1 if m/^\d{8}(\d+)/')
UVER_UDATE := $(shell date -u -d "$(UVER_DATE) $(UVER_TIME)" +%s)
get-orig-source:
	#uscan --noconf --force-download --repack --rename --download-current-version --verbose --destdir=.
	@echo " Upstream version: $(UVER)\n Version: $(VER)\n UDATE: $(UVER_UDATE)"
	git clone git://github.com/SFR-ZABBIX/Zabbix-API.git $(PACKAGE)-$(UVER)
	cd $(PACKAGE)-$(UVER) \
	&& git reset --hard $$(git rev-list --all -n 1 --before=$(UVER_UDATE)) \
	&& git checkout master \
	&& $(RM) -r .git .git* && cd .. && echo "Packing..." \
	&& tar cJf $(PACKAGE)_$(VER).orig.tar.xz $(PACKAGE)-$(UVER)
	$(RM) -r $(PACKAGE)-$(UVER)
