+# Replace only the last instance of DEB_DIVERT_EXTENSION in the
+# filename, to make it possible to divert /path/foo.divert to
+# foo.divert.divert-orig
+divert_files_replace_name = $(shell echo $(1) | perl -pe 's/(.*)\Q$(DEB_DIVERT_EXTENSION)\E/$$1$(2)/')
+
+# Transform a full path into the path it should be diverted to if it's
+# removed
+remove_files_name = /usr/share/$(cdbs_curpkg)/$(shell $(DEB_DIVERT_ENCODER) $(1))
+
+dh_compat_5 := $(shell if [ '$(DH_COMPAT)' -ge 5 ]; then echo y; fi)
+
+reverse = $(foreach n,$(shell seq $(words $(1)) -1 1),$(word $(n),$(1)))
+reverse_dh_compat_5 = $(if $(dh_compat_5),$(call reverse,$(1)),$(1))