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

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

-include /usr/share/cdbs/1/rules/upstream-tarball.mk
include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/cdbs/1/rules/debhelper.mk

# suppress optional build-dependencies
CDBS_BUILD_DEPENDS_rules_upstream-tarball =
CDBS_BUILD_DEPENDS_rules_utils_copyright-check =

DEB_UPSTREAM_URL = http://githubredir.debian.net/github/isaacs/npm
DEB_UPSTREAM_TARBALL_BASENAME = v$(DEB_UPSTREAM_TARBALL_VERSION)
DEB_UPSTREAM_WGET_OPTS += --no-check-certificate

# Suppress copyright-checking some binaries to not upset dpkg-source
DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^(html/npm-.*\.png|debian/(changelog|copyright(|_hints|_newhints)))$

install/npm::
	dh_bash-completion

# fix manpages file names : prepend npm- except for npm.1, and link manpages from npm manroot to the ones in /usr/share/man
# also fix permissions
binary-post-install/npm::
	fManpages=`find $(CURDIR)/debian/npm/usr/share/man -name *.1`; \
	for i in $$fManpages; do \
		lDir=`dirname "$$i"`; \
		lFile=`basename "$$i"`; \
		lManDir=`basename "$$lDir"`; \
		lRenamed="$$lFile"; \
		if [ "$$lFile" != "npm.1" ]; then \
			lRenamed="npm-$$lFile"; \
			mv "$$i" "$$lDir/$$lRenamed"; \
		fi; \
		ln -s "../../man/$$lManDir/$$lRenamed.gz" "$(CURDIR)/debian/npm/usr/share/npm/man1/$$lFile.gz"; \
	done
	chmod a-x debian/npm/usr/share/npm/bin/npm.js
	chmod a-x debian/npm/usr/share/npm/cli.js
	chmod a-x debian/npm/usr/share/npm/lib/utils/which.js
