#!/usr/bin/make -f

export DH_GOLANG_INSTALL_EXTRA := $(shell find . -name test-fixtures) \
                                  $(shell find . -name *.approved.*)
export DH_GOLANG_EXCLUDES := \
	cmd plugin/example builder/vsphere/examples/driver scripts \
	builder/hyperone builder/linode builder/osc \
	builder/ucloud post-processor/ucloud-import \
	builder/yandex post-processor/yandex-export post-processor/yandex-import

ifneq (,$(filter $(DEB_HOST_ARCH), armel armhf))
# armel/armhf: os/user(.text): direct call too far: .plt 87db4e
export GOFLAGS := -ldflags=-linkmode=external
endif

ifneq (,$(filter $(DEB_HOST_ARCH), mipsel))
# mipsel: panic: cannot allocate memory
export GOFLAGS := -ldflags=-w
endif

PKG = _build/src/github.com/hashicorp/packer

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

execute_after_dh_auto_configure:
ifneq (,$(filter $(DEB_HOST_ARCH), mipsel riscv64))
	# mipsel riscv64 are too slow to run these tests
	rm -vf $(PKG)/builder/googlecompute/step_create_windows_password_test.go
	rm -vf $(PKG)/builder/azure/arm/template_factory_test.go
endif
	# fail on ipv6-only buildd
	rm -vf $(PKG)/builder/proxmox/step_type_boot_command_test.go
	rm -vf $(PKG)/builder/vsphere/common/step_http_ip_discover_test.go
	# no tty in schroot
	rm -vf $(PKG)/common/terminal_test.go

override_dh_auto_install:
	dh_auto_install -- --no-source

override_dh_auto_test:
	dh_auto_test -- -timeout 1h
