#!/usr/bin/make -f
# -*- makefile -*-
#  version is the "init version"
VERSION := $(shell dpkg-parsechangelog -S Version)
# agent_version replaces the `-` with a space then takes the first "word" in the resulting "list"
# this essentially removes the version suffix `-1` using the limited makefile syntax
AGENT_VERSION := $(word 1, $(subst -, ,$(VERSION)))

export DH_VERBOSE=1

%:
	dh $@

override_dh_auto_clean:
override_dh_auto_test:
override_dh_auto_build:
override_dh_auto_install:
	make release-agent
	make gobuild-init-deb
	cp ./ecs-agent-v${AGENT_VERSION}.tar debian/amazon-ecs-init/var/cache/ecs/ecs-agent-v${VERSION}.tar
	echo "2" >debian/amazon-ecs-init/var/cache/ecs/state
	ln -s "/var/cache/ecs/ecs-agent-v${VERSION}.tar" debian/amazon-ecs-init/var/cache/ecs/ecs-agent.tar
	dh_installsystemd --no-start --no-enable --name=ecs
	dh_installsystemd --no-start --no-enable --name=amazon-ecs-volume-plugin
override_dh_gencontrol:
	dh_gencontrol -- -v$(VERSION)
