#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2003 Jonas Smedegaard <dr@jones.dk>

include debian/cdbs/1/rules/auto-update.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/patchsys-quilt.mk
include debian/cdbs/1/rules/buildinfo.mk
include debian/cdbs/1/rules/copyright-check.mk

DEB_INSTALL_CHANGELOGS_ALL = docs/awstats_changelog.txt
DEB_INSTALL_DOCS_ALL = README.TXT

awstats_example_scripts = $(wildcard tools/*.pl) $(wildcard debian/examples/*.sh) debian/examples/awstats-update

DEB_INSTALL_EXAMPLES_awstats = $(awstats_example_scripts) debian/examples/apache.conf debian/examples/awstats-update.8 wwwroot/cgi-bin/awstats.model.conf wwwroot/cgi-bin/plugins/example/* wwwroot/css wwwroot/js tools/xslt
DEB_COMPRESS_EXCLUDE = $(notdir $(awstats_example_scripts)) awstats.ico

pre-build::
	(cd debian/icons && uudecode firefox.png.uu)

common-configure-indep::
	# Use sed rather than a diff here, to make sure all relevant
	# options are checked (upstream defaults have moved around in
	# the past)
	sed \
		-e 's!^\(LogFile *= *\).*!\1"/var/log/apache/access.log"!g' \
		-e 's!^\(DirData *= *\).*!\1"/var/lib/awstats"!g' \
		-e 's!^\(LogFormat *= *\).*!\14!g' \
		-e 's!^\(DNSLookup *= *\).*!\11!g' \
		-e 's!^\(DirIcons *= *\).*!\1"/awstats-icon"!g' \
		-e 's!^\(HostAliases *= *\).*!\1"localhost 127\.0\.0\.1"!g' \
		-e 's!^\(DirLang *= *\).*!\1"/usr/share/awstats/lang"!g' \
		-e 's!^#\(LoadPlugin *= *"hashfiles"\)!\1!' \
		-e 's!^#\(Include *\)""!\1"/etc/awstats/awstats.conf.local"!' \
		wwwroot/cgi-bin/awstats.model.conf > debian/awstats.conf

clean::
	rm -f debian/awstats.conf debian/firefox.png

# Remove badly coded PDF
binary-post-install/awstats::
	find $(DEB_DESTDIR) -type f -name *.pdf | xargs -r rm

# Debian stores the GPL at one single spot
binary-post-install/awstats::
	find $(DEB_DESTDIR) -name COPYING.TXT -o -name LICENSE.TXT | xargs -r rm

# Set scripts executable - and unset other files
binary-fixup/awstats::
	find $(DEB_DESTDIR)/usr/share/awstats -type f | xargs -r chmod -x
	find $(DEB_DESTDIR)/usr/share/doc/awstats/examples -name *.pl -o -name *.sh | xargs -r chmod +x

# Set example scripts executable - and unset for remaining example files
binary-fixup/awstats::
	chmod -x,+X -R $(DEB_DESTDIR)/usr/share/doc/awstats/examples/
	chmod +x $(addprefix $(DEB_DESTDIR)/usr/share/doc/awstats/examples/,$(notdir $(awstats_example_scripts)))

binary-predep/awstats::
	dh_perl -p$(DEB_CURPACKAGE)
