summaryrefslogtreecommitdiffstats
path: root/debian/backports/rules
blob: 3b8699754f0210d2ec0a4e3999cd44424572dfaa (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
.PHONY: backports $(KNOWN_BACKPORTS)

# error out if these files are missing
required_files = $(foreach backport,$(KNOWN_BACKPORTS), \
	$(addprefix debian/backports/$(backport)/, \
		debian/source/format \
		versionext \
		exclude))
$(if $(filter-out $(wildcard $(required_files)),$(required_files)), \
	$(error missing required backports files: \
		$(filter-out $(wildcard $(required_files)),$(required_files)). \
		see debian/backports/README) \
)

TARBALLDIR ?= $(shell dh_testdir debian/changelog && realpath ../)

define backports-targets
# if this file is empty, no automatic changelog entry is created
VERSIONEXT_$(1) ?= $(strip \
	$(shell cat $(wildcard debian/backports/$(1)/versionext)))
DEBIAN_VERSION_$(1) = $(DEBIAN_VERSION)$$(VERSIONEXT_$(1))
BACKPORTDIR_$(1) = $(realpath debian/backports/$(1))

# as of right now, must be '3.0 (quilt)'
SOURCEFORMAT_$(1) ?= $(strip \
	$(shell cat debian/backports/$(1)/debian/source/format))

# files checked for the dirhash (see below)
FINDCMD_$(1) = find debian/backports/$(1)/debian \
	-type f \
	! -path debian/backports/$(1)/debian/changelog

# files *not* pulled from the root debian directory into the backport tarball:
# debian/changelog (copied and edited for backport version entry)
# debian/backports itself (relevant contents are copied out separately)
# anything provided in the current backports debian dir
# anything specified in the 'exclude' file in the current backports debian dir
EXCLUDEROOT_$(1) = debian/changelog debian/backports \
	$$(subst debian/backports/$(1)/,,$$(shell $$(FINDCMD_$(1)))) \
	$$(shell cat debian/backports/$(1)/exclude)

EXCLUDEROOT_TAR_$(1) = $$(foreach file,$$(EXCLUDEROOT_$(1)),--exclude $$(file))
EXCLUDEROOT_FIND_$(1) = $$(foreach file,$$(EXCLUDEROOT_$(1)),-o -path $$(file))

# find command resulting in all files that *will* be pulled into the backport
# tarball.
FINDCMDROOT_$(1) = find debian/ \
	'(' -false $$(EXCLUDEROOT_FIND_$(1)) ')' -prune -o \
	-type f -a '!' '(' -false $$(EXCLUDEROOT_FIND_$(1)) ')'

# usually using `find' output for dependencies has the downfall of not tracking
# file removal. Work around that by introducing a dependency on a file whose
# name contains the hash of `find' output, so that the name will change when a
# file is deleted.
DIRHASH_$(1) = \
	$$(shell $$(FINDCMD_$(1)) | sha1sum | sed -r 's/^(......).*/\1/')
DIRHASHROOT_$(1) = \
	$$(shell $$(FINDCMDROOT_$(1)) | sha1sum | sed -r 's/^(......).*/\1/')

CONTROL_$(1) = $$(strip \
	$$(if $$(wildcard $$(BACKPORTDIR_$(1))/debian/control), \
		$$(BACKPORTDIR_$(1))/debian/control, \
		$(realpath debian/control) \
	))

# TARGETS:

$(1): $(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).dsc ;

# we use 3.0 (custom) to build a source package directly from tarballs,
# bypassing the usual checks (which wouldn't like our combination-of-
# directories approach)
$(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).dsc:
	# -b directory unused (but required) for '3.0 (custom)' source format
	dpkg-source -l$$(BACKPORTDIR_$(1))/debian/changelog \
		-c$$(CONTROL_$(1)) \
		--format='3.0 (custom)' \
		--target-format='$$(SOURCEFORMAT_$(1))' \
		--build . $$^

ifeq ($$(SOURCEFORMAT_$(1)),3.0 (quilt))
# this target depends on the orig.tar.gz file, for which there is no target in
# this makefile. It is assumed to either already exist or be built by a target
# provided elsewhere in debian/rules (e.g. via pristine-tar)
$(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).dsc: \
		$(TARBALLDIR)/$(SRCPKG)_$(ORIG_VERSION).orig.tar.gz \
		$(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).debian.tar.xz
else
$$(error unsupported source format for $(1) backport: $$(SOURCEFORMAT_$(1)))
endif #SOURCEFORMAT_$(1)

# for 3.0 (quilt)
$(TARBALLDIR)/$(SRCPKG)_$$(DEBIAN_VERSION_$(1)).debian.tar.xz: \
		$$(BACKPORTDIR_$(1))/debian/changelog \
		$$(shell $$(FINDCMD_$(1))) \
		$$(BACKPORTDIR_$(1))/$$(DIRHASH_$(1)).backport.dirhash \
		$$(shell $$(FINDCMDROOT_$(1))) \
		$$(BACKPORTDIR_$(1))/$$(DIRHASHROOT_$(1)).root.dirhash \
		$$(BACKPORTDIR_$(1))/exclude
	rm -f $$(subst .tar.xz,.tar,$$@) $$@
	tar -cf $$(subst .tar.xz,.tar,$$@) \
		--exclude-vcs $$(EXCLUDEROOT_TAR_$(1)) debian/
	cd debian/backports/$(1) && tar -uf $$(subst .tar.xz,.tar,$$@) \
		--exclude-vcs debian/
	xz $$(subst .tar.xz,.tar,$$@)

$$(BACKPORTDIR_$(1))/debian/changelog: \
		debian/changelog \
		debian/backports/$(1)/versionext
	rm -f debian/backports/$(1)/debian/changelog
	cp $$< $$@
	$(if $$(VERSIONEXT_$(1)), \
		dch -c $$@ -v '$$(DEBIAN_VERSION_$(1))' -b \
			'backport to $(1) systems', \
	)

$$(BACKPORTDIR_$(1))/$$(DIRHASH_$(1)).backport.dirhash:
	rm -f debian/backports/$(1)/*.backport.dirhash
	touch $$@

$$(BACKPORTDIR_$(1))/$$(DIRHASHROOT_$(1)).root.dirhash:
	rm -f debian/backports/$(1)/*.root.dirhash
	touch $$@

endef # backports-targets
$(foreach backport,$(KNOWN_BACKPORTS),$(eval \
	$(call backports-targets,$(backport))))

backports: $(KNOWN_BACKPORTS)