#!/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::
	dh_testdir
	# make sure that cli-include-path.patch is up to date
	if grep -r -E '(include|repair).*\.\./' cli | grep -v /site/; then \
		echo " ^ fix above include paths in cli directory ^" && false; \
	fi
	touch configure-stamp

override_dh_clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	dh_clean 
	debconf-updatepo

override_dh_auto_install::
	dh_testdir
	dh_testroot
	dh_clean
	dh_installdirs
	install -p *.php ${SITEDIR}/
	cp -pr scripts images include install lib ${SITEDIR}/
	cp -pr cli resource ${SHAREDIR}/
	find ${SHAREDIR}/cli -type f -print0 | xargs -0 file | \
		grep /usr/bin/php | cut -d: -f1 | xargs chmod ug+x
	# place the sql script where dbconfig-common wants it
	cp cacti.sql ${TDIR}/usr/share/dbconfig-common/data/cacti/install/mysql
	# normalize permissions in the site directory
	find ${RRADIR} ${SITEDIR}/ -exec chown root:www-data {} \;
	find ${SITEDIR}/ -type f -exec chmod 640 {} \;
	find ${SITEDIR}/scripts -type f -exec chmod 750 {} \;
	find ${SITEDIR}/ -type d -exec chmod 750 {} \;
	# and then fix the special case files
	find ${SITEDIR}/scripts -type f -name '*.php' -exec chmod 640 {} \;
	chmod 770 ${RRADIR}
	# remove all adodb code at build time, as we get this from libphp-adodb
	rm -rf ${SITEDIR}/lib/adodb
	# plop in our lintian override file
	cp debian/cacti.lintian-overrides ${TDIR}/usr/share/lintian/overrides/cacti
	

override_dh_installchangelogs::
	dh_installchangelogs docs/CHANGELOG

override_dh_fixperms::
	dh_fixperms -X/var/lib/cacti/rra
