#!/usr/bin/make -f
# Sample CDBS+ rules file for pure data packages.
#
# Copyright 2007 by Michael Hanke <michael.hanke@gmail.com> licensed under the
# terms of the GNU General Public License (v2 or later)
#
# This rules file (together with the dh_datapkg script) implements the idea of
# virtually empty source packages for packages providing huge arch-all datasets.
# The goal is to prevent wasting disk space and bandwidth by not duplicating the
# datasets in source AND binary packages.
# This idea was outlined by Anthony Towns in a post to the Debian-devel
# mailing list:
#
# http://lists.debian.org/debian-devel/2007/06/msg00298.html
#
# The basic concept is to let the source package build-depend on the exact
# version of the arch-all binary package it builds, to be able to use the
# datafiles from the installed packages when (re)building the packages.

include /usr/share/cdbs/1/rules/debhelper.mk

DEB_DH_INSTALL_ARGS = --sourcedir=$(CURDIR)


populate-src-package:
# populate the source package
# dh_datapkg passes all arguments to the 'update-data' call in case of a
# package upgrade. 'update-data' should accept the to be processed upstream
# version as first positional argument
	debian/dh_datapkg $(DEB_UPSTREAM_VERSION)

# copy all addons from the Debian packaging
	cp --target-directory=$(CURDIR) debian/addon/*

	touch $@


build/$(DEB_INDEP_PACKAGES):: populate-src-package


clean::
# add build-depends on all arch-indep packages with the exact Debian version
	for pkg in $(DEB_INDEP_PACKAGES); do \
		deps="$${deps} $${pkg} (= $(DEB_VERSION)),"; \
	done; \
	sed -e "s/Build-Depends:/Build-Depends:$${deps}/" \
		debian/control.in > debian/control

# remove source package content
	rm -rf $(shell cat debian/*install | awk '{ print $$1 }') doc

	-rm populate-src-package


orig-src: clean
# create a properly named tarball from the content of the source package
# root directory while excluding debian/ and several SCM status files
	tar cvzf ../$(DEB_SOURCE_PACKAGE)_$(DEB_UPSTREAM_VERSION).orig.tar.gz \
		--exclude={debian,.git,.svn,.CVS} \
		--directory=.. \
		$(shell basename $(CURDIR))
