Debian Codegraph @

scripts/package/debian/rules

raw
1 #!/usr/bin/make -f
2 # SPDX-License-Identifier: GPL-2.0-only
3
4 # in case debian/rules is executed directly
5 export DEB_RULES_REQUIRES_ROOT := no
6
7 include debian/rules.vars
8
9 ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
10 NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
11 MAKEFLAGS += -j$(NUMJOBS)
12 endif
13
14 # When KBUILD_VERBOSE is undefined (presumably you are directly working with
15 # the debianized tree), show verbose logs unless DEB_BUILD_OPTION=terse is set.
16 ifeq ($(origin KBUILD_VERBOSE),undefined)
17 ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
18 export KBUILD_VERBOSE := 1
19 else
20 Q := @
21 endif
22 endif
23
24 revision = $(shell dpkg-parsechangelog -S Version | sed -n 's/.*-//p')
25 CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
26 make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) \
27 $(addprefix KBUILD_BUILD_VERSION=,$(revision)) \
28 $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
29
30 binary-targets := $(addprefix binary-, image image-dbg headers libc-dev)
31
32 all-packages = $(shell dh_listpackages)
33 image-package = $(filter linux-image-% user-%, $(filter-out %-dbg, $(all-packages)))
34 image-dbg-package = $(filter %-dbg, $(all-packages))
35 libc-dev-package = $(filter linux-libc-dev, $(all-packages))
36 headers-package = $(filter linux-headers-%, $(all-packages))
37
38 mk-files = $(patsubst binary-%,debian/%.files,$1)
39 package = $($(@:binary-%=%-package))
40
41 # DH_OPTION is an environment variable common for all debhelper commands.
42 # We could 'export' it, but here it is passed from the command line to clarify
43 # which package is being processed in the build log.
44 DH_OPTIONS = -p$(package)
45
46 # Note: future removal of KDEB_COMPRESS
47 # dpkg-deb >= 1.21.10 supports the DPKG_DEB_COMPRESSOR_TYPE environment
48 # variable, which provides the same functionality as KDEB_COMPRESS. The
49 # KDEB_COMPRESS variable will be removed in the future.
50 define binary
51 $(Q)dh_testdir $(DH_OPTIONS)
52 $(Q)dh_testroot $(DH_OPTIONS)
53 $(Q)dh_prep $(DH_OPTIONS)
54 $(Q)+$(MAKE) $(make-opts) run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb $(package)'
55 $(Q)dh_installdocs $(DH_OPTIONS)
56 $(Q)dh_installchangelogs $(DH_OPTIONS)
57 $(Q)dh_compress $(DH_OPTIONS)
58 $(Q)dh_fixperms $(DH_OPTIONS)
59 $(Q)dh_gencontrol $(DH_OPTIONS) -- -f$(call mk-files,$@)
60 $(Q)dh_md5sums $(DH_OPTIONS)
61 $(Q)dh_builddeb $(DH_OPTIONS) -- $(addprefix -Z,$(KDEB_COMPRESS))
62 endef
63
64 .PHONY: $(binary-targets)
65 $(binary-targets): build-arch
66 $(Q)truncate -s0 $(call mk-files,$@)
67 $(if $(package),$(binary))
68
69 .PHONY: binary binary-indep binary-arch
70 binary: binary-arch binary-indep
71 binary-indep: build-indep
72 binary-arch: $(binary-targets)
73 $(Q)cat $(call mk-files,$^) > debian/files
74
75 .PHONY: build build-indep build-arch
76 build: build-arch build-indep
77 build-indep:
78 build-arch:
79 $(Q)$(MAKE) $(make-opts) olddefconfig
80 $(Q)$(MAKE) $(make-opts) $(if $(filter um,$(ARCH)),,headers) all
81
82 .PHONY: clean
83 clean:
84 $(Q)dh_clean
85 $(Q)rm -rf debian/deb-env.vars* debian/*.files
86 $(Q)$(MAKE) ARCH=$(ARCH) clean
87
88 # If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
89 # directly. Run 'dpkg-architecture --print-set --print-format=make' to
90 # generate a makefile construct that exports all DEB_* variables.
91 ifndef DEB_HOST_ARCH
92 include debian/deb-env.vars
93
94 debian/deb-env.vars:
95 $(Q)dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > [email protected]
96 $(Q)mv [email protected] $@
97 endif