Newer
Older
# Maintainer: Sébastien Luttringer <seblu@seblu.net>
# Customized version of linux for seblu computers
license=('GPL2')
url='http://www.kernel.org'
makedepends=('llvm' 'clang' 'lld' 'libelf' 'kmod' 'git' 'make' 'bc' 'sed' 'cpio'
optdepends=(
'linux-firmware: linux firmwares'
'kernel-install-hook: systemd installation helpers'
)
_main=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
_stable=https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
_next=https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
sha256sums=('c7b693570f0c9f445ca246eb397557405149aa45a5fb5ee29a7c426d6dbc0dee'
'e0f905f47cee645b0831181d44b30ce634aca0313f3240d1150762cca94c2d5a')
[[ ! -d linux && -d linux-stable ]] && ln -snf linux-stable linux
[[ ! -d linux && -d linux-next ]] && ln -snf linux-next linux
# apply patch from the source array (should be a pacman feature)
local src
for src in "${source[@]}"; do
src="${src%%::*}"
src="${src##*/}"
[[ $src = *.patch ]] || continue
msg2 "Applying patch $src..."
patch -Np1 < "../$src"
# use make localmodconfig to check .config is correct
msg2 'Copying config'
# force suffixe in config (must be the right!)
msg2 'Setting kernel suffix'
sed -ri "s|(CONFIG_LOCALVERSION=).*|\1\"${pkgname#linux*}\"|g" .config
msg2 'Setting kernel build version'
echo "$(($pkgrel - 1 ))" > .version
# prevent addition of -dirty to version
msg2 'Patch setlocalversion'
sed -i 's|no_dirty=false|no_dirty=true|' scripts/setlocalversion
msg2 'Force use of LLVM in makefile'
# early makefile patching achieve 2 goals. Firstly, avoid adding variables to
# each make call. Secondly, it is later used by tools (e.g dkms) to build
# out-of-tree modules.
echo -e "\nLLVM = 1\nLLVM_IAS = 1\nexport LLVM LLVM_IAS" >> scripts/Kbuild.include
# get real compiled kernel version
provides=("linux=$pkgver" "linux-headers=$pkgver" "linux=${pkgver%.*}" VIRTUALBOX-GUEST-MODULES WIREGUARD-MODULE KSMBD-MODULE)
msg2 "Kernel release: $kernrel"
msg2 "Package kernel version: $pkgver"
msg2 'Installing vmlinuz'
install -D -m644 "$(make -s image_name)" "$pkgdir/usr/lib/kernel/vmlinuz-$kernrel"
msg2 'Installing modules'
# INSTALL_MOD_STRIP will cause modules to be fully stripped
make -s INSTALL_MOD_PATH="$pkgdir/usr" INSTALL_MOD_STRIP=1 DEPMOD=/bin/true modules_install
msg2 'Generating modules.dep and map files'
# run depmod to keep track of these files and remove them with the package
depmod -b "$pkgdir/usr" -F System.map "$kernrel"
msg2 'Symlink kernel into modules subdirectory'
# kernel-all expect kernel image in the modules directory
ln -s "../../kernel/vmlinuz-$kernrel" "$pkgdir/usr/lib/modules/$kernrel/vmlinuz"
msg2 'Add mkinitcpio pkgbase file'
# used by mkinitcpio to name the kernel
install -Dm644 <(echo "$pkgname") "$pkgdir/usr/lib/modules/$kernrel/pkgbase"
# remove previous build and source links
rm -f "$pkgdir/usr/lib/modules/$kernrel"/{source,build}
ln -rs "$kernsrc" "$pkgdir/usr/lib/modules/$kernrel"/source
ln -rs "$kernsrc" "$pkgdir/usr/lib/modules/$kernrel"/build
msg2 'Installing build files'
install -Dt "$kernsrc" -m644 .config Makefile Module.symvers System.map
install -Dt "$kernsrc/kernel" -m644 kernel/Makefile
install -Dt "$kernsrc/arch/x86" -m644 arch/x86/Makefile
for i in version localversion*; do
# add objtool for external module building when enabled VALIDATION_STACK option
# this is adding dependencty to glibc and libelf to the kernel package
msg2 'Installing objtool'
install -Dt "$kernsrc/tools/objtool" tools/objtool/objtool
msg2 'Installing headers'
cp -t "$kernsrc" -a include
# arch includes for external modules
cp -t "$kernsrc/arch/x86" -a arch/x86/include
install -Dt "$kernsrc/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s
# dm headers
install -Dt "$kernsrc/drivers/md" -m644 drivers/md/*.h
# wireless headers
install -Dt "$kernsrc/net/mac80211" -m644 net/mac80211/*.h
# dvb headers, http://bugs.archlinux.org/task/13146
install -Dt "$kernsrc/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
# dvb headers, http://bugs.archlinux.org/task/20402
install -Dt "$kernsrc/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
install -Dt "$kernsrc/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
install -Dt "$kernsrc/drivers/media/tuners" -m644 drivers/media/tuners/*.h
msg2 'Installing Kconfig files'
find . -name 'Kconfig*' -exec install -Dm644 {} "$kernsrc/{}" \;
msg2 'Removing unneeded architectures'
msg2 'Removing documentation'
rm -r "$kernsrc/Documentation"
msg2 'Stripping exectuables'
while read -rd '' i; do
case "$(file -Sbi "$i")" in
application/x-sharedlib\;*) # Libraries (.so)
strip -v $STRIP_SHARED "$i" ;;
application/x-archive\;*) # Libraries (.a)
strip -v $STRIP_STATIC "$i" ;;
application/x-executable\;*) # Binaries
strip -v $STRIP_BINARIES "$i" ;;
application/x-pie-executable\;*) # Relocatable binaries
strip -v $STRIP_SHARED "$i" ;;
done < <(find "$kernsrc" -type f -perm -u+x -print0)
msg2 'Removing sources broken symlinks'
find -L "$kernsrc" -type l -printf 'Removing %P\n' -delete
msg2 'Removing sources lost objects'
find "$kernsrc" -type f -name '*.o' -printf 'Removing %P\n' -delete