source: trunk/debathena/debathena/config-package-dev/displace.mk @ 25844

Revision 25844, 6.7 KB checked in by geofft, 12 years ago (diff)
Sync config-package-dev 5.0 from Debian unstable.
Line 
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# Don't include displace.mk in your rules files directly; instead use
21# config-package.mk.
22
23# displace.mk handles the low-level diversion logic.  It includes
24# displace.sh.in in the postinst and prerm scripts, and adds calls to
25# the functions in displace.sh.in to add and remove diversions and
26# symlinks at the appropriate points.
27
28ifndef _cdbs_rules_displace
29_cdbs_rules_displace = 1
30
31include /usr/share/cdbs/1/rules/debhelper.mk
32
33CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), config-package-dev (>= 5.0~)
34
35# displace.sh.in is included in the postinst/prerm scripts of packages
36# installing diversions and symlinks using config-package-dev.
37DEB_DISPLACE_SCRIPT = /usr/share/debhelper/autoscripts/displace.sh.in
38# script used to encode the path of a file uniquely in a valid virtual
39# package name.
40DEB_DISPLACE_ENCODER = /usr/share/config-package-dev/encode
41
42DEB_DISPLACE_PACKAGES += $(foreach package,$(DEB_ALL_PACKAGES), \
43    $(if $(DEB_TRANSFORM_FILES_$(package)),$(package), \
44    $(if $(DEB_HIDE_FILES_$(package)),$(package), \
45    $(if $(DEB_UNHIDE_FILES_$(package)),$(package), \
46    $(if $(DEB_UNDISPLACE_FILES_$(package)),$(package), \
47    $(if $(DEB_DISPLACE_FILES_$(package)),$(package), \
48    $(if $(DEB_REMOVE_FILES_$(package)),$(package), \
49    $(if $(DEB_UNREMOVE_FILES_$(package)),$(package), \
50    $(if $(DEB_UNDIVERT_FILES_$(package)),$(package), \
51    $(if $(DEB_DIVERT_FILES_$(package)),$(package)))))))))))
52
53ifeq ($(DEB_DISPLACE_EXTENSION),)
54ifeq ($(DEB_DIVERT_EXTENSION),)
55DEB_DISPLACE_EXTENSION = .divert
56else
57DEB_DISPLACE_EXTENSION = $(DEB_DIVERT_EXTENSION)
58endif
59endif
60
61# Replace only the last instance of DEB_DISPLACE_EXTENSION in the
62# filename, to make it possible to displace /path/foo.divert to
63# foo.divert.divert-orig
64displace_files_replace_name = $(shell echo $(1) | perl -pe 's/(.*)\Q$(DEB_DISPLACE_EXTENSION)\E/$$1$(2)/')
65
66# Encode a full path into the path it should be diverted to if it's
67# hidden
68hide_files_name = /usr/share/$(cdbs_curpkg)/$(shell $(DEB_DISPLACE_ENCODER) $(1))
69
70dh_compat_6 := $(shell if [ '$(DH_COMPAT)' -ge 6 ]; then echo y; fi)
71
72reverse = $(foreach n,$(shell seq $(words $(1)) -1 1),$(word $(n),$(1)))
73reverse_dh_compat_6 = $(if $(dh_compat_6),$(call reverse,$(1)),$(1))
74
75debian-displace/%: package = $(subst debian-displace/,,$@)
76debian-displace/%: displace_files = $(DEB_DISPLACE_FILES_$(package)) $(DEB_DIVERT_FILES_$(package)) $(DEB_TRANSFORM_FILES_$(package))
77debian-displace/%: displace_hide_files = $(DEB_HIDE_FILES_$(package)) $(DEB_REMOVE_FILES_$(package))
78debian-displace/%: displace_undisplace_files = $(DEB_UNDISPLACE_FILES_$(package)) $(DEB_UNDIVERT_FILES_$(package))
79debian-displace/%: displace_unhide_files = $(DEB_UNHIDE_FILES_$(package)) $(DEB_UNREMOVE_FILES_$(package))
80debian-displace/%: displace_files_all = $(strip $(displace_files) $(displace_hide_files) $(displace_undisplace_files) $(displace_unhide_files))
81debian-displace/%: displace_files_thispkg = $(strip $(displace_files) $(displace_hide_files))
82$(patsubst %,debian-displace/%,$(DEB_DISPLACE_PACKAGES)) :: debian-displace/%:
83#   Writing shell scripts in makefiles sucks.  Remember to $$ shell
84#   variables and include \ at the end of each line.
85# Add code to postinst to add/remove diversions and symlinks as appropriate
86        set -e; \
87        { \
88            sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DISPLACE_EXTENSION#/$(DEB_DISPLACE_EXTENSION)/g' $(DEB_DISPLACE_SCRIPT); \
89            $(if $(displace_files_all), \
90                echo 'if [ "$$1" = "configure" ]; then'; \
91                $(foreach file,$(displace_undisplace_files), \
92                    echo "    check_undisplace_unlink $(call displace_files_replace_name,$(file), )"; )\
93                $(foreach file,$(displace_unhide_files), \
94                    echo "    check_undisplace_unhide $(file) $(call hide_files_name,$(file))"; )\
95                $(foreach file,$(displace_files), \
96                    echo "    displace_link $(call displace_files_replace_name,$(file), )";) \
97                $(foreach file,$(displace_hide_files), \
98                    mkdir -p debian/$(cdbs_curpkg)/usr/share/$(cdbs_curpkg); \
99                    echo "    displace_hide $(file) $(call hide_files_name,$(file))";) \
100                echo 'fi'; \
101            ) \
102        } >> $(CURDIR)/debian/$(cdbs_curpkg).postinst.debhelper
103# Add code to prerm script to undo diversions and symlinks when package is removed.
104        set -e; \
105        { \
106            $(if $(dh_compat_6),, \
107                if [ -e $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper ]; then \
108                    cat $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper; \
109                fi;) \
110            sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DISPLACE_EXTENSION#/$(DEB_DISPLACE_EXTENSION)/g' $(DEB_DISPLACE_SCRIPT); \
111            $(if $(displace_files_thispkg), \
112                echo 'if [ "$$1" = "remove" ] || [ "$$1" = "deconfigure" ]; then'; \
113                $(foreach file,$(call reverse_dh_compat_6,$(displace_files)), \
114                    echo "    undisplace_unlink $(call displace_files_replace_name,$(file), )";) \
115                $(foreach file,$(call reverse_dh_compat_6,$(displace_hide_files)), \
116                    echo "    undisplace_unhide $(file) $(cdbs_curpkg)";) \
117                echo 'fi'; \
118            ) \
119            $(if $(dh_compat_6), \
120                if [ -e $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper ]; then \
121                    cat $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper; \
122                fi;) \
123        } >> $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper.new
124        mv $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper.new \
125            $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper
126# Add an encoding of the names of the diverted files to the Provides:
127# and Conflicts: lists.  This prevents two packages diverting the same
128# file from being installed simultaneously (it cannot work, and this
129# produces a much less ugly error).  Requires in debian/control:
130#   Provides: ${diverted-files}
131#   Conflicts: ${diverted-files}
132        set -e; \
133        { \
134            echo -n "diverted-files="; \
135            $(foreach file,$(displace_files_thispkg),\
136                echo -n "diverts-"; \
137                ${DEB_DISPLACE_ENCODER} "$(call displace_files_replace_name,$(file))"; \
138                echo -n ", ";) \
139            echo; \
140        } >> $(CURDIR)/debian/$(cdbs_curpkg).substvars
141
142$(patsubst %,binary-post-install/%,$(DEB_DISPLACE_PACKAGES)) :: binary-post-install/%: debian-displace/%
143
144endif
Note: See TracBrowser for help on using the repository browser.