#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DH_GOLANG_INSTALL_EXTRA = tests/assets/example.json

VERSION := $(DEB_VERSION)
GO_FLAGS = -ldflags "-X 'github.com/tomwright/dasel/internal.Version=v$(VERSION)'"

# golang does not support PIE on mips.
# see https://github.com/golang/go/issues/21222
ifeq (,$(filter $(DEB_HOST_ARCH),mips mipsel mips64el))
	GO_FLAGS += -buildmode=pie
endif

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

override_dh_auto_build:
	dh_auto_build -- $(GO_FLAGS)

execute_before_dh_install:
	mkdir -p debian/tmp/completions
	_build/bin/dasel completion zsh > debian/tmp/completions/_dasel
	_build/bin/dasel completion bash > debian/tmp/completions/dasel
	_build/bin/dasel completion fish > debian/tmp/completions/dasel.fish

ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
execute_before_dh_installman:
	_build/bin/dasel man -o debian/tmp
endif
