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

include /usr/share/dpkg/pkg-info.mk

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

MAIN_PKG=node-boom
SUBMODULES=node-hapi-bounce
SUBMODULES_GIT=node-hapi-bounce

%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean
	rm -rf node_modules

override_dh_auto_configure:
	dh_auto_configure
	mkdir -p node_modules/@hapi/
	ln -s ../../ node_modules/@hapi/boom

#override_dh_auto_build:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
override_dh_auto_test:
	#nodejs -e "require('.')"
	#cd node-hapi-bounce && nodejs -e "require('.')"
endif

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
override_dh_installdocs:
	dh_installdocs
	ln -s node-boom debian/$(MAIN_PKG)/usr/share/doc/node-hapi-boom
	set -e;for module in $(SUBMODULES); do \
		mkdir -p "debian/$(MAIN_PKG)/usr/share/doc/$$module"; \
		ln -s ../$(MAIN_PKG)/copyright debian/$(MAIN_PKG)/usr/share/doc/$$module/copyright || exit 1; \
	done
	set -e;for module in $(SUBMODULES); do \
		mkdir -p "debian/$(MAIN_PKG)/usr/share/doc/$$module"; \
		find -L "$$module" -maxdepth 1 -iname '*.md' -and -not -iname 'license.md' -and -not -iname 'changelog.md' -exec install {} "debian/$(MAIN_PKG)/usr/share/doc/$$module" \; || exit 1;\
	done
else
override_dh_installdocs:
	@echo '**********************************************************'
	@echo 'Skip doc'
	@echo '**********************************************************'
endif


override_dh_installchangelogs:
	dh_installchangelogs -XCHANGELOG.md
	mkdir -p debian/$(MAIN_PKG)/usr/share/doc/node-hapi-boom
	ln -sf ../$(MAIN_PKG)/changelog.Debian.gz debian/$(MAIN_PKG)/usr/share/doc/node-hapi-boom/changelog.Debian.gz
	set -e;for module in $(SUBMODULES); do \
		mkdir -p "debian/$(MAIN_PKG)/usr/share/doc/$$module"; \
		ln -s ../$(MAIN_PKG)/changelog.Debian.gz debian/$(MAIN_PKG)/usr/share/doc/$$module/changelog.Debian.gz; \
	done

COMPONENTS_LIST_GIT_DPM=$(foreach component,$(SUBMODULES_GIT),--component ../$(MAIN_PKG)_$(DEB_VERSION_UPSTREAM).orig-$(component).tar.*)

git_dpm_rules:
	git dpm inu --ignore-unclean-branches --pristine-tar $(COMPONENTS_LIST_GIT_DPM) --rebase ../$(MAIN_PKG)_$(DEB_VERSION_UPSTREAM).orig.tar.*
