#!/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 = https://github.com/isaacs/npm/archive
DEB_UPSTREAM_TARBALL_BASENAME = v$(DEB_UPSTREAM_TARBALL_VERSION).tar.gz
DEB_UPSTREAM_TARBALL_DELIMITER =
DEB_UPSTREAM_TARBALL_EXTENSION =
DEB_UPSTREAM_RECEIVED_EXTENSION = tar.gz
DEB_UPSTREAM_TARBALL_SRCDIR = npm-$(DEB_UPSTREAM_TARBALL_VERSION)
DEB_UPSTREAM_TARBALL_MD5 = 7e8d20e6c845802fbc2315428e7d6d9c
DEB_UPSTREAM_WGET_OPTS += --no-check-certificate
DEB_UPSTREAM_REPACKAGE_EXCLUDES += \
./html/static/webfonts/23242D_3_0.* \
./node_modules/abbrev/ \
./node_modules/ansi/ \
./node_modules/archy/ \
./node_modules/block-stream/ \
./node_modules/fstream/ \
./node_modules/fstream-npm/node_modules/fstream-ignore/ \
./node_modules/glob/ \
./node_modules/graceful-fs/ \
./node_modules/inherits/ \
./node_modules/ini/ \
./node_modules/lockfile/ \
./node_modules/lru-cache/ \
./node_modules/minimatch/ \
./node_modules/mkdirp/ \
./node_modules/node-gyp/ \
./node_modules/nopt/ \
./node_modules/npmlog/ \
./node_modules/once/ \
./node_modules/osenv/ \
./node_modules/read/ \
./node_modules/read-package-json/ \
./node_modules/request/ \
./node_modules/retry/ \
./node_modules/rimraf/ \
./node_modules/semver/ \
./node_modules/slide/ \
./node_modules/tar/ \
./node_modules/which/

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|html/favicon\.ico|html/n-.*\.png|debian/(changelog|copyright(|_hints|_newhints))|node_modules/npm-registry-client/node_modules/couch-login/test/fixtures/registry\.couch)$

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/node_modules/uid-number/get-uid-gid.js
	chmod a-x debian/npm/usr/share/npm/node_modules/npmconf/node_modules/config-chain/index.js
	chmod a+x debian/npm/usr/share/npm/bin/npm-cli.js
	find debian/npm -name LICENSE -delete
	find debian/npm -name LICENCE -delete
	find debian/npm -name LICENSE.txt -delete

