#!/usr/bin/make -f

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

%:
	dh ${@}

CFLAGS = -Wall -g

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

override_dh_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

override_dh_clean:
	# make sure that we catch translation updates
	debconf-updatepo
	# remove all adodb code as we get this from libphp-adodb
	# you can prevent git from showing these as missing with:
	# find lib/adodb -type f -exec git update-index --assume-unchanged {} \;
	rm -rf lib/adodb
	dh_clean

override_dh_installchangelogs:
	dh_installchangelogs docs/CHANGELOG

override_dh_fixperms:
	# normalize permissions in the site directory
	find ${RRADIR} -exec chown root:www-data {} \;
	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 {} \;
	chmod 770 ${RRADIR}
	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/rra

get-orig-source:
	-uscan --rename --force-download
