]> andersk Git - config-package-dev.git/blame - divert.mk
divert.mk: Finish writing a sentence in the comments.
[config-package-dev.git] / divert.mk
CommitLineData
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
02209392
GT
24# divert.sh.in in the postinst and prerm scripts, and adds calls to the
25# functions in divert.sh.in to add and remove diversions and symlinks at
26# the appropriate points.
56709134 27
ab8e2a67
TA
28ifndef _cdbs_rules_divert
29_cdbs_rules_divert = 1
30
be43c288
TA
31include /usr/share/cdbs/1/rules/debhelper.mk
32
02bde96f 33CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), config-package-dev (>= 4.5~)
ab8e2a67 34
56709134
TA
35# divert.sh.in is included in the postinst/prerm scripts of packages
36# installing diversions using config-package-dev.
ab8e2a67 37DEB_DIVERT_SCRIPT = /usr/share/config-package-dev/divert.sh.in
56709134
TA
38# script used to encode the path of a file uniquely in a valid virtual
39# package name.
40DEB_DIVERT_ENCODER = /usr/share/config-package-dev/encode
ab8e2a67
TA
41
42DEB_DIVERT_PACKAGES += $(foreach package,$(DEB_ALL_PACKAGES), \
02bde96f 43 $(if $(DEB_TRANSFORM_FILES_$(package)),$(package), \
936cb21e
TA
44 $(if $(DEB_REMOVE_FILES_$(package)),$(package), \
45 $(if $(DEB_UNREMOVE_FILES_$(package)),$(package), \
46 $(if $(DEB_UNDIVERT_FILES_$(package)),$(package), \
47 $(if $(DEB_DIVERT_FILES_$(package)),$(package)))))))
ab8e2a67
TA
48
49ifeq ($(DEB_DIVERT_EXTENSION),)
50DEB_DIVERT_EXTENSION = .divert
51endif
52
56709134
TA
53# Replace only the last instance of DEB_DIVERT_EXTENSION in the
54# filename, to make it possible to divert /path/foo.divert to
55# foo.divert.divert-orig
936cb21e
TA
56divert_files_replace_name = $(shell echo $(1) | perl -pe 's/(.*)\Q$(DEB_DIVERT_EXTENSION)\E/$$1$(2)/')
57
c94f42bb 58# Encode a full path into the path it should be diverted to if it's
50bf7563
AK
59# removed
60remove_files_name = /usr/share/$(cdbs_curpkg)/$(shell $(DEB_DIVERT_ENCODER) $(1))
61
9350e976 62dh_compat_6 := $(shell if [ '$(DH_COMPAT)' -ge 6 ]; then echo y; fi)
a06c63da
AK
63
64reverse = $(foreach n,$(shell seq $(words $(1)) -1 1),$(word $(n),$(1)))
9350e976 65reverse_dh_compat_6 = $(if $(dh_compat_6),$(call reverse,$(1)),$(1))
a06c63da 66
ab8e2a67 67debian-divert/%: package = $(subst debian-divert/,,$@)
02bde96f 68debian-divert/%: divert_files = $(DEB_DIVERT_FILES_$(package)) $(DEB_TRANSFORM_FILES_$(package))
936cb21e
TA
69debian-divert/%: divert_remove_files = $(DEB_REMOVE_FILES_$(package))
70debian-divert/%: divert_undivert_files = $(DEB_UNDIVERT_FILES_$(package))
71debian-divert/%: divert_unremove_files = $(DEB_UNREMOVE_FILES_$(package))
72debian-divert/%: divert_files_all = $(strip $(divert_files) $(divert_remove_files) $(divert_undivert_files) $(divert_unremove_files))
73debian-divert/%: divert_files_thispkg = $(strip $(divert_files) $(divert_remove_files))
ab8e2a67 74$(patsubst %,debian-divert/%,$(DEB_DIVERT_PACKAGES)) :: debian-divert/%:
56709134
TA
75# Writing shell scripts in makefiles sucks. Remember to $$ shell
76# variables and include \ at the end of each line.
77# Add code to postinst to add/remove diversions as appropriate
3aab360a
AK
78 set -e; \
79 { \
ab8e2a67 80 sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \
936cb21e 81 $(if $(divert_files_all), \
ab8e2a67 82 echo 'if [ "$$1" = "configure" ]; then'; \
936cb21e 83 $(foreach file,$(divert_undivert_files), \
50bf7563 84 echo " check_undivert_unlink $(call divert_files_replace_name,$(file), )"; )\
936cb21e 85 $(foreach file,$(divert_unremove_files), \
50bf7563 86 echo " check_undivert_unremove $(file) $(call remove_files_name,$(file))"; )\
ab8e2a67 87 $(foreach file,$(divert_files), \
936cb21e
TA
88 echo " divert_link $(call divert_files_replace_name,$(file), )";) \
89 $(foreach file,$(divert_remove_files), \
a7a01014 90 mkdir -p debian/$(cdbs_curpkg)/usr/share/$(cdbs_curpkg); \
50bf7563 91 echo " divert_remove $(file) $(call remove_files_name,$(file))";) \
ab8e2a67
TA
92 echo 'fi'; \
93 ) \
3aab360a 94 } >> $(CURDIR)/debian/$(cdbs_curpkg).postinst.debhelper
56709134 95# Add code to prerm script to undo diversions when package is removed.
3aab360a
AK
96 set -e; \
97 { \
9350e976 98 $(if $(dh_compat_6),, \
a06c63da
AK
99 if [ -e $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper ]; then \
100 cat $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper; \
101 fi;) \
ab8e2a67 102 sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \
936cb21e 103 $(if $(divert_files_thispkg), \
96d37386 104 echo 'if [ "$$1" = "remove" ] || [ "$$1" = "deconfigure" ]; then'; \
9350e976 105 $(foreach file,$(call reverse_dh_compat_6,$(divert_files)), \
936cb21e 106 echo " undivert_unlink $(call divert_files_replace_name,$(file), )";) \
9350e976 107 $(foreach file,$(call reverse_dh_compat_6,$(divert_remove_files)), \
936cb21e 108 echo " undivert_unremove $(file) $(cdbs_curpkg)";) \
ab8e2a67
TA
109 echo 'fi'; \
110 ) \
9350e976 111 $(if $(dh_compat_6), \
a06c63da
AK
112 if [ -e $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper ]; then \
113 cat $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper; \
114 fi;) \
115 } >> $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper.new
116 mv $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper.new \
117 $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper
56709134
TA
118# Add an encoding of the names of the diverted files to the Provides:
119# and Conflicts: lists. This prevents two packages diverting the same
120# file from being installed simultaneously (it cannot work, and this
121# produces a much less ugly error). Requires in debian/control:
c94f42bb
GT
122# Provides: ${diverted-files}
123# Conflicts: ${diverted-files}
3aab360a
AK
124 set -e; \
125 { \
ab8e2a67 126 echo -n "diverted-files="; \
936cb21e 127 $(foreach file,$(divert_files_thispkg),\
56709134 128 echo -n "diverts-"; \
936cb21e 129 ${DEB_DIVERT_ENCODER} "$(call divert_files_replace_name,$(file))"; \
ab8e2a67 130 echo -n ", ";) \
3aab360a
AK
131 echo; \
132 } >> $(CURDIR)/debian/$(cdbs_curpkg).substvars
ab8e2a67 133
be43c288 134$(patsubst %,binary-post-install/%,$(DEB_DIVERT_PACKAGES)) :: binary-post-install/%: debian-divert/%
ab8e2a67
TA
135
136endif
This page took 0.162612 seconds and 5 git commands to generate.