#!/usr/bin/make -f
export DH_VERBOSE=1

TMP=$(CURDIR)/debian/tmp/
TMPD=$(CURDIR)/debian/tmp-debug/
prefix=/usr
ARCH = $(shell dpkg-architecture -qDEB_BUILD_ARCH)
ARCH_OS = $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)
NCPU = $(shell grep -c processor /proc/cpuinfo)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

DEB_SOURCE_PACKAGE ?= $(strip $(shell egrep '^Source: ' debian/control | cut -f 2 -d ':'))
DEB_VERSION ?= $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
DEB_NOEPOCH_VERSION ?= $(shell echo $(DEB_VERSION) | cut -d: -f2-)
DEB_UPSTREAM_VERSION ?= $(shell echo $(DEB_NOEPOCH_VERSION) | sed 's/-[^-]*$$//')
DEB_UPSTREAM_VERSION_MAJOR_MINOR := $(shell echo $(DEB_UPSTREAM_VERSION) | sed -r -n 's/^([0-9]+\.[0-9]+).*/\1/p')
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

DISTRIBUTION = $(shell lsb_release -i -s)
DISTRELEASE = $(shell lsb_release -c -s)

%:
	dh $@ --with-systemd

override_dh_auto_test override_dh_compress override_dh_fixperms override_dh_strip override_dh_usrlocal:

override_dh_auto_build:
	@echo "RULES.$@"
	bash script/build
	touch $@

override_dh_builddeb:
	dh_builddeb -- -Zgzip

override_dh_auto_install:
	@echo "RULES.$@"
	mkdir -p $(TMP)
	mkdir -p $(TMP)/default
	mkdir -p $(TMP)/usr/local/orchestrator
	cp -rf bin/resources  $(TMP)/resources
	cp -f bin/resources/bin/orchestrator-client  $(TMP)/orchestrator-client
	cp -f  conf/orchestrator-sample.conf.json $(TMP)/orchestrator-sample.conf.json
	cp -f  conf/orchestrator-sample-sqlite.conf.json $(TMP)/orchestrator-sample-sqlite.conf.json
	cp -f bin/orchestrator  $(TMP)/orchestrator
	cp -f etc/systemd/orchestrator.service $(TMP)/orchestrator.service
	ls -la $(TMP)
	ls -la $(TMP)/resources/

override_dh_systemd_start:

