summaryrefslogtreecommitdiff
path: root/scripts/package-build/linux-kernel/patches/kernel/0003-build-linux-perf-package.patch
blob: 32254849bc3fb71236c1a5bb94711ada66da863c (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
From: Christian Breunig <christian@breunig.cc>
Subject: [PATCH] VyOS: build a linux-perf Debian package alongside the kernel

The upstream "make bindeb-pkg" target stopped emitting a perf package
quite a while ago. Re-add it by hooking into the new builddeb / mkdebian
infrastructure:

  * mkdebian: emit a "linux-perf-${KERNELRELEASE}" stanza in
    debian/control whenever the architecture is not user-mode-linux.
  * scripts/package/debian/rules: add a "binary-perf" target so the
    binary build loop processes the new package.
  * builddeb: add an install_perf() helper that invokes
    "make -C tools/perf install" with prefix=/usr and DESTDIR pointing
    at the package staging directory, plus a dispatch case for
    "linux-perf-*" packages.

Refreshed for Linux 6.18.x: the old patch targeted the previous loop
based scripts/package/builddeb (one-shot builddeb invocation that
iterated over every package); since v6.7 the package build is driven
per-package from debian/rules, so we have to extend that mechanism
instead.
---
 scripts/package/builddeb      | 16 ++++++++++++++++
 scripts/package/debian/rules  |  3 ++-
 scripts/package/mkdebian      | 12 ++++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/scripts/package/builddeb b/scripts/package/builddeb
--- a/scripts/package/builddeb
+++ b/scripts/package/builddeb
@@ -156,6 +156,20 @@ install_libc_headers () {
 	mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
 }
 
+install_perf () {
+	pdir=debian/$1
+
+	rm -rf "$pdir"
+	mkdir -p "$pdir"
+
+	# In-source kernel builds export srctree as a relative path (".").
+	# "make -C tools/perf" changes the working directory, which breaks
+	# Makefile.perf's "include $(srctree)/tools/build/Makefile.include"
+	# unless srctree is absolute. Force an absolute path here.
+	$MAKE -C "$srctree/tools/perf" srctree="$(realpath "$srctree")" \
+		prefix=/usr DESTDIR="$(pwd)/$pdir" install
+}
+
 package=$1
 
 case "${package}" in
@@ -167,4 +181,6 @@ linux-libc-dev)
 	install_libc_headers "${package}";;
 linux-headers-*)
 	install_kernel_headers "${package}";;
+linux-perf-*)
+	install_perf "${package}";;
 esac
diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules
--- a/scripts/package/debian/rules
+++ b/scripts/package/debian/rules
@@ -27,13 +27,14 @@ make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) \
     $(addprefix KBUILD_BUILD_VERSION=,$(revision)) \
     $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
 
-binary-targets := $(addprefix binary-, image image-dbg headers libc-dev)
+binary-targets := $(addprefix binary-, image image-dbg headers libc-dev perf)
 
 all-packages = $(shell dh_listpackages)
 image-package = $(filter linux-image-% user-%, $(filter-out %-dbg, $(all-packages)))
 image-dbg-package = $(filter %-dbg, $(all-packages))
 libc-dev-package = $(filter linux-libc-dev, $(all-packages))
 headers-package = $(filter linux-headers-%, $(all-packages))
+perf-package = $(filter linux-perf-%, $(all-packages))
 
 mk-files = $(patsubst binary-%,debian/%.files,$1)
 package = $($(@:binary-%=%-package))
diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian
--- a/scripts/package/mkdebian
+++ b/scripts/package/mkdebian
@@ -247,6 +247,18 @@ Description: Linux kernel headers for ${KERNELRELEASE} on $debarch
  This is useful for people who need to build external modules
 EOF
 fi
+
+cat <<EOF >> debian/control
+
+Package: linux-perf-${KERNELRELEASE}
+Section: devel
+Architecture: $debarch
+Depends: libpfm4, libslang2, libtraceevent1
+Description: Performance analysis tools for Linux ${KERNELRELEASE}
+ This package contains the 'perf' performance analysis tools for Linux
+ kernel version ${KERNELRELEASE}.
+Multi-Arch: same
+EOF
 fi
 
 if is_enabled CONFIG_DEBUG_INFO; then
-- 
2.39.5