X-Git-Url: http://andersk.mit.edu/gitweb/config-package-dev.git/blobdiff_plain/567091347bd3fe6087395e06f4d50dd24ff0571c..0515debb5b875ac6b4002953cdae5206485d0937:/divert.mk diff --git a/divert.mk b/divert.mk index 483c9a9..6212abe 100644 --- a/divert.mk +++ b/divert.mk @@ -53,6 +53,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 +# 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)) + 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)) @@ -64,58 +73,61 @@ $(patsubst %,debian-divert/%,$(DEB_DIVERT_PACKAGES)) :: debian-divert/%: # Writing shell scripts in makefiles sucks. Remember to $$ shell # variables and include \ at the end of each line. # Add code to postinst to add/remove diversions as appropriate - ( \ + set -e; \ + { \ sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ $(if $(divert_files_all), \ echo 'if [ "$$1" = "configure" ]; then'; \ $(foreach file,$(divert_undivert_files), \ - $(if $(DEB_UNDIVERT_VERSION_$(file)),,\ - echo "ERROR! Missing undivert version for $(file)!">&2; exit 1;) \ - echo -n " if [ -n \"\$$2\" ] && dpkg --compare-versions \"\$$2\" '<<' "; \ - echo "'$(DEB_UNDIVERT_VERSION_$(file))'; then"; \ - echo " undivert_unlink $(call divert_files_replace_name,$(file), )"; \ - echo " fi";) \ + echo " check_undivert_unlink $(call divert_files_replace_name,$(file), )"; )\ $(foreach file,$(divert_unremove_files), \ - $(if $(DEB_UNREMOVE_VERSION_$(file)),,\ - echo "ERROR! Missing unremove version for $(file)!">&2; exit 1;) \ - echo -n " if [ -n \"\$$2\" ] && dpkg --compare-versions \"\$$2\" '<<' "; \ - echo "'$(DEB_UNREMOVE_VERSION_$(file))'; then"; \ - echo " undivert_unremove $(file)"; \ - echo " fi";) \ + echo " check_undivert_unremove $(file) $(call remove_files_name,$(file))"; )\ $(foreach file,$(divert_files), \ echo " divert_link $(call divert_files_replace_name,$(file), )";) \ $(foreach file,$(divert_remove_files), \ - mkdir -p $(DEB_DESTDIR)/usr/share/$(cdbs_curpkg); \ - echo " divert_remove $(file) /usr/share/$(cdbs_curpkg)/`$(DEB_DIVERT_ENCODER) $(file)`";) \ + mkdir -p debian/$(cdbs_curpkg)/usr/share/$(cdbs_curpkg); \ + echo " divert_remove $(file) $(call remove_files_name,$(file))";) \ echo 'fi'; \ ) \ - ) >> $(CURDIR)/debian/$(cdbs_curpkg).postinst.debhelper + } >> $(CURDIR)/debian/$(cdbs_curpkg).postinst.debhelper # Add code to prerm script to undo diversions when package is removed. - ( \ + set -e; \ + { \ + $(if $(dh_compat_5),, \ + 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), \ + $(foreach file,$(call reverse_dh_compat_5,$(divert_files)), \ echo " undivert_unlink $(call divert_files_replace_name,$(file), )";) \ - $(foreach file,$(divert_remove_files), \ + $(foreach file,$(call reverse_dh_compat_5,$(divert_remove_files)), \ echo " undivert_unremove $(file) $(cdbs_curpkg)";) \ echo 'fi'; \ ) \ - ) >> $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper + $(if $(dh_compat_5), \ + 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) - ( \ + set -e; \ + { \ echo -n "diverted-files="; \ $(foreach file,$(divert_files_thispkg),\ echo -n "diverts-"; \ ${DEB_DIVERT_ENCODER} "$(call divert_files_replace_name,$(file))"; \ echo -n ", ";) \ - echo \ - ) >> $(CURDIR)/debian/$(cdbs_curpkg).substvars + echo; \ + } >> $(CURDIR)/debian/$(cdbs_curpkg).substvars $(patsubst %,binary-post-install/%,$(DEB_DIVERT_PACKAGES)) :: binary-post-install/%: debian-divert/%