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

PKGDIR=$(CURDIR)/debian/node-sqlite3/

override_dh_auto_configure:
	node-pre-gyp configure --sqlite=external --module_name=node_sqlite3

override_dh_auto_build:
	node-pre-gyp build

override_dh_auto_test:
	dh_auto_test || true

override_dh_fixperms:
	dh_fixperms
	chmod a-x $(PKGDIR)/usr/lib/nodejs/sqlite3/lib/binding/node-*/node_sqlite3.node

%:
	dh $@

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/

.PHONY: override_dh_auto_configure override_dh_auto_build \
	override_dh_fixperms override_dh_auto_test
