History

kbuild: add script and target to generate pacman package

pacman is the package manager used by Arch Linux and its derivates. Creating native packages from the kernel tree has multiple advantages: * The package triggers the correct hooks for initramfs generation and bootloader configuration * Uninstallation is complete and also invokes the relevant hooks * New UAPI headers can be installed without any manual bookkeeping The PKGBUILD file is a modified version of the one used for the downstream Arch Linux "linux" package. Extra steps that should not be necessary for a development kernel have been removed and an UAPI header package has been added.

Thomas Weißschuh committed 2 years ago

Commit c8578531 parent 3554a455 files · +136 −1Browse files

Unified · Split

5 files
  1. .gitignore +6 −0
  2. MAINTAINERS +7 −0
  3. Makefile +1 −1
  4. scripts/Makefile.package +14 −0
  5. scripts/package/PKGBUILD +108 −0
.gitignore+6−0
@@ -92,6 +92,12 @@ modules.order · 91 unmodified lines
92#92#
93/tar-install/93/tar-install/
94 94
95#
96# pacman files (make pacman-pkg)
97#
98/PKGBUILD
99/pacman/
100
95#101#
96# We don't want to ignore the following even if they are dot-files102# We don't want to ignore the following even if they are dot-files
97#103#
MAINTAINERS+7−0
@@ -11998,6 +11998,13 @@ F: include/uapi/linux/nfsd/ · 11997 unmodified lines
11998F: include/uapi/linux/sunrpc/11998F: include/uapi/linux/sunrpc/
11999F: net/sunrpc/11999F: net/sunrpc/
12000 12000
12001KERNEL PACMAN PACKAGING (in addition to generic KERNEL BUILD)
12002M: Thomas Weißschuh <linux@weissschuh.net>
12003R: Christian Heusel <christian@heusel.eu>
12004R: Nathan Chancellor <nathan@kernel.org>
12005S: Maintained
12006F: scripts/package/PKGBUILD
12007
12001KERNEL REGRESSIONS12008KERNEL REGRESSIONS
12002M: Thorsten Leemhuis <linux@leemhuis.info>12009M: Thorsten Leemhuis <linux@leemhuis.info>
12003L: regressions@lists.linux.dev12010L: regressions@lists.linux.dev
Makefile+1−1
@@ -1489,7 +1489,7 @@ CLEAN_FILES += vmlinux.symvers modules-only.symvers \ · 1488 unmodified lines
1489# Directories & files removed with 'make mrproper'1489# Directories & files removed with 'make mrproper'
1490MRPROPER_FILES += include/config include/generated \1490MRPROPER_FILES += include/config include/generated \
1491 arch/$(SRCARCH)/include/generated .objdiff \1491 arch/$(SRCARCH)/include/generated .objdiff \
1492 debian snap tar-install \1492 debian snap tar-install PKGBUILD pacman \
1493 .config .config.old .version \1493 .config .config.old .version \
1494 Module.symvers \1494 Module.symvers \
1495 certs/signing_key.pem \1495 certs/signing_key.pem \
scripts/Makefile.package+14−0
@@ -141,6 +141,19 @@ snap-pkg: · 140 unmodified lines
141 cd $(objtree)/snap && \141 cd $(objtree)/snap && \
142 snapcraft --target-arch=$(UTS_MACHINE)142 snapcraft --target-arch=$(UTS_MACHINE)
143 143
144# pacman-pkg
145# ---------------------------------------------------------------------------
146
147PHONY += pacman-pkg
148pacman-pkg:
149 @ln -srf $(srctree)/scripts/package/PKGBUILD $(objtree)/PKGBUILD
150 +objtree="$(realpath $(objtree))" \
151 BUILDDIR="$(realpath $(objtree))/pacman" \
152 CARCH="$(UTS_MACHINE)" \
153 KBUILD_MAKEFLAGS="$(MAKEFLAGS)" \
154 KBUILD_REVISION="$(shell $(srctree)/scripts/build-version)" \
155 makepkg $(MAKEPKGOPTS)
156
144# dir-pkg tar*-pkg - tarball targets157# dir-pkg tar*-pkg - tarball targets
145# ---------------------------------------------------------------------------158# ---------------------------------------------------------------------------
146 159
@@ -221,6 +234,7 @@ help: · 74 unmodified lines
221 @echo ' bindeb-pkg - Build only the binary kernel deb package'234 @echo ' bindeb-pkg - Build only the binary kernel deb package'
222 @echo ' snap-pkg - Build only the binary kernel snap package'235 @echo ' snap-pkg - Build only the binary kernel snap package'
223 @echo ' (will connect to external hosts)'236 @echo ' (will connect to external hosts)'
237 @echo ' pacman-pkg - Build only the binary kernel pacman package'
224 @echo ' dir-pkg - Build the kernel as a plain directory structure'238 @echo ' dir-pkg - Build the kernel as a plain directory structure'
225 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'239 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
226 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'240 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
scripts/package/PKGBUILD+108−0
@@ -0,0 +1,108 @@
1# SPDX-License-Identifier: GPL-2.0-only
2# Maintainer: Thomas Weißschuh <linux@weissschuh.net>
3# Contributor: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
4
5pkgbase=${PACMAN_PKGBASE:-linux-upstream}
6pkgname=("${pkgbase}" "${pkgbase}-api-headers")
7if grep -q CONFIG_MODULES=y include/config/auto.conf; then
8 pkgname+=("${pkgbase}-headers")
9fi
10pkgver="${KERNELRELEASE//-/_}"
11# The PKGBUILD is evaluated multiple times.
12# Running scripts/build-version from here would introduce inconsistencies.
13pkgrel="${KBUILD_REVISION}"
14pkgdesc='Upstream Linux'
15url='https://www.kernel.org/'
16# Enable flexible cross-compilation
17arch=(${CARCH})
18license=(GPL-2.0-only)
19makedepends=(
20 bc
21 bison
22 cpio
23 flex
24 gettext
25 kmod
26 libelf
27 openssl
28 pahole
29 perl
30 python
31 rsync
32 tar
33)
34options=(!debug !strip !buildflags !makeflags)
35
36build() {
37 # MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
38 # Bypass this override with a custom variable.
39 export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
40 cd "${objtree}"
41
42 ${MAKE} KERNELRELEASE="${KERNELRELEASE}" KBUILD_BUILD_VERSION="${pkgrel}"
43}
44
45_package() {
46 pkgdesc="The ${pkgdesc} kernel and modules"
47
48 export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
49 cd "${objtree}"
50 local modulesdir="${pkgdir}/usr/${MODLIB}"
51
52 echo "Installing boot image..."
53 # systemd expects to find the kernel here to allow hibernation
54 # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
55 install -Dm644 "$(${MAKE} -s image_name)" "${modulesdir}/vmlinuz"
56
57 # Used by mkinitcpio to name the kernel
58 echo "${pkgbase}" > "${modulesdir}/pkgbase"
59
60 echo "Installing modules..."
61 ${MAKE} INSTALL_MOD_PATH="${pkgdir}/usr" INSTALL_MOD_STRIP=1 \
62 DEPMOD=true modules_install
63
64 if [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
65 echo "Installing dtbs..."
66 ${MAKE} INSTALL_DTBS_PATH="${modulesdir}/dtb" dtbs_install
67 fi
68
69 # remove build link, will be part of -headers package
70 rm -f "${modulesdir}/build"
71}
72
73_package-headers() {
74 pkgdesc="Headers and scripts for building modules for the ${pkgdesc} kernel"
75
76 export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
77 cd "${objtree}"
78 local builddir="${pkgdir}/usr/${MODLIB}/build"
79
80 echo "Installing build files..."
81 "${srctree}/scripts/package/install-extmod-build" "${builddir}"
82
83 echo "Installing System.map and config..."
84 cp System.map "${builddir}/System.map"
85 cp .config "${builddir}/.config"
86
87 echo "Adding symlink..."
88 mkdir -p "${pkgdir}/usr/src"
89 ln -sr "${builddir}" "${pkgdir}/usr/src/${pkgbase}"
90}
91
92_package-api-headers() {
93 pkgdesc="Kernel headers sanitized for use in userspace"
94 provides=(linux-api-headers)
95 conflicts=(linux-api-headers)
96
97 export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
98 cd "${objtree}"
99
100 ${MAKE} headers_install INSTALL_HDR_PATH="${pkgdir}/usr"
101}
102
103for _p in "${pkgname[@]}"; do
104 eval "package_$_p() {
105 $(declare -f "_package${_p#$pkgbase}")
106 _package${_p#$pkgbase}
107 }"
108done

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t