#!/usr/bin/make -f

include /usr/share/dpkg/default.mk
include /usr/share/dpkg/pkg-info.mk

# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

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

execute_before_dh_auto_build:
	# This step is necessary because the upstream distributes the library with
	# a folder structure that differs from the expected Go module path.
	# The Go module for this library is sigs.k8s.io/kustomize/kustomize/v5.
	# To align the folder structure with the expected module path, this step
	# renames the 'kustomize' folder to 'v5'.
	mv $(CURDIR)/_build/src/sigs.k8s.io/kustomize/kustomize/kustomize $(CURDIR)/_build/src/sigs.k8s.io/kustomize/kustomize/v5

execute_before_dh_auto_install:
	mv _build/bin/v5 _build/bin/kustomize
ifeq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
	mkdir -v -p $(CURDIR)/debian/completion
	_build/bin/kustomize completion bash > $(CURDIR)/debian/completion/kustomize.bash
	_build/bin/kustomize completion fish > $(CURDIR)/debian/completion/kustomize.fish
	_build/bin/kustomize completion zsh > $(CURDIR)/debian/completion/kustomize.zsh
endif

ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
execute_before_dh_installman-arch:
	help2man debian/kustomize/usr/bin/kustomize \
		--no-info --no-discard-stderr \
		--version-string="$(DEB_VERSION_UPSTREAM)" \
		-n "Customization of Kubernetes YAML configurations" > debian/kustomize.1
endif
