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

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

define newline =


endef
define space =
endef

MODULES_COMPONENTS=$(pkgjs-utils root_modules_list|grep -v types)

TIMEOUT=30000
TAP:= $(CURDIR)/bin/run.js -J -R spec -t $(TIMEOUT)

%:
	dh $@

override_dh_fixperms:
	dh_fixperms
	chmod a+x debian/node-tap/usr/share/nodejs/tap/bin/*.js

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
override_dh_installman:
	help2man -N -n "Test-Anything-Protocol module for Node.js" --no-discard-stderr bin/run.js -o debian/tap.1
	dh_installman
else
override_dh_installman:
	@echo '**********************************************************'
	@echo 'Skip generating man page                                  '
	@echo '**********************************************************'
endif

override_dh_installdocs:
	dh_installdocs
	set -e ; for c in $(MODULES_COMPONENTS); do \
	    mkdir -p "debian/node-tap/usr/share/doc/node-$$c"; \
	    ln -s ../node-tap/copyright debian/node-tap/usr/share/doc/node-$$c/copyright; \
	    ln -s ../node-tap/changelog.Debian.gz debian/node-tap/usr/share/doc/node-$$c/changelog.Debian.gz; \
	    cp -f module-$$c/README.md debian/node-tap/usr/share/doc/node-$$c/; \
	done

override_dh_installexamples:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	dh_installexamples
	find debian/node-tap/usr/share/doc/node-tap/examples -name '*.js' -exec \
		sed -i "s,require[(]['][.][.][^']lib/tap.js['][)],require('tap'),g" {} \;
else
endif
