File PKGBUILD of Package linux-cachyos
_major=6.18
_minor=0
pkgbase=linux-cachyos
if [[ ! -z "$KBUILD_BUILD_HOST" ]]; then
pkgbase="linux-cachyos-$KBUILD_BUILD_HOST"
fi
pkgname=("$pkgbase" "$pkgbase-headers")
if [[ ! -z "$KBUILD_BUILD_DEBUG" ]]; then
pkgname+=("$pkgbase-dbg")
fi
pkgdesc='Linux BORE + LTO + Cachy Sauce Kernel by CachyOS with other patches and improvements'
pkgver="$_major.$_minor"
pkgrel=1
url="https://github.com/misotolar/linux-cachyos"
license=('GPL2')
arch=(
x86_64
x86_64_v3
)
_srcdir="linux-$_major"
_kernel="https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x"
_cachyos="acf85ecb3d8a03fb9fd3160ce6d9bdb05ef1c124"
_cachyos="https://raw.githubusercontent.com/cachyos/linux-cachyos/$_cachyos/linux-cachyos"
_patches="0ac7e72d6b9f973a1682806d0166042869aa4144"
_patches="https://raw.githubusercontent.com/cachyos/kernel-patches/$_patches/$_major"
makedepends=(
bc
clang
cpio
libelf
lld
llvm
pahole
perl
python
rust
rust-bindgen
rust-src
tar
xz
zstd
)
options=(
!debug
!strip
)
source=(
"$_kernel/$_srcdir.tar.xz"
"$_kernel/$_srcdir.tar.sign"
"$_cachyos/config" 'config.sh' 'config.trinity.sh'
'0101-CACHYOS-cachyos-base-all.patch'::"$_patches/all/0001-cachyos-base-all.patch"
'0102-CACHYOS-bore-cachy.patch'::"$_patches/sched/0001-bore-cachy.patch"
'0103-CACHYOS-dkms-clang.patch'::"$_patches/misc/dkms-clang.patch"
)
validpgpkeys=(
ABAF11C65A2970B130ABE3C479BE3E4300411886 # Linus Torvalds
647F28654894E3BD457199BE38DBBDC86092693E # Greg Kroah-Hartman
)
b2sums=('b94b7b9bf18aca0c3e50baf79b009a1448fc6cd9c3ee019f641cc247dcf53a4abef4274ee0608ad8cd4943af69854363a95d26e117ff23620bb07dccb158859f'
'SKIP'
'e39b09a43f94c626b7788d437fb1e26dfcd719c184581405e91546bd9231bb9de2b97bc6d8b2c0ce017ed67d946a16ab146ffbdd87fc0161426b8ecde0027469'
'e20d1013d5870a2dfd6ab30aa5c0978ddf052570f518b7a8c4cad8e2a1a9c0f18e4eb033091baf017a751e196dc86286d28c19252aa2f4b078d54915da424d5d'
'd3db1c54c1e3e530bff681d0bf806e05c2dcef8387857e15c92d9f8fdd755fed3c9ca135330e5db0bcba0fbdc999885292477ed43c689b190d4f410583511683'
'bf61130d27b16f3ac7129dc57095103efba918d6468d2726d0ed73982c99967e05c7ca2e62e269f9e2e7433c416a231cb7f8af2afc507e336da39cbb82202977'
'bfd5d4cdfe8f2c2e7466d7095befe40f95049ef8190e2ba01d7ba853903741d6ccb54087e8af72f4dad1790faf6d341d7b55b14eb00405d54bd4f62c772b880d'
'c7294a689f70b2a44b0c4e9f00c61dbd59dd7063ecbe18655c4e7f12e21ed7c5bb4f5169f5aa8623b1c59de7b2667facb024913ecb9f4c650dabce4e8a7e5452')
export KBUILD_BUILD_USER="${KBUILD_BUILD_USER:-$pkgbase}"
export KBUILD_BUILD_HOST="${KBUILD_BUILD_HOST:-archlinux}"
export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
export KBUILD_BUILD_FLAGS=(
CC=clang
LD=ld.lld
LLVM=1
LLVM_IAS=1
)
prepare() {
if [ -d /usr/src/certs-local ]; then
echo "Rebuilding local signing key..."
cp -rf /usr/src/certs-local ../
cd ../certs-local
echo "Updating kernel config with new key..."
./genkeys.py -v --config ../src/config
cd ../src
fi
cd $_srcdir
echo "Setting version..."
echo "-$pkgrel" > localversion.10-pkgrel
echo "${pkgbase#linux}" > localversion.20-pkgname
if [[ "archlinux" != "$KBUILD_BUILD_HOST" ]]; then
echo "-$KBUILD_BUILD_HOST" > localversion.20-pkgname
fi
local src
for src in "${source[@]}"; do
src="${src%%::*}"
src="${src##*/}"
src="${src%.zst}"
[[ $src = *.patch ]] || continue
echo "Applying patch $src..."
patch -Nsp1 < "../$src"
done
echo "Setting config..."
cp ../config .config
### Configuration
sh $srcdir/config.sh
### AutoFDO
if [ ! -z KBUILD_BUILD_DEBUG ] || [ ! -z KBUILD_AUTOFDO_PROFILE ]; then
scripts/config -e AUTOFDO_CLANG
if [ ! -z KBUILD_AUTOFDO_PROFILE ]; then
KBUILD_BUILD_FLAGS+=(CLANG_AUTOFDO_PROFILE="${KBUILD_AUTOFDO_PROFILE}")
fi
fi
### Propeller
if [ ! -z KBUILD_BUILD_DEBUG ] || [ ! -z KBUILD_PROPELLER_PROFILE_PREFIX ]; then
scripts/config -e PROPELLER_CLANG
if [ ! -z KBUILD_AUTOFDO_PROFILE ]; then
KBUILD_BUILD_FLAGS+=(CLANG_PROPELLER_PROFILE_PREFIX="${KBUILD_PROPELLER_PROFILE_PREFIX}")
fi
fi
### Modprobed-db
if [ -f "$HOME/.config/modprobed.db" ]; then
yes "" | make ${KBUILD_BUILD_FLAGS[*]} LSMOD=$HOME/.config/modprobed.db localmodconfig >/dev/null
fi
### Build host configuration
if [ -f "$srcdir/config.$KBUILD_BUILD_HOST.sh" ]; then
sh $srcdir/config.$KBUILD_BUILD_HOST.sh
fi
### Rewrite configuration
echo "Rewrite configuration..."
make ${KBUILD_BUILD_FLAGS[*]} prepare
yes "" | make ${KBUILD_BUILD_FLAGS[*]} config >/dev/null
### Prepared version
make -s kernelrelease > version
echo "Prepared $pkgbase version $(<version)"
}
build() {
cd $_srcdir
make ${KBUILD_BUILD_FLAGS[*]} -j$(nproc) all
make -C tools/bpf/bpftool vmlinux.h feature-clang-bpf-co-re=1
}
_package() {
pkgdesc="The $pkgdesc kernel and modules"
depends=('coreutils' 'kmod' 'initramfs')
optdepends=('wireless-regdb: to set the correct wireless channels of your country'
'linux-firmware: firmware images needed for some devices'
'modprobed-db: Keeps track of EVERY kernel module that has ever been probed - useful for those of us who make localmodconfig'
'scx-scheds: to use sched-ext schedulers')
provides=(ADIOS-MODULE KSMBD-MODULE NTSYNC-MODULE UKSMD-BUILTIN VHBA-MODULE VIRTUALBOX-GUEST-MODULES V4L2LOOPBACK-MODULE WIREGUARD-MODULE)
replaces=()
cd $_srcdir
local modulesdir="$pkgdir/usr/lib/modules/$(<version)"
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" | install -Dm644 /dev/stdin "$modulesdir/pkgbase"
echo "Installing modules..."
ZSTD_CLEVEL=-1 make INSTALL_MOD_PATH="$pkgdir/usr" INSTALL_MOD_STRIP=1 \
DEPMOD=/doesnt/exist modules_install # Suppress depmod
# remove build links
rm "$modulesdir"/build
}
_package-headers() {
pkgdesc="Headers and scripts for building modules for the $pkgdesc kernel"
depends=("${pkgbase}" 'clang' 'llvm' 'lld' 'pahole')
cd $_srcdir
local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
echo "Installing build files..."
install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map \
localversion.* version vmlinux tools/bpf/bpftool/vmlinux.h
install -Dt "$builddir/kernel" -m644 kernel/Makefile
install -Dt "$builddir/arch/x86" -m644 arch/x86/Makefile
cp -t "$builddir" -a scripts
ln -srt "$builddir" "$builddir/scripts/gdb/vmlinux-gdb.py"
# required when STACK_VALIDATION is enabled
install -Dt "$builddir/tools/objtool" tools/objtool/objtool
# required when DEBUG_INFO_BTF_MODULES is enabled
if [ -f tools/bpf/resolve_btfids/resolve_btfids ]; then
install -Dt "$builddir/tools/bpf/resolve_btfids" tools/bpf/resolve_btfids/resolve_btfids
fi
echo "Installing headers..."
cp -t "$builddir" -a include
cp -t "$builddir/arch/x86" -a arch/x86/include
install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s
install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h
# https://bugs.archlinux.org/task/13146
install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
# https://bugs.archlinux.org/task/20402
install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h
# https://bugs.archlinux.org/task/71392
install -Dt "$builddir/drivers/iio/common/hid-sensors" -m644 drivers/iio/common/hid-sensors/*.h
echo "Installing KConfig files..."
find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;
# Install .rmeta files if they exist
if compgen -G "rust/*.rmeta" 1>/dev/null; then
install -Dt "$builddir/rust" -m644 rust/*.rmeta
fi
# Install .so files if they exist
if compgen -G "rust/*.so" 1>/dev/null; then
install -Dt "$builddir/rust" rust/*.so
fi
echo "Installing unstripped VDSO..."
make INSTALL_MOD_PATH="$pkgdir/usr" vdso_install \
link= # Suppress build-id symlinks
echo "Removing unneeded architectures..."
local arch
for arch in "$builddir"/arch/*/; do
[[ $arch = */x86/ ]] && continue
echo "Removing $(basename "$arch")"
rm -r "$arch"
done
echo "Removing documentation..."
rm -r "$builddir/Documentation"
echo "Removing broken symlinks..."
find -L "$builddir" -type l -printf 'Removing %P\n' -delete
echo "Removing loose objects..."
find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete
echo "Stripping build tools..."
local file
while read -rd '' file; do
case "$(file -Sib "$file")" in
application/x-sharedlib\;*) # Libraries (.so)
strip -v $STRIP_SHARED "$file" ;;
application/x-archive\;*) # Libraries (.a)
strip -v $STRIP_STATIC "$file" ;;
application/x-executable\;*) # Binaries
strip -v $STRIP_BINARIES "$file" ;;
application/x-pie-executable\;*) # Relocatable binaries
strip -v $STRIP_SHARED "$file" ;;
esac
done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)
echo "Stripping vmlinux..."
strip -v $STRIP_STATIC "$builddir/vmlinux"
echo "Adding symlink..."
mkdir -p "$pkgdir/usr/src"
ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase"
# Out-of-tree module signing
if [ -d /usr/src/certs-local ]; then
echo "Local signing certs for out-of-tree modules..."
certs_local_src="../../certs-local"
certs_local_dst="${builddir}/certs-local"
# Certificates
${certs_local_src}/install-certs.py $certs_local_dst
fi
}
_package-dbg() {
pkgdesc="Non-stripped vmlinux file for the $pkgdesc kernel"
depends=("${pkgbase}-headers")
cd $_srcdir
mkdir -p "$pkgdir/usr/src/debug/${pkgbase}"
install -Dt "$pkgdir/usr/src/debug/${pkgbase}" -m644 vmlinux
}
for _p in "${pkgname[@]}"; do
eval "package_$_p() {
$(declare -f "_package${_p#$pkgbase}")
_package${_p#$pkgbase}
}"
done