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

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

%:
	dh $@

override_dh_auto_test:
	#find . -maxdepth 1 -type f -name "*.crt" -exec openssl verify "{}" \;
	certtool --verify --load-ca-certificate root.crt --infile class3.crt
	certtool --verify --load-ca-certificate root.crt --infile root.crt

PKD  = $(abspath $(dir $(MAKEFILE_LIST)))
PKG  = $(word 2,$(shell dpkg-parsechangelog -l$(PKD)/changelog | grep ^Source))
VER ?= $(shell dpkg-parsechangelog -l$(PKD)/changelog | perl -ne 'print $$1 if m{^Version:\s*([\d\.+git]+)}')
.PHONY: get-orig-source
get-orig-source: $(PKG)_$(VER).orig.tar.xz
	@

$(PKG)_$(VER).orig.tar.xz:
	mkdir $(PKG)_$(VER)
	@echo "# Downloading..."
	cd $(PKG)_$(VER) && wget --continue --timestamp --no-check-certificate https://www.cacert.org/certs/root.crt
	cd $(PKG)_$(VER) && wget --continue --timestamp --no-check-certificate https://www.cacert.org/certs/class3.crt
	find -L "$(PKG)_$(VER)" -xdev -type f -print | LC_ALL=C sort \
        | XZ_OPT="-6v" tar -caf $(PKG)_$(VER).orig.tar.xz -T- --owner=root --group=root --mode=a+rX
	$(RM) -r $(PKG)_$(VER)
