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 check-files.mk in your rules files directly; instead |
---|
21 | # use config-package.mk. |
---|
22 | |
---|
23 | # check-files.mk is used to verify that files on local disk have not |
---|
24 | # been modified from the upstream packaged version. Its only API |
---|
25 | # function is adding the following function as a dependency: |
---|
26 | # |
---|
27 | # $(call debian_check_files,filename) |
---|
28 | # |
---|
29 | # Returns the path to a copy of filename that is verified to be |
---|
30 | # unmodified from the version shipped by the distribution (by checking |
---|
31 | # md5sums). The function causes the package to fail to build if the |
---|
32 | # relevant configuration file has been modified on the build machine. |
---|
33 | |
---|
34 | ifndef _cdbs_rules_check_files |
---|
35 | _cdbs_rules_check_files = 1 |
---|
36 | |
---|
37 | include /usr/share/cdbs/1/rules/divert.mk |
---|
38 | |
---|
39 | DEB_CHECK_FILES_TMPDIR = debian/check_file_copies |
---|
40 | |
---|
41 | debian_check_files_source = $(if $(DEB_CHECK_FILES_SOURCE_$(1)),$(DEB_CHECK_FILES_SOURCE_$(1)),$(1)) |
---|
42 | debian_check_files_check = $(call divert_files_replace_name,$(call debian_check_files_source,$(1))) |
---|
43 | |
---|
44 | debian_check_files = $(patsubst %,$(DEB_CHECK_FILES_TMPDIR)%,$(1)) |
---|
45 | undebian_check_files = $(patsubst $(DEB_CHECK_FILES_TMPDIR)%,%,$(1)) |
---|
46 | |
---|
47 | debian_check_files_tmp = $(patsubst %,%.tmp,$(call debian_check_files,$(1))) |
---|
48 | undebian_check_files_tmp = $(call undebian_check_files,$(patsubst %.tmp,%,$(1))) |
---|
49 | |
---|
50 | # We need a level of indirection here in order to make sure that |
---|
51 | # normal makefile targets, like "clean", are not affected by the |
---|
52 | # debian_check_files rules. |
---|
53 | $(call debian_check_files,%): $(call debian_check_files_tmp,%) |
---|
54 | mv $< $@ |
---|
55 | |
---|
56 | # We check md5sums from both /var/lib/dpkg/info/$(package).md5sums |
---|
57 | # (the md5sums database for non-conffiles) and the conffiles database |
---|
58 | # used for prompting about conffiles being changed (via dpkg-query). |
---|
59 | # |
---|
60 | # There is some wrangling here because the formats of these sources differ. |
---|
61 | $(call debian_check_files_tmp,%): target = $(call undebian_check_files_tmp,$@) |
---|
62 | $(call debian_check_files_tmp,%): name = $(call debian_check_files_check,$(target)) |
---|
63 | $(call debian_check_files_tmp,%): truename = $(shell /usr/sbin/dpkg-divert --truename $(name)) |
---|
64 | $(call debian_check_files_tmp,%): package = $(shell dpkg -S $(name) | grep -v "^diversion by" | cut -f1 -d:) |
---|
65 | $(call debian_check_files_tmp,%): $(truename) |
---|
66 | [ -n $(package) ] |
---|
67 | mkdir -p $(@D) |
---|
68 | cp "$(truename)" $@ |
---|
69 | set -e; \ |
---|
70 | md5=$$(dpkg-query --showformat='$${Conffiles}\n' --show $(package) | \ |
---|
71 | sed -n 's,^ $(name) \([0-9a-f]*\)$$,\1 $@, p'); \ |
---|
72 | if [ -n "$$md5" ]; then \ |
---|
73 | echo "$$md5" | md5sum -c; \ |
---|
74 | elif [ -e /var/lib/dpkg/info/$(package).md5sums ]; then \ |
---|
75 | md5=$$(sed -n 's,^\([0-9a-f]*\) $(patsubst /%,%,$(name))$$,\1 $@, p' \ |
---|
76 | /var/lib/dpkg/info/$(package).md5sums); \ |
---|
77 | [ -n "$$md5" ] && echo "$$md5" | md5sum -c; \ |
---|
78 | else \ |
---|
79 | echo "config-package-dev: warning: $(package) does not include md5sums!"; \ |
---|
80 | echo "config-package-dev: warning: md5sum for $(name) not verified."; \ |
---|
81 | fi |
---|
82 | |
---|
83 | clean:: |
---|
84 | rm -rf $(DEB_CHECK_FILES_TMPDIR) |
---|
85 | |
---|
86 | endif |
---|