]> andersk Git - config-package-dev.git/blobdiff - divert.mk
divert.mk: Finish writing a sentence in the comments.
[config-package-dev.git] / divert.mk
index ffa4d3116edd8de2fa346ba3300e68fe703dbd70..9ad61caf12ccf17007b60949d367c130ab5da440 100644 (file)
--- a/divert.mk
+++ b/divert.mk
@@ -21,7 +21,9 @@
 # config-package.mk.
 
 # divert.mk handles the low-level diversion logic.  It includes
-# divert.sh.in in the postinst and prerm scripts, and adds 
+# divert.sh.in in the postinst and prerm scripts, and adds calls to the
+# functions in divert.sh.in to add and remove diversions and symlinks at
+# the appropriate points.
 
 ifndef _cdbs_rules_divert
 _cdbs_rules_divert = 1
@@ -53,10 +55,15 @@ endif
 # 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
+# Encode 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_6 := $(shell if [ '$(DH_COMPAT)' -ge 6 ]; then echo y; fi)
+
+reverse = $(foreach n,$(shell seq $(words $(1)) -1 1),$(word $(n),$(1)))
+reverse_dh_compat_6 = $(if $(dh_compat_6),$(call reverse,$(1)),$(1))
+
 debian-divert/%: package = $(subst debian-divert/,,$@)
 debian-divert/%: divert_files = $(DEB_DIVERT_FILES_$(package)) $(DEB_TRANSFORM_FILES_$(package))
 debian-divert/%: divert_remove_files = $(DEB_REMOVE_FILES_$(package))
@@ -88,22 +95,32 @@ $(patsubst %,debian-divert/%,$(DEB_DIVERT_PACKAGES)) :: debian-divert/%:
 # Add code to prerm script to undo diversions when package is removed.
        set -e; \
        { \
+           $(if $(dh_compat_6),, \
+               if [ -e $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper ]; then \
+                   cat $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper; \
+               fi;) \
            sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \
            $(if $(divert_files_thispkg), \
-               echo 'if [ "$$1" = "remove" ]; then'; \
-               $(foreach file,$(divert_files), \
+               echo 'if [ "$$1" = "remove" ] || [ "$$1" = "deconfigure" ]; then'; \
+               $(foreach file,$(call reverse_dh_compat_6,$(divert_files)), \
                    echo "    undivert_unlink $(call divert_files_replace_name,$(file), )";) \
-               $(foreach file,$(divert_remove_files), \
+               $(foreach file,$(call reverse_dh_compat_6,$(divert_remove_files)), \
                    echo "    undivert_unremove $(file) $(cdbs_curpkg)";) \
                echo 'fi'; \
            ) \
-       } >> $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper
+           $(if $(dh_compat_6), \
+               if [ -e $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper ]; then \
+                   cat $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper; \
+               fi;) \
+       } >> $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper.new
+       mv $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper.new \
+           $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper
 # Add an encoding of the names of the diverted files to the Provides:
 # and Conflicts: lists.  This prevents two packages diverting the same
 # file from being installed simultaneously (it cannot work, and this
 # produces a much less ugly error).  Requires in debian/control:
-#   Provides: $(diverted-files)
-#   Conflicts: $(diverted-files)
+#   Provides: ${diverted-files}
+#   Conflicts: ${diverted-files}
        set -e; \
        { \
            echo -n "diverted-files="; \
This page took 0.637648 seconds and 4 git commands to generate.