#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

PROMPTDIR=$(CURDIR)/_build/src/github.com/fvwmorg/FvwmPrompt

override_dh_auto_configure:
	# Create links to Debian golang libs, but this copies the full source.
	dh_auto_configure -O--buildsystem=golang -O--builddirectory=_build
	# Delete full source and copy only FvwmPrompt module into place.
	rm -rf $(PROMPTDIR)/*; \
	cd $(CURDIR)/bin/FvwmPrompt; \
	cp FvwmPrompt.go go.mod go.sum $(PROMPTDIR)
	dh_auto_configure -- -Dgolang=enabled -Dhtmldoc=true -Dmandoc=true

execute_after_dh_auto_build:
	# Build FvwmPrompt
	dh_auto_build -O--buildsystem=golang -O--builddirectory=_build

execute_after_dh_install:
	# Copy FvwmPrompt into place.
	cp $(CURDIR)/_build/bin/FvwmPrompt $(CURDIR)/debian/fvwm3/usr/bin
	# Rename fvwm helper binaries to install along side fvwm package.
	cd $(CURDIR)/debian/fvwm3/usr/bin; \
	mv FvwmCommand Fvwm3Command; \
	for name in convert-2.6 menu-desktop menu-directory menu-xlock \
		perllib root; \
	do \
		mv fvwm-$$name fvwm3-$$name; \
	done

execute_after_dh_installman:
	# Rename fvwm3 manpages to install along side fvwm package.
	cd $(CURDIR)/debian/fvwm3/usr/share/man/man1; \
	for module in Animate Auto Backer Buttons Command Event \
		Form IconMan Ident MFL Pager Perl Rearrange Script; \
	do \
		mv Fvwm$$module.1 Fvwm3$$module.1; \
	done; \
	for name in convert-2.6 menu-desktop menu-directory menu-xlock \
		perllib root; \
	do \
		mv fvwm-$$name.1 fvwm3-$$name.1; \
	done

override_dh_installchangelogs:
	dh_installchangelogs CHANGELOG.md

# Skip running dwz on FvwmPrompt, it is already compressed.
override_dh_dwz:
	dh_dwz -XFvwmPrompt

# Determine golang version used in build to add to Static-Built-Using.
override_dh_gencontrol:
	dh_gencontrol -- -Vgo:Version="$(shell dpkg-query \
		--showformat='$${source:Package} (= $${source:Version})' \
		--show golang-*-go)"

%:
	dh $@
