]> Git Repo - linux.git/commitdiff
kbuild: add script and target to generate pacman package
authorThomas Weißschuh <[email protected]>
Sat, 20 Jul 2024 09:18:12 +0000 (11:18 +0200)
committerMasahiro Yamada <[email protected]>
Sun, 21 Jul 2024 16:24:22 +0000 (01:24 +0900)
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.

Signed-off-by: Thomas Weißschuh <[email protected]>
Reviewed-by: Nathan Chancellor <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>
Signed-off-by: Masahiro Yamada <[email protected]>
.gitignore
MAINTAINERS
Makefile
scripts/Makefile.package
scripts/package/PKGBUILD [new file with mode: 0644]

index c59dc60ba62ef082cd027bb0a2f0d74cfebb7d71..7902adf4f7f1a55e40c21fb793ecb36c479fa947 100644 (file)
@@ -92,6 +92,12 @@ modules.order
 #
 /tar-install/
 
+#
+# pacman files (make pacman-pkg)
+#
+/PKGBUILD
+/pacman/
+
 #
 # We don't want to ignore the following even if they are dot-files
 #
index 0fe40cf1929fc8a23e40021c6a5ab69f25c08744..a48ae15e5bdb900dbdd83098b054bd05d3d60089 100644 (file)
@@ -11998,6 +11998,13 @@ F:     include/uapi/linux/nfsd/
 F:     include/uapi/linux/sunrpc/
 F:     net/sunrpc/
 
+KERNEL PACMAN PACKAGING (in addition to generic KERNEL BUILD)
+M:     Thomas Weißschuh <[email protected]>
+R:     Christian Heusel <[email protected]>
+R:     Nathan Chancellor <[email protected]>
+S:     Maintained
+F:     scripts/package/PKGBUILD
+
 KERNEL REGRESSIONS
 M:     Thorsten Leemhuis <[email protected]>
 L:     [email protected]
index cbad2bbe45618aa267cd5bb0cbc3fe4e64f1e31e..2750024208be6d2469e9d99ffa5d81f925539485 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1489,7 +1489,7 @@ CLEAN_FILES += vmlinux.symvers modules-only.symvers \
 # Directories & files removed with 'make mrproper'
 MRPROPER_FILES += include/config include/generated          \
                  arch/$(SRCARCH)/include/generated .objdiff \
-                 debian snap tar-install \
+                 debian snap tar-install PKGBUILD pacman \
                  .config .config.old .version \
                  Module.symvers \
                  certs/signing_key.pem \
index bf016af8bf8ada197f8d7594adb46380a27e900c..4a80584ec771216c4ea737b289ec653defb8f1f0 100644 (file)
@@ -141,6 +141,19 @@ snap-pkg:
        cd $(objtree)/snap && \
        snapcraft --target-arch=$(UTS_MACHINE)
 
+# pacman-pkg
+# ---------------------------------------------------------------------------
+
+PHONY += pacman-pkg
+pacman-pkg:
+       @ln -srf $(srctree)/scripts/package/PKGBUILD $(objtree)/PKGBUILD
+       +objtree="$(realpath $(objtree))" \
+               BUILDDIR="$(realpath $(objtree))/pacman" \
+               CARCH="$(UTS_MACHINE)" \
+               KBUILD_MAKEFLAGS="$(MAKEFLAGS)" \
+               KBUILD_REVISION="$(shell $(srctree)/scripts/build-version)" \
+               makepkg $(MAKEPKGOPTS)
+
 # dir-pkg tar*-pkg - tarball targets
 # ---------------------------------------------------------------------------
 
@@ -221,6 +234,7 @@ help:
        @echo '  bindeb-pkg          - Build only the binary kernel deb package'
        @echo '  snap-pkg            - Build only the binary kernel snap package'
        @echo '                        (will connect to external hosts)'
+       @echo '  pacman-pkg          - Build only the binary kernel pacman package'
        @echo '  dir-pkg             - Build the kernel as a plain directory structure'
        @echo '  tar-pkg             - Build the kernel as an uncompressed tarball'
        @echo '  targz-pkg           - Build the kernel as a gzip compressed tarball'
diff --git a/scripts/package/PKGBUILD b/scripts/package/PKGBUILD
new file mode 100644 (file)
index 0000000..663ce30
--- /dev/null
@@ -0,0 +1,108 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Maintainer: Thomas Weißschuh <[email protected]>
+# Contributor: Jan Alexander Steffens (heftig) <[email protected]>
+
+pkgbase=${PACMAN_PKGBASE:-linux-upstream}
+pkgname=("${pkgbase}" "${pkgbase}-api-headers")
+if grep -q CONFIG_MODULES=y include/config/auto.conf; then
+       pkgname+=("${pkgbase}-headers")
+fi
+pkgver="${KERNELRELEASE//-/_}"
+# The PKGBUILD is evaluated multiple times.
+# Running scripts/build-version from here would introduce inconsistencies.
+pkgrel="${KBUILD_REVISION}"
+pkgdesc='Upstream Linux'
+url='https://www.kernel.org/'
+# Enable flexible cross-compilation
+arch=(${CARCH})
+license=(GPL-2.0-only)
+makedepends=(
+       bc
+       bison
+       cpio
+       flex
+       gettext
+       kmod
+       libelf
+       openssl
+       pahole
+       perl
+       python
+       rsync
+       tar
+)
+options=(!debug !strip !buildflags !makeflags)
+
+build() {
+       # MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
+       # Bypass this override with a custom variable.
+       export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
+       cd "${objtree}"
+
+       ${MAKE} KERNELRELEASE="${KERNELRELEASE}" KBUILD_BUILD_VERSION="${pkgrel}"
+}
+
+_package() {
+       pkgdesc="The ${pkgdesc} kernel and modules"
+
+       export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
+       cd "${objtree}"
+       local modulesdir="${pkgdir}/usr/${MODLIB}"
+
+       echo "Installing boot image..."
+       # systemd expects to find the kernel here to allow hibernation
+       # https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
+       install -Dm644 "$(${MAKE} -s image_name)" "${modulesdir}/vmlinuz"
+
+       # Used by mkinitcpio to name the kernel
+       echo "${pkgbase}" > "${modulesdir}/pkgbase"
+
+       echo "Installing modules..."
+       ${MAKE} INSTALL_MOD_PATH="${pkgdir}/usr" INSTALL_MOD_STRIP=1 \
+               DEPMOD=true modules_install
+
+       if [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
+               echo "Installing dtbs..."
+               ${MAKE} INSTALL_DTBS_PATH="${modulesdir}/dtb" dtbs_install
+       fi
+
+       # remove build link, will be part of -headers package
+       rm -f "${modulesdir}/build"
+}
+
+_package-headers() {
+       pkgdesc="Headers and scripts for building modules for the ${pkgdesc} kernel"
+
+       export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
+       cd "${objtree}"
+       local builddir="${pkgdir}/usr/${MODLIB}/build"
+
+       echo "Installing build files..."
+       "${srctree}/scripts/package/install-extmod-build" "${builddir}"
+
+       echo "Installing System.map and config..."
+       cp System.map "${builddir}/System.map"
+       cp .config "${builddir}/.config"
+
+       echo "Adding symlink..."
+       mkdir -p "${pkgdir}/usr/src"
+       ln -sr "${builddir}" "${pkgdir}/usr/src/${pkgbase}"
+}
+
+_package-api-headers() {
+       pkgdesc="Kernel headers sanitized for use in userspace"
+       provides=(linux-api-headers)
+       conflicts=(linux-api-headers)
+
+       export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
+       cd "${objtree}"
+
+       ${MAKE} headers_install INSTALL_HDR_PATH="${pkgdir}/usr"
+}
+
+for _p in "${pkgname[@]}"; do
+       eval "package_$_p() {
+               $(declare -f "_package${_p#$pkgbase}")
+               _package${_p#$pkgbase}
+       }"
+done
This page took 0.142897 seconds and 4 git commands to generate.