#!/usr/bin/make -f

ifeq (,$(filter terse,${DEB_BUILD_OPTIONS}))
export DH_VERBOSE=1
export V=1
export VERBOSE=1
endif

LC_ALL:=C
export LC_ALL
TZ:=UTC
export TZ

shellescape='$(subst ','\'',$(1))'
shellexport=$(1)=$(call shellescape,${$(1)})

CLEANFILES+=	debian/mkdiridx.tmp

# mostly ../.gitignore
CLEANFILES+=	*.log
CLEANFILES+=	LICENCE.js
CLEANFILES+=	coverage
CLEANFILES+=	dist
CLEANFILES+=	disttmp
CLEANFILES+=	docroot
CLEANFILES+=	docs/download.html
CLEANFILES+=	docs/options.html
CLEANFILES+=	env
CLEANFILES+=	jsdoc
CLEANFILES+=	jsdoc.tmp
CLEANFILES+=	node_modules
CLEANFILES+=	package-lock.json
CLEANFILES+=	site
CLEANFILES+=	src-es5

execute_before_dh_clean:
	-rm -rf ${CLEANFILES}

%:
	dh $@ --buildsystem=none

override_dh_auto_build:
	scripts/build.sh
	sed 's!^ah=.*$$!ah='\''<a href="../">libjs-dygraphs</a> manual integration tests'\''!' \
	    <scripts/mkdiridx.sh >debian/mkdiridx.tmp
	(cd site && exec mksh ../debian/mkdiridx.tmp ./tests)
	rm debian/mkdiridx.tmp

execute_after_dh_installdocs:
	# replaced with symbolic links
	rm debian/libjs-dygraphs/usr/share/doc/libjs-dygraphs/site/.jslibs/*
	rm debian/libjs-dygraphs/usr/share/doc/libjs-dygraphs/site/LICENSE.txt
	rm -r debian/libjs-dygraphs/usr/share/doc/libjs-dygraphs/site/dist

execute_after_dh_compress:
	(cd debian/libjs-dygraphs/usr/share/doc/libjs-dygraphs/site && \
	    find . -name \*.gz -a \! -name \*.pdf.gz -exec gzip -d '{}' +)
