#!/usr/bin/make -f

export LC_ALL=C.UTF-8
export LANG=C.UTF-8

export DH_GOLANG_EXCLUDES := iphlpapi

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

override_dh_auto_configure:
	# work-around for older etcd versions
	if [ -d /usr/share/gocode/src/github.com/coreos/etcd ]; then			\
		sed -i s#client..go.etcd.*#client\ \"github.com/coreos/etcd/clientv3\"#	\
		checker/etcd_leader_checker.go;						\
	fi
	# work-around for older arp versions
	if ! grep -e net.netip /usr/share/gocode/src/github.com/mdlayher/arp/client.go > /dev/null; then	\
		patch -p1 < debian/patches/relax_go_requirements.patch;						\
	fi
	dh_auto_configure

override_dh_auto_install:
	dh_auto_install -- --no-source

override_dh_install:
	dh_install
	install -d $(CURDIR)/debian/vip-manager2/lib/systemd/system
	install -m 664 vip-manager.service $(CURDIR)/debian/vip-manager2/lib/systemd/system/vip-manager.service
	install -m 664 debian/vip-manager@.service $(CURDIR)/debian/vip-manager2/lib/systemd/system/vip-manager@.service
	install -d $(CURDIR)/debian/vip-manager2/etc/patroni
	install -m 664 debian/vip.in $(CURDIR)/debian/vip-manager2/etc/patroni/vip.in
