forked from sipb/config-package-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-files.mk
88 lines (76 loc) · 3.78 KB
/
check-files.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2007-2008 Anders Kaseorg <[email protected]> and
# Tim Abbott <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
# Don't include check-files.mk in your rules files directly; instead
# use config-package.mk.
# check-files.mk is used to verify that files on local disk have not
# been modified from the upstream packaged version. Its only API
# function is adding the following function as a dependency:
#
# $(call debian_check_files,filename)
#
# Returns the path to a copy of filename that is verified to be
# unmodified from the version shipped by the distribution (by checking
# md5sums). The function causes the package to fail to build if the
# relevant configuration file has been modified on the build machine.
ifndef _cdbs_rules_check_files
_cdbs_rules_check_files = 1
include /usr/share/cdbs/1/rules/displace.mk
DEB_CHECK_FILES_TMPDIR = debian/check_file_copies
debian_check_files_source = $(if $(DEB_CHECK_FILES_SOURCE_$(1)),$(DEB_CHECK_FILES_SOURCE_$(1)),$(call displace_files_replace_name,$(1)))
debian_check_files = $(patsubst %,$(DEB_CHECK_FILES_TMPDIR)%,$(1))
undebian_check_files = $(patsubst $(DEB_CHECK_FILES_TMPDIR)%,%,$(1))
debian_check_files_tmp = $(patsubst %,%.tmp,$(call debian_check_files,$(1)))
undebian_check_files_tmp = $(call undebian_check_files,$(patsubst %.tmp,%,$(1)))
# We need a level of indirection here in order to make sure that
# normal makefile targets, like "clean", are not affected by the
# debian_check_files rules.
$(call debian_check_files,%): $(call debian_check_files_tmp,%)
mv $< $@
# We check md5sums from both /var/lib/dpkg/info/$(package).md5sums
# (the md5sums database for non-conffiles) and the conffiles database
# used for prompting about conffiles being changed (via dpkg-query).
#
# There is some wrangling here because the formats of these sources differ.
$(call debian_check_files_tmp,%): target = $(call undebian_check_files_tmp,$@)
$(call debian_check_files_tmp,%): name = $(call debian_check_files_source,$(target))
$(call debian_check_files_tmp,%): truename = $(if $(filter /%,$(name)),$(shell dpkg-divert --truename $(name)),$(name))
$(call debian_check_files_tmp,%): package = $(if $(filter /%,$(name)),$(shell LC_ALL=C dpkg -S $(name) | sed -n '/^diversion by /! s/: .*$$// p'),x)
$(call debian_check_files_tmp,%): $(truename)
[ -n "$(package)" ]
mkdir -p $(@D)
cp "$(truename)" $@
set -e; \
case "$(name)" in /*) ;; *) exit 0;; esac; \
md5sums="$$(dpkg-query --control-path $(package) md5sums 2>/dev/null)" || \
md5sums=/var/lib/dpkg/info/$(package).md5sums; \
md5=$$(dpkg-query --showformat='$${Conffiles}\n' --show $(package) | \
sed -n 's,^ $(name) \([0-9a-f]*\)$$,\1 $@, p'); \
if [ -n "$$md5" ]; then \
echo "$$md5" | md5sum -c; \
elif [ -e "$$md5sums" ]; then \
md5=$$(sed -n 's,^\([0-9a-f]*\) $(patsubst /%,%,$(name))$$,\1 $@, p' \
"$$md5sums"); \
[ -n "$$md5" ] && echo "$$md5" | md5sum -c; \
else \
echo "config-package-dev: warning: $(package) does not include md5sums!"; \
echo "config-package-dev: warning: md5sum for $(name) not verified."; \
fi
clean::
rm -rf $(DEB_CHECK_FILES_TMPDIR)
endif