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

#export DH_VERBOSE=1
export DH_OPTIONS
export DH_GOPKG := github.com/snapcore/snapd
#export DEB_BUILD_OPTIONS=nocheck
export DH_GOLANG_EXCLUDES=integration-tests
export DH_GOLANG_GO_GENERATE=1

# we need the builddir; is there a simpler way to get it?
BUILDDIR:=${CURDIR}/obj-$(shell dpkg-architecture -qDEB_TARGET_GNU_TYPE)

export PATH:=${PATH}:${CURDIR}

RELEASE = $(shell lsb_release -c -s)

%:
	dh $@ --buildsystem=golang --with=golang --fail-missing --with systemd

override_dh_systemd_enable:
	# enable boot-ok
	dh_systemd_enable \
		-pubuntu-core-snapd-units \
		snapd.boot-ok.service
	# enable the first boot service
	dh_systemd_enable \
		-pubuntu-core-snapd-units \
		snapd.firstboot.service
	# we want the auto-update timer enabled by default
	dh_systemd_enable \
		-psnapd \
		snapd.refresh.timer
	# but the auto-update service disabled
	dh_systemd_enable \
		--no-enable \
		-psnapd \
		snapd.refresh.service
	# enable snapd
	dh_systemd_enable \
		-psnapd \
		snapd.socket
	dh_systemd_enable \
		-psnapd \
		snapd.service

override_dh_systemd_start:
	# start boot-ok
	dh_systemd_start \
		-pubuntu-core-snapd-units \
		snapd.boot-ok.service
	# we want to start the auto-update timer
	dh_systemd_start \
		-psnapd \
		snapd.refresh.timer
	# but not start the service
	dh_systemd_start \
		--no-start \
		-psnapd \
		snapd.refresh.service
	# start snapd
	dh_systemd_start \
		-psnapd \
		snapd.socket
	dh_systemd_start \
		-psnapd \
		snapd.service

override_dh_auto_install: snap.8
	dh_auto_install -O--buildsystem=golang
	# we do not need this in the package, its just needed during build
	rm -rf ${CURDIR}/debian/tmp/usr/bin/xgettext-go
	# Making the packages private
	rm -rf ${CURDIR}/debian/snapd/usr/share/gocode
	# toolbelt is not shippable
	rm -f ${CURDIR}/debian/tmp/usr/bin/toolbelt
	# we do not like /usr/bin/snappy anymore
	rm -f ${CURDIR}/debian/tmp/usr/bin/snappy

snap.8:
	${BUILDDIR}/bin/snap help --man > $@

override_dh_auto_clean:
	dh_auto_clean -O--buildsystem=golang
	rm -vf snap.8
