#! /bin/sh
# This file writes debian/substvars and appends it to
# debian/$packages.substvars. Called from common/rules.mk after dh_shlibdeps.
# $Id$

listpackages=debian/common/list-packages
chmod +x $listpackages

OUT=debian/substvars
exec >$OUT

# Package version, package upstream version, package next upstream version
VERSION=`dpkg-parsechangelog | grep -E '^Version:' | cut -f 2 -d ' '`
VERSION_NODEB=`echo $VERSION | sed -e s/-[^-]*$//`
VERSION_NODEB_NEXT=`echo $VERSION_NODEB | perl -pe 's/(?<=\.)(\d+)$/($1+1)/e'`

# Build-Dependencies on kdelibs4-dev go like kdelibs4-dev (>> ${Source-Version-NoDebRev})
echo "Source-Version-NoDebRev=$VERSION_NODEB"

# This next two loops provide a ${Variable} for each package, with the
# following dependency policy: dependencies on arch-specific packages
# use an exact version; dependencies on arch-all packages only require
# the same upstream version (to allow binary NMUs).
#
# Later, it should be discussed the tightening the policy to: "packages
# from a same source package must be all at the same version." See my
# comments on Bug#276607. Currently, only packages with dependencies
# between them are forced to be the same version; the commented third
# loop would force *all* packages from a same source to be at the same
# version. Hopefully it won't be necessary.

for p in `$listpackages arch`; do
  echo "$p:Depends=$p (= $VERSION)"
done

for p in `$listpackages indep`; do
  echo "$p:Depends=$p (>> $VERSION_NODEB), $p (<< $VERSION_NODEB_NEXT)"
done

# Conflicts for $source-base
# echo -n "Strict-Conflicts="
# for p in `$listpackages arch`; do
#   echo -n "$p (<< $VERSION_NODEB), $p (>> $VERSION_NODEB_NEXT),"
# done
# echo

# I'd like to know if this can be done less uglyly
for p in `$listpackages`; do
  cat $OUT >>debian/$p.substvars
done
