[L/unstable 05/13] UBUNTU: [Packaging] simplify revision/release

Masahiro Yamada masahiro.yamada at canonical.com
Mon Dec 5 08:56:11 UTC 2022


Use "dpkg-parsepackage -S version" to get the version, and use Make's
built-in functions to split it into the upsteam-version and the
debian revision. This is more readable and works more efficiently.

BTW, GNU Make >= 3.81 supports $(lastword x) as a shorthand of
$(word $(words x), x).

Drop "revisions" and "prev_revisions", which are unused anywhere
except "printenv".

I did not get the use of "?=" for revision and prev_revison, but
I am keeping them in case I am missing something here.

Signed-off-by: Masahiro Yamada <masahiro.yamada at canonical.com>
---
 debian/rules.d/0-common-vars.mk | 15 +++++++--------
 debian/rules.d/1-maintainer.mk  |  2 --
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
index 104029dc0a8e..a54b83dd943b 100644
--- a/debian/rules.d/0-common-vars.mk
+++ b/debian/rules.d/0-common-vars.mk
@@ -1,5 +1,7 @@
 # Used when you need to 'escape' a comma.
 comma = ,
+empty :=
+space := $(empty) $(empty)
 
 #
 # The source package name will be the first token from $(DEBIAN)/changelog
@@ -10,15 +12,12 @@ src_pkg_name := $(shell dpkg-parsechangelog -l$(DEBIAN)/changelog -S source)
 series := $(shell dpkg-parsechangelog -l$(DEBIAN)/changelog -S distribution | sed -e 's/-\(security\|updates\|proposed\)$$//')
 
 # Get some version info
-release := $(shell sed -n '1s/^$(src_pkg_name).*(\(.*\)-.*).*$$/\1/p' $(DEBIAN)/changelog)
-revisions := $(shell sed -n 's/^$(src_pkg_name)\ .*($(release)-\(.*\)).*$$/\1/p' $(DEBIAN)/changelog | tac)
-revision ?= $(word $(words $(revisions)),$(revisions))
-prev_revisions := $(filter-out $(revision),0.0 $(revisions))
-ifneq (,$(prev_revisions))
-prev_revision := $(word $(words $(prev_revisions)),$(prev_revisions))
-endif
+version := $(shell dpkg-parsechangelog -l$(DEBIAN)/changelog -S version)
+revision ?= $(lastword $(subst -,$(space),$(version)))
+release := $(patsubst %-$(revision),%,$(version))
 
-prev_fullver ?= $(shell dpkg-parsechangelog -l$(DEBIAN)/changelog -o1 -c1 | sed -ne 's/^Version: *//p')
+prev_fullver ?= $(shell dpkg-parsechangelog -l$(DEBIAN)/changelog -o1 -c1 -S version)
+prev_revision := $(lastword 0.0 $(subst -,$(space),$(prev_fullver)))
 
 # Get variants. Assume primary if debian/variants is not present.
 variants = --
diff --git a/debian/rules.d/1-maintainer.mk b/debian/rules.d/1-maintainer.mk
index f20409ce6a72..1eb84f6b1943 100644
--- a/debian/rules.d/1-maintainer.mk
+++ b/debian/rules.d/1-maintainer.mk
@@ -78,10 +78,8 @@ printenv:
 	@echo "src package name  = $(src_pkg_name)"
 	@echo "series            = $(series)"
 	@echo "release           = $(release)"
-	@echo "revisions         = $(revisions)"
 	@echo "revision          = $(revision)"
 	@echo "uploadnum         = $(uploadnum)"
-	@echo "prev_revisions    = $(prev_revisions)"
 	@echo "prev_revision     = $(prev_revision)"
 	@echo "abinum            = $(abinum)"
 	@echo "upstream_tag      = $(upstream_tag)"
-- 
2.34.1




More information about the kernel-team mailing list