#!/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-debbundle-es-to-primitive
SUBMODULES=node-is-callable node-make-generator-function node-make-arrow-function node-is-date-object node-is-symbol node-has-symbols node-object-is
SUBMODULES_GIT=node-is-callable node-make-generator-function node-make-arrow-function node-is-date-object node-is-symbol node-has-symbols node-object-is

%:
	dh $@ --with nodejs

override_dh_auto_test:
	cd node-make-generator-function && tap -R spec test
	# fail but not important
	# cd node-make-arrow-function && tap -R spec test
	cd node-make-arrow-function && node -e 'require("./")'
	cd node-is-date-object && tap -R spec test.js
	cd node-has-symbols && tap -R spec test
	cd node-is-symbol && tap -R spec test
	cd node-object-is && tap -R spec test.js
	cd node-is-callable && tap -R spec test.js
	tap -R spec test

#override_dh_auto_build:


ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
override_dh_installdocs:
	dh_installdocs
	mkdir -p debian/$(MAIN_PKG)/usr/share/doc/node-es-to-primitive
	install README.md $(CURDIR)/debian/$(MAIN_PKG)/usr/share/doc/node-es-to-primitive
	cd  debian/$(MAIN_PKG)/usr/share/doc/$(MAIN_PKG) && for file in *; do \
		ln -sf ../$(MAIN_PKG)/$$file $(CURDIR)/debian/$(MAIN_PKG)/usr/share/doc/node-es-to-primitive/$$file || exit 1; \
	done
	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-es-to-primitive
	ln -sf ../$(MAIN_PKG)/changelog.Debian.gz debian/$(MAIN_PKG)/usr/share/doc/node-es-to-primitive/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
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	mkdir -p debian/$(MAIN_PKG)/usr/share/doc/node-es-to-primitive
	cp CHANGELOG.md debian/$(MAIN_PKG)/usr/share/doc/node-es-to-primitive/changelog
	set -e;for module in $(SUBMODULES); do \
		mkdir -p "debian/$(MAIN_PKG)/usr/share/doc/$$module"; \
		find -L "$$module" -maxdepth 1 -iname 'changelog.md' -exec cp {} "debian/$(MAIN_PKG)/usr/share/doc/$$module/changelog" \; ;\
	done
else
       # skip
endif

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.*
