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

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

ifndef UPVER
UPVER := $(shell dpkg-parsechangelog -SVersion | cut -d- -f1 | cut -d+ -f1)
endif

TARDIR := node-zipfile-$(UPVER)
TARNAME := node-zipfile_$(UPVER)+ds1.orig.tar

%:
	dh $@

override_dh_install:
	dh_install
	dh_buildinfo
	chmod 644 $(CURDIR)/debian/node-zipfile/usr/lib/nodejs/zipfile/node_zipfile.node

override_dh_auto_configure:
	node-gyp configure --libzip=shared

override_dh_auto_build:
	node-gyp build

override_dh_auto_test:

override_dh_shlibdeps:
	dpkg-shlibdeps \
		-T$(CURDIR)/debian/node-zipfile.substvars \
		$(CURDIR)/debian/node-zipfile/usr/lib/nodejs/zipfile/node_zipfile.node

override_dh_strip:
	strip \
		--remove-section=.comment \
		--remove-section=.note \
		--strip-unneeded \
		$(CURDIR)/debian/node-zipfile/usr/lib/nodejs/zipfile/node_zipfile.node

get-orig-source:
	mkdir -p ../tarballs
	uscan \
		--verbose \
		--download-version $(UPVER) \
		--force-download \
		--destdir ../tarballs \
		--rename
	tar xvf ../tarballs/node-zipfile_0.4.0.orig.tar.gz
	@echo Repackaging
	rm -rf $(TARDIR)/deps/libzip*
	rm -rf $(TARDIR)/deps/zlib
	rm -rf $(TARDIR)/deps/*-include
	rm -rf $(TARDIR)/deps/*.py
	rm $(TARDIR)/test/data/world_merc.zip
	tar cf $(TARNAME) $(TARDIR)/
	rm -rf $(TARDIR)/
	gzip -9 $(TARNAME)
	mv $(TARNAME).gz ../tarballs/

