Skip to content
PKGBUILD 6.22 KiB
Newer Older
Seblu's avatar
Seblu committed
# Maintainer: Sébastien Luttringer <seblu@seblu.net>
# Customized version of linux for seblu computers

Seblu's avatar
Seblu committed
pkgname=linux-seblu
Seblu's avatar
Seblu committed
pkgver=5.19.0
Seblu's avatar
Seblu committed
pkgrel=1
Seblu's avatar
Seblu committed
pkgdesc='The Linux Kernel cooked by Seblu'
Seblu's avatar
up  
Seblu committed
arch=('x86_64')
license=('GPL2')
url='http://www.kernel.org'
Seblu's avatar
Seblu committed
options=('!strip' '!buildflags')
Seblu's avatar
Seblu committed
makedepends=('llvm' 'clang' 'lld' 'libelf' 'kmod' 'git' 'make' 'bc' 'sed' 'cpio'
Seblu's avatar
Seblu committed
  'python' 'zstd')
Seblu's avatar
Seblu committed
optdepends=(
  'linux-firmware: linux firmwares'
  'kernel-install-hook: systemd installation helpers'
)
Seblu's avatar
Seblu committed
install=linux-seblu.install
Seblu's avatar
Seblu committed
_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
Seblu's avatar
Seblu committed
source=("git+$_main#tag=v5.19"
Seblu's avatar
Seblu committed
        "config.$CARCH")
Seblu's avatar
Seblu committed
            '91820ec4a2d99f09d7e8153687ae47a1663ba0fdc02c5d5b4ff40a8bec642526')
Seblu's avatar
Seblu committed
prepare() {
Seblu's avatar
Seblu committed
  [[ -d linux-stable ]] && ln -snf linux-stable linux
Seblu's avatar
Seblu committed
  # 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"
Seblu's avatar
Seblu committed
  done

Seblu's avatar
Seblu committed
  # loading default config
Seblu's avatar
Seblu committed
  # use make localmodconfig to check .config is correct
  msg2 'Copying config'
  install "$srcdir/config.$CARCH" .config
Seblu's avatar
Seblu committed
  # force suffixe in config (must be the right!)
  msg2 'Setting kernel suffix'
  sed -ri "s|(CONFIG_LOCALVERSION=).*|\1\"${pkgname#linux*}\"|g" .config
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  # define current build version
Seblu's avatar
Seblu committed
  msg2 'Setting kernel build version'
  echo "$(($pkgrel - 1 ))" > .version

  # no scm version
  # this prevent an issue with “make kernelrelease” which add -dirty to version
  # because ownership of git files has fakely been changed by fakeroot when
  # called from makepkg
  echo '' > .scmversion
Seblu's avatar
Seblu committed

  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.
Seblu's avatar
Seblu committed
  echo -e "\nLLVM = 1\nLLVM_IAS = 1\nexport LLVM LLVM_IAS" >> scripts/Kbuild.include
Seblu's avatar
Seblu committed
}

Seblu's avatar
Seblu committed
pkgver() {
  cd linux
Seblu's avatar
Seblu committed
  make -s kernelversion|tr '-' '_'
Seblu's avatar
Seblu committed
}

Seblu's avatar
Seblu committed
build() {
Seblu's avatar
Seblu committed
  msg2 'Make prepare'
Seblu's avatar
Seblu committed
  make prepare
Seblu's avatar
Seblu committed
  msg2 'Make bzImage'
Seblu's avatar
Seblu committed
  make bzImage
Seblu's avatar
Seblu committed
  msg2 'Make modules'
Seblu's avatar
Seblu committed
  make modules
Seblu's avatar
Seblu committed

  # get real compiled kernel version
Seblu's avatar
Seblu committed
  kernrel=$(make kernelrelease)
Seblu's avatar
Seblu committed
  pkgdesc+=", version $kernrel"
Seblu's avatar
Seblu committed
  pkgname="linux-$kernrel"
Seblu's avatar
Seblu committed
  provides=("linux=$pkgver" "linux-headers=$pkgver" VIRTUALBOX-GUEST-MODULES WIREGUARD-MODULE)
Seblu's avatar
Seblu committed
  msg2 "Kernel release: $kernrel"
  msg2 "Package kernel version: $pkgver"
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  msg2 'Installing vmlinuz'
  install -D -m644 "$(make -s image_name)" "$pkgdir/usr/lib/kernel/vmlinuz-$kernrel"

  msg2 'Installing modules'
Seblu's avatar
up  
Seblu committed
  # disable DEPMOD because it fail due to poor hack in scripts/depmod.sh
Seblu's avatar
Seblu committed
  # 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
Seblu's avatar
up  
Seblu committed

Seblu's avatar
Seblu committed
  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"

Seblu's avatar
Seblu committed
  msg2 'Add mkinitcpio pkgbase file'
  # used by mkinitcpio to name the kernel
  install -Dm644 <(echo "$pkgname") "$pkgdir/usr/lib/modules/$kernrel/pkgbase"

Seblu's avatar
Seblu committed
  install_sources
Seblu's avatar
Seblu committed
  msg2 'Removing firmwares'
Seblu's avatar
up  
Seblu committed
  rm -rf "$pkgdir/usr/lib/firmware"
Seblu's avatar
Seblu committed
install_sources() {
Seblu's avatar
Seblu committed
  local kernsrc="$pkgdir/usr/src/$pkgname"
Seblu's avatar
Seblu committed
  local i
  cd "$srcdir/linux"
Seblu's avatar
Seblu committed
  msg2 'Installing sources'
Seblu's avatar
Seblu committed
  install -d -m 755 "$kernsrc"

Seblu's avatar
Seblu committed
  msg2 'Installing symlinks in modules/'
Seblu's avatar
Seblu committed
  # remove previous build and source links
  rm -f "$pkgdir/usr/lib/modules/$kernrel"/{source,build}
Seblu's avatar
Seblu committed
  ln -rs  "$kernsrc" "$pkgdir/usr/lib/modules/$kernrel"/source
  ln -rs  "$kernsrc" "$pkgdir/usr/lib/modules/$kernrel"/build
Seblu's avatar
Seblu committed
  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
Seblu's avatar
Seblu committed
    [[ -e "$i" ]] && install -m644 "$i" "$kernsrc/$i"
Seblu's avatar
Seblu committed
  msg2 'Installing scripts'
  cp -t "$kernsrc" -a scripts
Seblu's avatar
Seblu committed
  # 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'
Seblu's avatar
Seblu committed
  for i in "$kernsrc"/arch/*; do
Seblu's avatar
Seblu committed
    [[ "${i##*/}" != x86 ]] && rm -rf "$i"
Seblu's avatar
Seblu committed
  done

Seblu's avatar
Seblu committed
  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" ;;
Seblu's avatar
Seblu committed
  done < <(find "$kernsrc" -type f -perm -u+x -print0)

  msg2 'Removing sources broken symlinks'
  find -L "$kernsrc" -type l -printf 'Removing %P\n' -delete
Seblu's avatar
Seblu committed
  msg2 'Removing sources lost objects'
  find "$kernsrc" -type f -name '*.o' -printf 'Removing %P\n' -delete
# vim:set ts=2 sw=2 ft=sh et: