xref: /linux/scripts/package/debian/rules (revision caf400c8b68af29568e39ef99b12d25966c3e76b)
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
28.PHONY: binary binary-indep binary-arch
29binary: binary-arch binary-indep
30binary-indep: build-indep
31binary-arch: build-arch
32	$(Q)$(MAKE) $(make-opts) \
33	run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb'
34
35.PHONY: build build-indep build-arch
36build: build-arch build-indep
37build-indep:
38build-arch:
39	$(Q)$(MAKE) $(make-opts) olddefconfig
40	$(Q)$(MAKE) $(make-opts) $(if $(filter um,$(ARCH)),,headers) all
41
42.PHONY: clean
43clean:
44	$(Q)rm -rf debian/files debian/linux-* debian/deb-env.vars*
45	$(Q)$(MAKE) ARCH=$(ARCH) clean
46
47# If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
48# directly. Run 'dpkg-architecture --print-set --print-format=make' to
49# generate a makefile construct that exports all DEB_* variables.
50ifndef DEB_HOST_ARCH
51include debian/deb-env.vars
52
53debian/deb-env.vars:
54	$(Q)dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@.tmp
55	$(Q)mv $@.tmp $@
56endif
57