#!/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$(shell echo $(DEB_UPSTREAM_VERSION) | cut -f 1 -d '~')
DEB_UPSTREAM_TARBALL_SRCDIR = isaacs-npm-2defe7b
DEB_UPSTREAM_TARBALL_MD5 = d476e9b8000e11d395b7c817ee0f45c4
DEB_UPSTREAM_WGET_OPTS += --no-check-certificate
DEB_UPSTREAM_REPACKAGE_EXCLUDES += \
./html/*/GubbleBum-Blocky.ttf \
./node_modules/request/ \
./node_modules/node-uuid/ \
./node_modules/mkdirp/ \
./node_modules/minimatch/ \
./node_modules/lru-cache/ \
./node_modules/semver/ \
./node_modules/graceful-fs/ \
./node_modules/inherits/ \
./node_modules/abbrev/ \
./node_modules/nopt/ \
./node_modules/ini/ \
./node_modules/block-stream/ \
./node_modules/fstream/ \
./node_modules/rimraf/ \
./node_modules/tar/ \
./node_modules/fast-list/ \
./node_modules/which/ \
./node_modules/slide/nodejs-controlling-flow.pdf

DEB_UPSTREAM_REPACKAGE_TAG = $(shell echo $(DEB_UPSTREAM_VERSION) | egrep -o "dfsg[0-9]*")

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

clean::
	make docclean

build/npm::
	make doc

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
# Fix permissions
# Remove LICENSE files.
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/man/man1/$$lFile"; \
	done
	fManpages=`find $(CURDIR)/debian/npm/usr/share/man -name *.3`; \
	for i in $$fManpages; do \
		lDir=`dirname "$$i"`; \
		lFile=`basename "$$i"`; \
		lManDir=`basename "$$lDir"`; \
		lRenamed="$$lFile"; \
		if [ "$$lFile" != "npm.3" ]; then \
			lRenamed="npm-$$lFile"; \
			mv "$$i" "$$lDir/$$lRenamed"; \
		fi; \
		ln -s "../../../man/$$lManDir/$$lRenamed.gz" "$(CURDIR)/debian/npm/usr/share/npm/man/man3/$$lFile"; \
	done
	chmod a-x debian/npm/usr/share/npm/bin/*.js
	chmod a+x debian/npm/usr/share/npm/bin/npm-cli.js
	find debian/npm -name LICENSE -delete

