]>
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 | ||
20 | ifndef _cdbs_rules_divert | |
21 | _cdbs_rules_divert = 1 | |
22 | ||
936cb21e | 23 | CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), config-package-dev (>= 4.4) |
ab8e2a67 TA |
24 | |
25 | DEB_DIVERT_SCRIPT = /usr/share/config-package-dev/divert.sh.in | |
26 | ||
27 | DEB_DIVERT_PACKAGES += $(foreach package,$(DEB_ALL_PACKAGES), \ | |
c5ca58a5 | 28 | $(if $(DEB_REPLACE_FILES_$(package)),$(package), \ |
936cb21e TA |
29 | $(if $(DEB_REMOVE_FILES_$(package)),$(package), \ |
30 | $(if $(DEB_UNREMOVE_FILES_$(package)),$(package), \ | |
31 | $(if $(DEB_UNDIVERT_FILES_$(package)),$(package), \ | |
32 | $(if $(DEB_DIVERT_FILES_$(package)),$(package))))))) | |
ab8e2a67 TA |
33 | |
34 | ifeq ($(DEB_DIVERT_EXTENSION),) | |
35 | DEB_DIVERT_EXTENSION = .divert | |
36 | endif | |
37 | ||
38 | DEB_DIVERT_ENCODER = /usr/share/config-package-dev/encode | |
39 | ||
936cb21e TA |
40 | divert_files_replace_name = $(shell echo $(1) | perl -pe 's/(.*)\Q$(DEB_DIVERT_EXTENSION)\E/$$1$(2)/') |
41 | ||
ab8e2a67 | 42 | debian-divert/%: package = $(subst debian-divert/,,$@) |
936cb21e TA |
43 | debian-divert/%: divert_files = $(DEB_DIVERT_FILES_$(package)) $(DEB_REPLACE_FILES_$(package)) |
44 | debian-divert/%: divert_remove_files = $(DEB_REMOVE_FILES_$(package)) | |
45 | debian-divert/%: divert_undivert_files = $(DEB_UNDIVERT_FILES_$(package)) | |
46 | debian-divert/%: divert_unremove_files = $(DEB_UNREMOVE_FILES_$(package)) | |
47 | debian-divert/%: divert_files_all = $(strip $(divert_files) $(divert_remove_files) $(divert_undivert_files) $(divert_unremove_files)) | |
48 | debian-divert/%: divert_files_thispkg = $(strip $(divert_files) $(divert_remove_files)) | |
ab8e2a67 TA |
49 | $(patsubst %,debian-divert/%,$(DEB_DIVERT_PACKAGES)) :: debian-divert/%: |
50 | ( \ | |
51 | sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ | |
936cb21e | 52 | $(if $(divert_files_all), \ |
ab8e2a67 | 53 | echo 'if [ "$$1" = "configure" ]; then'; \ |
936cb21e TA |
54 | $(foreach file,$(divert_undivert_files), \ |
55 | $(if $(DEB_UNDIVERT_FILES_VERSION_$(file)),,\ | |
56 | echo "ERROR! Missing undivert version for $(file)!">&2; exit 1;) \ | |
57 | echo -n " if [ -n \"\$$2\" ] && dpkg --compare-versions \"\$$2\" '<<' "; \ | |
58 | echo "'$(DEB_UNDIVERT_FILES_VERSION_$(file))'; then"; \ | |
59 | echo " undivert_unlink $(call divert_files_replace_name,$(file), )"; \ | |
60 | echo " fi";) \ | |
61 | $(foreach file,$(divert_unremove_files), \ | |
62 | $(if $(DEB_UNREMOVE_FILES_VERSION_$(file)),,\ | |
63 | echo "ERROR! Missing unremove version for $(file)!">&2; exit 1;) \ | |
64 | echo -n " if [ -n \"\$$2\" ] && dpkg --compare-versions \"\$$2\" '<<' "; \ | |
65 | echo "'$(DEB_UNREMOVE_FILES_VERSION_$(file))'; then"; \ | |
66 | echo " undivert_unremove $(file)"; \ | |
67 | echo " fi";) \ | |
ab8e2a67 | 68 | $(foreach file,$(divert_files), \ |
936cb21e TA |
69 | echo " divert_link $(call divert_files_replace_name,$(file), )";) \ |
70 | $(foreach file,$(divert_remove_files), \ | |
71 | mkdir -p $(DEB_DESTDIR)/usr/share/$(cdbs_curpkg); \ | |
72 | echo " divert_remove $(file) /usr/share/$(cdbs_curpkg)/`$(DEB_DIVERT_ENCODER) $(file)`";) \ | |
ab8e2a67 TA |
73 | echo 'fi'; \ |
74 | ) \ | |
75 | ) >> $(CURDIR)/debian/$(cdbs_curpkg).postinst.debhelper | |
76 | ( \ | |
77 | sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \ | |
936cb21e | 78 | $(if $(divert_files_thispkg), \ |
ab8e2a67 TA |
79 | echo 'if [ "$$1" = "remove" ]; then'; \ |
80 | $(foreach file,$(divert_files), \ | |
936cb21e TA |
81 | echo " undivert_unlink $(call divert_files_replace_name,$(file), )";) \ |
82 | $(foreach file,$(divert_remove_files), \ | |
83 | echo " undivert_unremove $(file) $(cdbs_curpkg)";) \ | |
ab8e2a67 TA |
84 | echo 'fi'; \ |
85 | ) \ | |
86 | ) >> $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper | |
87 | ( \ | |
88 | echo -n "diverted-files="; \ | |
936cb21e TA |
89 | $(foreach file,$(divert_files_thispkg),\ |
90 | echo -n "configures-"; \ | |
91 | ${DEB_DIVERT_ENCODER} "$(call divert_files_replace_name,$(file))"; \ | |
ab8e2a67 TA |
92 | echo -n ", ";) \ |
93 | echo \ | |
94 | ) >> $(CURDIR)/debian/$(cdbs_curpkg).substvars | |
95 | ||
96 | $(patsubst %,binary-fixup/%,$(DEB_DIVERT_PACKAGES)) :: binary-fixup/%: debian-divert/% | |
97 | ||
98 | endif |