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