#!/usr/bin/make -f
DPKG_EXPORT_BUILDFLAGS = 1
DEB_BUILD_MAINT_OPTIONS = hardening=+all
include /usr/share/dpkg/default.mk

PACKAGE := $(shell dh_listpackages)
TMP     := $(CURDIR)/debian/$(PACKAGE)

# I disable autopoint. Not clear on why this is needed, but otherwise the
# package build says
#   configure:18339: error: possibly undefined macro: gl_PTHREADLIB
#   configure:18452: error: possibly undefined macro: gl_WEAK_SYMBOLS
#   configure:23056: error: possibly undefined macro: gl_TYPE_WINT_T_PREREQ
# Workaround from the nano package:
#   https://lists.nongnu.org/archive/html/nano-devel/2024-05/msg00017.html
export AUTOPOINT := true

%:
	dh $@

# Disabling auto-clean to work-around this build error:
#
#   dh clean
#      dh_auto_clean
#           make -j20 distclean
#   make[1]: Entering directory '/home/dima/debianstuff/datamash'
#   There seems to be no Makefile in this directory.
#   You must run ./configure before running 'make'.
override_dh_auto_clean:

execute_after_dh_auto_install:
	mkdir -p $(TMP)/usr/share/bash-completion/completions
	mv $(TMP)/usr/share/datamash/bash-completion.d/datamash $(TMP)/usr/share/bash-completion/completions
	rmdir $(TMP)/usr/share/datamash/bash-completion.d

	mkdir -p $(TMP)/usr/share/doc/datamash
	mv $(TMP)/usr/share/datamash/examples $(TMP)/usr/share/doc/datamash
	rmdir $(TMP)/usr/share/datamash
