#!/usr/bin/make -f
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

CONTRIB_EXAMPLES = debian/mrtg-contrib/usr/share/doc/mrtg/examples

%:
	dh $@

# Using *-indep to avoid issues when building arch dependent binary only

override_dh_install-indep:
	dh_install

	# xlsummary depends on non-free software. See #293641.
	rm -rf $(CONTRIB_EXAMPLES)/xlsummary

	# Removing extra licensing files
	find $(CONTRIB_EXAMPLES) -name COPYING -exec rm -f {} \;

	# Fix hashbangs: c:\perl\bin
	egrep -sri '#!c:\\perl\\bin' $(CONTRIB_EXAMPLES) | cut -d: -f1 | \
            xargs sed -i 's/#!c:\\perl\\bin/#!\/usr\/bin\/perl/'

	# Fix all Unixes hashbangs with 'perl'
	egrep -sr '^#!\/[a-z/]+perl[0-9]?' $(CONTRIB_EXAMPLES) | cut -d: -f1 | \
            xargs sed -i 's/^#!\/[a-z/]\+perl[0-9]\?/#!\/usr\/bin\/perl/'

	# Convert all files to Unix EOL style
	find $(CONTRIB_EXAMPLES) -type f -exec dos2unix -q {} \;

	# Create symlinks for duplicate files
	jdupes -rl $(CONTRIB_EXAMPLES)

override_dh_fixperms-indep:
	# There are several examples with wrong permissions for Unix, so
        # changing all regular files to 644 is a good idea because they are
        # examples only. Note that dh_fixperms will change some permissions
        # again.
	find $(CONTRIB_EXAMPLES) -type f -exec chmod 644 {} \;
	dh_fixperms

override_dh_compress-indep:
	dh_compress -Xexamples/
