]>
Commit | Line | Data |
---|---|---|
ab8e2a67 TA |
1 | # -*- mode: makefile; coding: utf-8 -*- |
2 | # Copyright © 2007-2008 Anders Kaseorg <andersk@mit.edu> and | |
3 | # Tim Abbott <tabbott@mit.edu> | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or | |
6 | # modify it under the terms of the GNU General Public License as | |
7 | # published by the Free Software Foundation; either version 2, or (at | |
8 | # your option) any later version. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, but | |
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | # General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
18 | # 02111-1307 USA. | |
19 | ||
56709134 TA |
20 | # Don't include divert.mk in your rules files directly; instead use |
21 | # config-package.mk. | |
22 | ||
23 | # divert.mk handles the low-level diversion logic. It includes | |
24 | # divert.sh.in in the postinst and prerm scripts, and adds | |
25 | ||
ab8e2a67 TA |
26 | ifndef _cdbs_rules_divert |
27 | _cdbs_rules_divert = 1 | |
28 | ||
be43c288 TA |
29 | include /usr/share/cdbs/1/rules/debhelper.mk |
30 | ||
02bde96f | 31 | CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), config-package-dev (>= 4.5~) |
ab8e2a67 | 32 | |
56709134 TA |
33 | # divert.sh.in is included in the postinst/prerm scripts of packages |
34 | # installing diversions using config-package-dev. | |
ab8e2a67 | 35 | DEB_DIVERT_SCRIPT = /usr/share/config-package-dev/divert.sh.in |
56709134 TA |
36 | # script used to encode the path of a file uniquely in a valid virtual |
37 | # package name. | |
38 | DEB_DIVERT_ENCODER = /usr/share/config-package-dev/encode | |
ab8e2a67 TA |
39 | |
40 | DEB_DIVERT_PACKAGES += $(foreach package,$(DEB_ALL_PACKAGES), \ | |
02bde96f | 41 | $(if $(DEB_TRANSFORM_FILES_$(package)),$(package), \ |
936cb21e TA |
42 | $(if $(DEB_REMOVE_FILES_$(package)),$(package), \ |
43 | $(if $(DEB_UNREMOVE_FILES_$(package)),$(package), \ | |
44 | $(if $(DEB_UNDIVERT_FILES_$(package)),$(package), \ | |
45 | $(if $(DEB_DIVERT_FILES_$(package)),$(package))))))) | |
ab8e2a67 TA |
46 | |
47 | ifeq ($(DEB_DIVERT_EXTENSION),) | |
48 | DEB_DIVERT_EXTENSION = .divert | |
49 | endif | |
50 | ||
56709134 TA |
51 | # Replace only the last instance of DEB_DIVERT_EXTENSION in the |
52 | # filename, to make it possible to divert /path/foo.divert to | |
53 | # foo.divert.divert-orig | |
936cb21e TA |
54 | divert_files_replace_name = $(shell echo $(1) | perl -pe 's/(.*)\Q$(DEB_DIVERT_EXTENSION)\E/$$1$(2)/') |
55 | ||
ab8e2a67 | 56 | debian-divert/%: package = $(subst debian-divert/,,$@) |
02bde96f | 57 | debian-divert/%: divert_files = $(DEB_DIVERT_FILES_$(package)) $(DEB_TRANSFORM_FILES_$(package)) |
936cb21e TA |
58 | debian-divert/%: divert_remove_files = $(DEB_REMOVE_FILES_$(package)) |
59 | debian-divert/%: divert_undivert_files = $(DEB_UNDIVERT_FILES_$(package)) | |
60 | debian-divert/%: divert_unremove_files = $(DEB_UNREMOVE_FILES_$(package)) | |
61 | debian-divert/%: divert_files_all = $(strip $(divert_files) $(divert_remove_files) $(divert_undivert_files) $(divert_unremove_files)) | |
62 | debian-divert/%: divert_files_thispkg = $(strip $(divert_files) $(divert_remove_files)) | |
ab8e2a67 | 63 | $(patsubst %,debian-divert/%,$(DEB_DIVERT_PACKAGES)) :: debian-divert/%: |
56709134 TA |
64 | # Writing shell scripts in makefiles sucks. Remember to $$ shell |
65 | # variables and include \ at the end of each line. | |
66 | # Add code to postinst to add/remove diversions as appropriate | |
3aab360a AK |
67 | set -e; \ |
68 | { \ | |
ab8e2a67 | 69 | sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ |
936cb21e | 70 | $(if $(divert_files_all), \ |
ab8e2a67 | 71 | echo 'if [ "$$1" = "configure" ]; then'; \ |
936cb21e | 72 | $(foreach file,$(divert_undivert_files), \ |
02bde96f | 73 | $(if $(DEB_UNDIVERT_VERSION_$(file)),,\ |
936cb21e TA |
74 | echo "ERROR! Missing undivert version for $(file)!">&2; exit 1;) \ |
75 | echo -n " if [ -n \"\$$2\" ] && dpkg --compare-versions \"\$$2\" '<<' "; \ | |
02bde96f | 76 | echo "'$(DEB_UNDIVERT_VERSION_$(file))'; then"; \ |
936cb21e TA |
77 | echo " undivert_unlink $(call divert_files_replace_name,$(file), )"; \ |
78 | echo " fi";) \ | |
79 | $(foreach file,$(divert_unremove_files), \ | |
02bde96f | 80 | $(if $(DEB_UNREMOVE_VERSION_$(file)),,\ |
936cb21e TA |
81 | echo "ERROR! Missing unremove version for $(file)!">&2; exit 1;) \ |
82 | echo -n " if [ -n \"\$$2\" ] && dpkg --compare-versions \"\$$2\" '<<' "; \ | |
02bde96f | 83 | echo "'$(DEB_UNREMOVE_VERSION_$(file))'; then"; \ |
936cb21e TA |
84 | echo " undivert_unremove $(file)"; \ |
85 | echo " fi";) \ | |
ab8e2a67 | 86 | $(foreach file,$(divert_files), \ |
936cb21e TA |
87 | echo " divert_link $(call divert_files_replace_name,$(file), )";) \ |
88 | $(foreach file,$(divert_remove_files), \ | |
a7a01014 | 89 | mkdir -p debian/$(cdbs_curpkg)/usr/share/$(cdbs_curpkg); \ |
936cb21e | 90 | echo " divert_remove $(file) /usr/share/$(cdbs_curpkg)/`$(DEB_DIVERT_ENCODER) $(file)`";) \ |
ab8e2a67 TA |
91 | echo 'fi'; \ |
92 | ) \ | |
3aab360a | 93 | } >> $(CURDIR)/debian/$(cdbs_curpkg).postinst.debhelper |
56709134 | 94 | # Add code to prerm script to undo diversions when package is removed. |
3aab360a AK |
95 | set -e; \ |
96 | { \ | |
ab8e2a67 | 97 | sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ |
936cb21e | 98 | $(if $(divert_files_thispkg), \ |
ab8e2a67 TA |
99 | echo 'if [ "$$1" = "remove" ]; then'; \ |
100 | $(foreach file,$(divert_files), \ | |
936cb21e TA |
101 | echo " undivert_unlink $(call divert_files_replace_name,$(file), )";) \ |
102 | $(foreach file,$(divert_remove_files), \ | |
103 | echo " undivert_unremove $(file) $(cdbs_curpkg)";) \ | |
ab8e2a67 TA |
104 | echo 'fi'; \ |
105 | ) \ | |
3aab360a | 106 | } >> $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper |
56709134 TA |
107 | # Add an encoding of the names of the diverted files to the Provides: |
108 | # and Conflicts: lists. This prevents two packages diverting the same | |
109 | # file from being installed simultaneously (it cannot work, and this | |
110 | # produces a much less ugly error). Requires in debian/control: | |
111 | # Provides: $(diverted-files) | |
112 | # Conflicts: $(diverted-files) | |
3aab360a AK |
113 | set -e; \ |
114 | { \ | |
ab8e2a67 | 115 | echo -n "diverted-files="; \ |
936cb21e | 116 | $(foreach file,$(divert_files_thispkg),\ |
56709134 | 117 | echo -n "diverts-"; \ |
936cb21e | 118 | ${DEB_DIVERT_ENCODER} "$(call divert_files_replace_name,$(file))"; \ |
ab8e2a67 | 119 | echo -n ", ";) \ |
3aab360a AK |
120 | echo; \ |
121 | } >> $(CURDIR)/debian/$(cdbs_curpkg).substvars | |
ab8e2a67 | 122 | |
be43c288 | 123 | $(patsubst %,binary-post-install/%,$(DEB_DIVERT_PACKAGES)) :: binary-post-install/%: debian-divert/% |
ab8e2a67 TA |
124 | |
125 | endif |