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

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

SCRIPTS = \
	$(CURDIR)/usr/sbin/ngcp-instances-validator \
	$(CURDIR)/usr/sbin/ngcp-network \
	$(CURDIR)/usr/sbin/ngcp-network-validator

%:
	dh $@

override_dh_auto_build:
	dh_testdir
	$(MAKE) man
	# catch any syntax errors *before* building the .deb
	$(MAKE) syntaxcheck

execute_after_dh_install:
	for s in $(SCRIPTS); do \
	  test -r "$$s" \
	    && sed -i -e "s/VERSION = 'UNRELEASED'/VERSION = '$(VERSION)'/" "$$s" \
	    || true; \
	done

execute_after_dh_auto_test:
	## this is a hack to automatically copy the pytest result via pbuilder to
	## the workspace so we can automatically use it as Jenkins test result
	# starting with pbuilder v0.216 it defaults to /build
	if [ -d /build/ ] ; then find $(CURDIR)/results/ -name pytest.xml -exec cp {} /build/ \; || true ; fi
	# previous pbuilder versions default to /tmp/buildd
	if [ -d /tmp/buildd/ ] ; then find $(CURDIR)/results/ -name pytest.xml -exec cp {} /tmp/buildd/ \; || true ; fi
