#!/usr/bin/make -f

export DH_GOLANG_INSTALL_EXTRA := \
	test/hooks.json.tmpl \
	test/hooks.yaml.tmpl \
	hooks.json.example \
	hooks.json.tmpl.example \
	hooks.yaml.example \
	hooks.yaml.tmpl.example

export DH_GOLANG_EXCLUDES := test

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

# The bundled golang.org/x/sys snapshot (2019-12) contains no loong64 support
# files at all (no zerrors/zsyscall/zsysnum/ztypes_linux_loong64.go), hence
# golang.org/x/sys/unix cannot be compiled for linux/loong64 (_CPU_SETSIZE,
# Cmsghdr, RawSockaddr* ... all undefined). On loong64 drop the bundled copy so
# that the build falls back to the distro provided golang-golang-x-sys-dev,
# which carries upstream loong64 support.
DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)

ifeq ($(DEB_HOST_ARCH),loong64)
override_dh_auto_configure:
	rm -rf vendor/golang.org/x/sys
	dh_auto_configure
endif

override_dh_auto_install:
	dh_auto_install -- --no-source

override_dh_installinit:
	dh_installsystemd -pwebhook --no-start --name=webhook webhook.service
	dh_installinit -pwebhook --no-start --noscripts
