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

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

# Verbose output
export V=1

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

# Disable SSE on non-amd64 architectures.
export SSE_MATH=true
ifeq (,$(findstring $(DEB_BUILD_ARCH),"amd64"))
	export SSE_MATH=false
endif

%:
	dh $@ --parallel --with nodejs

override_dh_auto_configure:
	node-pre-gyp configure --enable_sse=$(SSE_MATH)

override_dh_auto_build:
	node-pre-gyp build --enable_sse=$(SSE_MATH)

override_dh_auto_install:

override_dh_auto_test:

override_dh_install:
	dh_install --list-missing

	dh_buildinfo

	for i in bin/*.js; do \
		cp $$i $(CURDIR)/debian/node-mapnik/usr/bin/`basename $$i .js`; \
	done

	# Don't install binaries with the same name in mapnik-utils
	$(RM) $(CURDIR)/debian/*/usr/bin/mapnik-index
	$(RM) $(CURDIR)/debian/*/usr/bin/mapnik-render
	$(RM) $(CURDIR)/debian/*/usr/bin/mapnik-shapeindex

	chmod 644 $(CURDIR)/debian/node-mapnik/usr/lib/nodejs/mapnik/lib/binding/mapnik.node

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

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