#!/usr/bin/make -f

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

%:
	dh ${@} --with linktree

TDIR:=debian/cacti
SHAREDIR:=${TDIR}/usr/share/cacti
SITEDIR:=${SHAREDIR}/site
LIBDIR:=${TDIR}/var/lib/cacti

override_dh_auto_configure:
	# make sure that we catch it when cli-include-path.patch is not up-to-date
	if grep -r -E '(include|repair).*\.\./' cli | grep -v /site/; then \
		echo " ^ fix above include paths in cli directory ^" && false; \
	fi
	dh_auto_configure

override_dh_clean:
	# make sure that we catch translation updates
	debconf-updatepo
	dh_clean

override_dh_auto_build:
#	cd docs ; \
#		docbook2txt --dsl build/cacti.dsl#html2txt \
#		--output txt build/manual.sgml
#	cd docs ; \
#		docbook2html --dsl build/cacti.dsl#html \
#		--output html build/manual.sgml
#	cd docs ; \
#		docbook2pdf --dsl build/cacti.dsl#print \
#		--output pdf build/manual.sgml
	dh_auto_build

override_dh_installchangelogs:
	dh_installchangelogs docs/CHANGELOG

override_dh_fixperms:
	# normalize permissions in the site directory
	find ${LIBDIR}/* -exec chown root:www-data {} \;
	find ${LIBDIR}/* -type d -exec chmod 770 {} \;
	find ${SITEDIR}/ -type d -exec chmod 755 {} \;
	find ${SITEDIR}/ -type f -exec chmod 644 {} \;
	find ${SITEDIR}/scripts -type f -exec chmod 755 {} \;
	# and then fix the special case files
	find ${SITEDIR}/scripts -type f -name '*.php' -exec chmod 644 {} \;
	find ${SHAREDIR}/cli -type f -print0 | xargs -0 file | \
		grep -e /usr/bin/php -e "PHP script, ASCII text executable" | \
		cut -d: -f1 | xargs chmod 755

	dh_fixperms -X/var/lib/cacti

get-orig-source:
	uscan --verbose --force-download --repack --compression xz
