#!/usr/bin/make -f

-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
include /usr/share/cdbs/1/class/autotools.mk

DEB_UPSTREAM_URL = http://nodejs.org/dist/v$(DEB_UPSTREAM_TARBALL_VERSION)/
DEB_UPSTREAM_TARBALL_BASENAME = node-v$(DEB_UPSTREAM_TARBALL_VERSION)

DEB_UPSTREAM_WGET_OPTS += --no-check-certificate
# ./deps/npm contains some non-DFSG files, repackaging is needed.
# ./tools/doc/ is unlicensed, https://github.com/joyent/node/issues/2872
# and will be fixed in 0.6.13, https://github.com/joyent/node/commit/33f9074a.
# Conveniently, remove unused software to ease debian/copyright maintenance.
DEB_UPSTREAM_REPACKAGE_EXCLUDES += \
./deps/npm/ \
./deps/openssl/ \
./deps/zlib/ \
./deps/uv/src/ares/ \
./deps/uv/src/unix/ev/ \
./deps/uv/include/ares*.h \
./deps/uv/include/uv-private/ev.h \
./deps/uv/include/uv-private/tree.h \
./tools/scons/ \
./tools/gyp/ \
./tools/closure_linter/ \
./tools/doc/

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

# suppress checking binary files, to not upset dpkg-source
DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^(doc/trademark-policy\.pdf|doc/mac_osx_nodejs_installer_logo\.png|doc/.*-white-stripe\.jpg|favicon\.ico|debian/(changelog|copyright(|_hints|_newhints)))$

DEB_CONFIGURE_NORMAL_ARGS = ""
DEB_CONFIGURE_EXTRA_FLAGS = --debug --without-npm --shared-v8 --shared-cares --shared-libev --shared-zlib --no-ssl2
DEB_CONFIGURE_SCRIPT_ENV += PREFIX="/usr"
DEB_DESTDIR = $(CURDIR)/debian/tmp
DEB_MAKE_CLEAN_TARGET = clean
#  * relax regression tests when targeted experimental suite
exp-relax-check := $(if $(shell dpkg-parsechangelog | grep -x 'Distribution: \(experimental\|UNRELEASED\)'),-i)
DEB_MAKE_CHECK_TARGET = $(exp-relax-check) test

# properly clean files from build, waf, test, python
clean::
	rm -f node
	rm -f node_g
	rm -f .lock-wscript
	rm -rf build
	rm -f test/fixtures/hello.txt
	rm -rf test/tmp
	find . -name "*.pyc" -delete
	rm -rf out

# remove *.json files from documentation, remove google-analytics calls
# TODO: when doc will be generated from markdown, remove it from doc/template.html
binary-install/nodejs::
	find debian/nodejs/usr/share/doc/nodejs -name *.json -delete
	sed -i -e '/document\.write/d' -e '/pageTracker/d' debian/nodejs/usr/share/doc/nodejs/api/*.html

# we have completion for nodejs-waf
install/nodejs-dev::
	dh_bash-completion

