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

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

MAIN_PACKAGE=node-hoek
PACKAGES_DOCS_DIR=node-hapi-b64 node-hapi-teamwork
NODE_SUBPACKAGE=node-hapi-b64 node-hapi-teamwork

%:
	dh $@

override_dh_fixperms:
	find 'debian/node-hoek/usr/share/nodejs/@hapi' -type f -exec chmod 444 {} \;
	dh_fixperms

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
override_dh_installdocs:
	mkdir -p debian/${MAIN_PACKAGE}/usr/share/doc/${MAIN_PACKAGE}
	ln -s node-hoek debian/${MAIN_PACKAGE}/usr/share/doc/node-hapi-hoek
	if test "X$(PACKAGES_DOCS_DIR)" != X ; then \
		for module in $(PACKAGES_DOCS_DIR); do \
			mkdir -p "debian/${MAIN_PACKAGE}/usr/share/doc/$$module"; \
			ln -s "../${MAIN_PACKAGE}/copyright" "debian/${MAIN_PACKAGE}/usr/share/doc/$$module/copyright" ; \
		done; \
	else \
		true; \
	fi
	dh_installdocs --link-doc=${MAIN_PACKAGE}
	mkdir -p "debian/${MAIN_PACKAGE}/usr/share/doc/${MAIN_PACKAGE}";
	if test "X$(NODE_SUBPACKAGE)" != X ; then \
		for module in $(NODE_SUBPACKAGE); do \
			mkdir -p "debian/$(MAIN_PACKAGE)/usr/share/doc/$$module"; \
			find "$$module" -maxdepth 1 -iname '*.md' -and -not -iname 'license.md' -exec install {} "debian/$(MAIN_PACKAGE)/usr/share/doc/$$module" \; ; \
		done; \
	else \
		true; \
	fi
else
override_dh_installdocs:
	@echo '**********************************************************'
	@echo 'Skip dh_installdocs                                       '
	@echo '**********************************************************'
endif

override_dh_installchangelogs:
	# create changelog
	if test "X$(PACKAGES_DOCS_DIR)" != X ; then \
		for module in $(PACKAGES_DOCS_DIR); do \
			mkdir -p "debian/$(MAIN_PACKAGE)/usr/share/doc/$$module"; \
			ln -s "../$(MAIN_PACKAGE)/changelog.Debian.gz" "debian/$(MAIN_PACKAGE)/usr/share/doc/$$module/changelog.Debian.gz" ; \
		done; \
	else \
		true; \
	fi
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	dh_installchangelogs
#	mkdir -p debian/node-acorn/usr/share/doc/node-acorn
#install module-acorn-node/CHANGELOG.md debian/node-acorn/usr/share/doc/node-acorn/changelog.acorn-node
else
	dh_installchangelogs
endif
