Joseph Herlant
version 1.0.0, 2014-06-16 : Initial version

If you’re using cdbs, it’s simple: use the "$(DEB_UPSTREAM_VERSION)" variable defined in the /usr/share/cdbs/1/rules/ file.

If you’re using debhelper, you can use /usr/share/dpkg/ file from dpkg-dev which defines this "$(DEB_UPSTREAM_VERSION)" variable.

This last file defines some usefull variables as: * DEB_SOURCE: the source package name * DEB_VERSION: the full version of the package (epoch + upstream vers.
revision) * DEB_VERSION_EPOCH_UPSTREAM: the package’s version without the Debian revision * DEB_VERSION_UPSTREAM_REVISION: the package’s version without the Debian epoch * DEB_VERSION_UPSTREAM: the package’s upstream version * DEB_DISTRIBUTION: the distribution(s) listed in the current entry of debian/changelog

If you still want to redefine it. You can use, for example:

DEB_UPSTREAM_VERSION ?= $(shell dpkg-parsechangelog \
                          | sed -rne 's/^Version: ([0-9.]+)[-+].*$$/\1/p')

But if you want, you can still use exactly the same way as cdbs did (also added some other usefull variables that were defined in this makefile):

# Gets the name of the source package
DEB_SOURCE_PACKAGE := $(strip $(shell egrep '^Source: ' debian/control | cut -f 2 -d ':'))

# Gets the full version of the source package including debian version
DEB_VERSION := $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
DEB_NOEPOCH_VERSION := $(shell echo $(DEB_VERSION) | cut -d: -f2-)
# Gets only the upstream version of the package
DEB_UPSTREAM_VERSION := $(shell echo $(DEB_NOEPOCH_VERSION) | sed 's/-[^-]*$$//')

# Prints the version line if the package is native. Nothing for a non native package
DEB_ISNATIVE := $(shell dpkg-parsechangelog | egrep '^Version:' | perl -ne 'print if not /^Version:\s*.*-/;')