#!/usr/bin/make -f
# Copyright 2001, 2002, 2007  Matt Kraai
# Copyright 2010, 2016, 2021  Peter Pentchev

export PYBUILD_NAME=tina_mgr

# Aim for the top, adapt if anything should break on the buildds.
DEB_BUILD_MAINT_OPTIONS=	hardening=+all
export DEB_BUILD_MAINT_OPTIONS

DEB_CFLAGS_MAINT_APPEND=	-Wall -W -std=c99 -pedantic -Wbad-function-cast \
		-Wcast-align -Wcast-qual -Wchar-subscripts -Winline \
		-Wmissing-prototypes -Wnested-externs -Wpointer-arith \
		-Wredundant-decls -Wshadow -Wwrite-strings
ifneq (,$(filter werror,$(DEB_BUILD_OPTIONS)))
	DEB_CFLAGS_MAINT_APPEND+=	-Werror
endif
export DEB_CFLAGS_MAINT_APPEND

include /usr/share/dpkg/default.mk

packages:=	$(shell dh_listpackages)

execute_after_dh_auto_clean:
	dh_auto_clean --buildsystem=pybuild

execute_after_dh_auto_build:
	dh_auto_build --buildsystem=pybuild

execute_after_dh_auto_test:
	env TINA='$(CURDIR)/tina' dh_auto_test --buildsystem=pybuild

execute_after_dh_auto_install:
	dh_auto_install --buildsystem=pybuild

execute_after_dh_install:
ifneq (,$(filter tina,$(packages)))
	mv 'debian/python3-tina-mgr/usr/bin/tina-convert' 'debian/tina/usr/bin/'
else
	rm 'debian/python3-tina-mgr/usr/bin/tina-convert'
endif
	rmdir 'debian/python3-tina-mgr/usr/bin'

override_dh_installchangelogs:
	dh_installchangelogs -X ChangeLog -X NEWS -X changes.md
ifneq (,$(filter tina,$(packages)))
	install -m 644 docs/changes.md debian/tina/usr/share/doc/tina/NEWS.md
endif

%:
	dh $@
