1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/scripts/package/PKGBUILD
Masahiro Yamada 82a1978d0f kheaders: use 'tar' instead of 'cpio' for copying files
The 'cpio' command is used solely for copying header files to the
temporary directory. However, there is no strong reason to use 'cpio'
for this purpose. For example, scripts/package/install-extmod-build
uses the 'tar' command to copy files.

This commit replaces the use of 'cpio' with 'tar' because 'tar' is
already used in this script to generate kheaders_data.tar.xz anyway.

Performance-wide, there is no significant difference between 'cpio'
and 'tar'.

[Before]

  $ rm -fr kheaders; mkdir kheaders
  $ time sh -c '
  for f in include arch/x86/include
  do
          find "$f" -name "*.h"
  done | cpio --quiet -pd kheaders
  '
  real    0m0.148s
  user    0m0.021s
  sys     0m0.140s

[After]

  $ rm -fr kheaders; mkdir kheaders
  $ time sh -c '
  for f in include arch/x86/include
  do
          find "$f" -name "*.h"
  done | tar -c -f - -T - | tar -xf - -C kheaders
  '
  real    0m0.098s
  user    0m0.024s
  sys     0m0.131s

Revert commit 69ef0920bd ("Docs: Add cpio requirement to changes.rst")
because 'cpio' is not used anywhere else during the kernel build.
Please note that the built-in initramfs is created by the in-tree tool,
usr/gen_init_cpio, so it does not rely on the external 'cpio' command
at all.

Remove 'cpio' from the package build dependencies as well.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2025-01-10 23:01:22 +09:00

131 lines
3.2 KiB
Bash

# SPDX-License-Identifier: GPL-2.0-only
# Maintainer: Thomas Weißschuh <linux@weissschuh.net>
# Contributor: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
pkgbase=${PACMAN_PKGBASE:-linux-upstream}
pkgname=("${pkgbase}")
_extrapackages=${PACMAN_EXTRAPACKAGES-headers api-headers debug}
for pkg in $_extrapackages; do
pkgname+=("${pkgbase}-${pkg}")
done
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
flex
gettext
kmod
libelf
openssl
pahole
perl
python
rsync
tar
)
options=(!debug !strip !buildflags !makeflags)
_prologue() {
# MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
# Bypass this override with a custom variable.
export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
# Kbuild works in the output directory, where this PKGBUILD is located.
cd "$(dirname "${BASH_SOURCE[0]}")"
}
build() {
_prologue
${MAKE} KERNELRELEASE="${KERNELRELEASE}" KBUILD_BUILD_VERSION="${pkgrel}"
}
_package() {
pkgdesc="The ${pkgdesc} kernel and modules"
local modulesdir="${pkgdir}/usr/${MODLIB}"
_prologue
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"
local builddir="${pkgdir}/usr/${MODLIB}/build"
_prologue
if grep -q CONFIG_MODULES=y include/config/auto.conf; then
echo "Installing build files..."
"${srctree}/scripts/package/install-extmod-build" "${builddir}"
fi
echo "Installing System.map and config..."
mkdir -p "${builddir}"
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="${pkgver}")
conflicts=(linux-api-headers)
_prologue
${MAKE} headers_install INSTALL_HDR_PATH="${pkgdir}/usr"
}
_package-debug(){
pkgdesc="Non-stripped vmlinux file for the ${pkgdesc} kernel"
local debugdir="${pkgdir}/usr/src/debug/${pkgbase}"
local builddir="${pkgdir}/usr/${MODLIB}/build"
_prologue
install -Dt "${debugdir}" -m644 vmlinux
mkdir -p "${builddir}"
ln -sr "${debugdir}/vmlinux" "${builddir}/vmlinux"
}
for _p in "${pkgname[@]}"; do
eval "package_$_p() {
$(declare -f "_package${_p#$pkgbase}")
_package${_p#$pkgbase}
}"
done