1 # -*- mode: makefile; coding: utf-8 -*-
2 # Copyright © 2007-2008 Anders Kaseorg <andersk@mit.edu> and
3 # Tim Abbott <tabbott@mit.edu>
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.
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.
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
20 ifndef _cdbs_rules_divert
21 _cdbs_rules_divert = 1
23 CDBS_BUILD_DEPENDS := $(CDBS_BUILD_DEPENDS), config-package-dev
25 DEB_DIVERT_SCRIPT = /usr/share/config-package-dev/divert.sh.in
27 DEB_DIVERT_PACKAGES += $(foreach package,$(DEB_ALL_PACKAGES), \
28 $(if $(DEB_DIVERT_FILES_$(package)),$(package)))
30 DEB_DIVERT_PACKAGES += $(foreach package,$(DEB_ALL_PACKAGES), \
31 $(if $(DEB_REPLACE_FILES_$(package)),$(package)))
33 ifeq ($(DEB_DIVERT_EXTENSION),)
34 DEB_DIVERT_EXTENSION = .divert
37 DEB_DIVERT_ENCODER = /usr/share/config-package-dev/encode
39 debian-divert/%: package = $(subst debian-divert/,,$@)
40 debian-divert/%: replace_inputs = $(DEB_REPLACE_FILES_$(package))
41 debian-divert/%: replace_files = $(foreach file,$(replace_inputs),$(file))
42 debian-divert/%: divert_files = $(DEB_DIVERT_FILES_$(package)) $(replace_files)
43 $(patsubst %,debian-divert/%,$(DEB_DIVERT_PACKAGES)) :: debian-divert/%:
45 sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \
46 $(if $(divert_files), \
47 echo 'if [ "$$1" = "configure" ]; then'; \
48 $(foreach file,$(divert_files), \
49 echo " divert_link $(subst $(DEB_DIVERT_EXTENSION), ,$(file))";) \
52 ) >> $(CURDIR)/debian/$(cdbs_curpkg).postinst.debhelper
54 sed 's/#PACKAGE#/$(cdbs_curpkg)/g; s/#DEB_DIVERT_EXTENSION#/$(DEB_DIVERT_EXTENSION)/g' $(DEB_DIVERT_SCRIPT); \
55 $(if $(divert_files), \
56 echo 'if [ "$$1" = "remove" ]; then'; \
57 $(foreach file,$(divert_files), \
58 echo " undivert_unlink $(subst $(DEB_DIVERT_EXTENSION), ,$(file))";) \
61 ) >> $(CURDIR)/debian/$(cdbs_curpkg).prerm.debhelper
63 echo -n "diverted-files="; \
64 $(foreach file,$(divert_files),\
65 ${DEB_DIVERT_ENCODER} "$(subst $(DEB_DIVERT_EXTENSION),,$(file))"; \
68 ) >> $(CURDIR)/debian/$(cdbs_curpkg).substvars
70 $(patsubst %,binary-fixup/%,$(DEB_DIVERT_PACKAGES)) :: binary-fixup/%: debian-divert/%