#!/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

DSVER := $(shell dpkg-parsechangelog -SVersion | cut -d- -f1 | cut -d+ -f2)

TARDIR := node-sqlite3-$(UPVER)
TARNAME := node-sqlite3_$(UPVER)+$(DSVER).orig.tar


%:
	dh $@

override_dh_install:
	dh_install
	dh_buildinfo
	chrpath -d $(CURDIR)/debian/node-sqlite3/usr/lib/nodejs/sqlite3/lib/node_sqlite3.node
	chmod 644 $(CURDIR)/debian/node-sqlite3/usr/lib/nodejs/sqlite3/lib/node_sqlite3.node

override_dh_auto_configure:
	node-gyp configure --sqlite=external

override_dh_auto_build:
	node-gyp build

override_dh_auto_test:

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

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

get-orig-source:
	mkdir -p ../tarballs
	uscan \
		--verbose \
		--download-version $(UPVER) \
		--force-download \
		--destdir ../tarballs \
		--rename
	tar xvf ../tarballs/node-sqlite3_$(UPVER).orig.tar.gz
	@echo Repackaging
	rm -rf $(TARDIR)/deps/sqlite-*.tar.gz
	tar cf $(TARNAME) $(TARDIR)/
	rm -rf $(TARDIR)/
	gzip -9 $(TARNAME)
	mv $(TARNAME).gz ../tarballs/
