#!/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_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/child-process-close/ \
./node_modules/cmd-shim/ \
./node_modules/fstream/ \
./node_modules/fstream-npm/node_modules/fstream-ignore/ \
./node_modules/github-url-from-git/ \
./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/sha/ \
./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 permissions
# Remove LICENSE files.
binary-post-install/npm::
	chmod a-x debian/npm/usr/share/npm/bin/read-package-json.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
	sed -i -e "s|#!/usr/bin/env node|#!/usr/bin/nodejs|" debian/npm/usr/share/npm/node_modules/opener/opener.js
	find debian/npm -name LICENSE -delete
	find debian/npm -name LICENCE -delete
	find debian/npm -name LICENSE.txt -delete

