Skip to content
PKGBUILD 5.82 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.12.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')
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.12"
Seblu's avatar
Seblu committed
        "config.$CARCH")
Seblu's avatar
Seblu committed
            'e7e44ca2662ea5eaaefe8510bf711480b200dc0b706dccab549414469490a51b')
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
}

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 LLVM=1 LLVM_IAS=1 prepare
Seblu's avatar
Seblu committed
  msg2 'Make bzImage'
Seblu's avatar
Seblu committed
  make LLVM=1 LLVM_IAS=1 bzImage
Seblu's avatar
Seblu committed
  msg2 'Make modules'
Seblu's avatar
Seblu committed
  make LLVM=1 LLVM_IAS=1 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
  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: