#!/usr/bin/make -f

# Don't install the t-03-queue_persistency binary, this is just for testing
# and appears because of how Debian autodetects the available binaries.
export DH_GOLANG_EXCLUDES := t-03-queue_persistency cmd/spf-check

DEBVERS    ?= $(shell dpkg-parsechangelog -SVersion)
DEBDATE    ?= $(shell dpkg-parsechangelog -SDate)
BUILD_DATE := $(shell date --utc --date='$(DEBDATE)' +%s)

BUILDFLAGS := -ldflags \
    " -X main.version=$(DEBVERS) \
      -X main.sourceDateTs=$(BUILD_DATE)"

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

override_dh_auto_build:
	dh_auto_build -- $(BUILDFLAGS)

# No need to install the source files, this is a binary package.
override_dh_auto_install:
	dh_auto_install -- --no-source

# Enable both the service and the sockets (by default only the service will be
# enabled, and that's not enough for our case).
# This is based on openssh's package.
override_dh_systemd_enable:
	dh_systemd_enable --name chasquid chasquid.service
	dh_systemd_enable --name chasquid --no-enable chasquid-smtp.socket
	dh_systemd_enable --name chasquid --no-enable \
            chasquid-submission.socket
