#! /usr/bin/make -f
include /usr/share/dpkg/default.mk

pre-clean:
	# I wish I could just use $${source:Version} in debian/control, but no
	sed 's/^ s390-tools-zkey (= $${source:Version})/ s390-tools-zkey (= $(DEB_VERSION))/' debian/control.in > debian/control
PHONY: pre-clean
clean:: pre-clean

%:
	dh $@

override_dh_auto_build:
	./download-signed s390-tools $(DEB_VERSION) s390-tools
	mkdir SIGNED
	(									\
		cd "$(DEB_VERSION)" || exit 1;					\
		for s in *.sipl.sig; do						\
			[ ! -f "$$s" ] && continue;				\
			chmod 600 "$$s";					\
			base=$$(echo "$$s" | sed -e 's/.sipl.sig//');		\
			cat "$$base.sipl" "$$s" >"../SIGNED/$$base";		\
		done;								\
		openssl x509 -inform der -outform pem -in control/sipl.x509 -text -out ../SIGNED/stage3.pem \
	)

override_dh_install:
	dh_install SIGNED/stage3.bin usr/lib/s390-tools/
	dh_install SIGNED/stage3.bin SIGNED/stage3.pem usr/lib/s390-tools/
