Skip to content
PKGBUILD 6.72 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=4.20
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')
makedepends=('glibc' 'libelf' 'kmod' 'git' 'make' 'gcc' 'bc' 'sed')
Seblu's avatar
Seblu committed
depends=('linux-firmware' 'kernel-install-hook')
Seblu's avatar
Seblu committed
install=linux-seblu.install
_repourl='git+https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git'
#_repourl='git+https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git'
Seblu's avatar
Seblu committed
source=("$_repourl#tag=v${pkgver/_/-}"
Seblu's avatar
Seblu committed
        "config.$CARCH")
Seblu's avatar
Seblu committed
md5sums=('SKIP'
Seblu's avatar
Seblu committed
         '4cd9e1f416590da5e993c2691dd434ae')
Seblu's avatar
Seblu committed
prepare() {
  # fake linux directory if necessary
  if [[ ${_repourl##*/} != 'linux.git' ]]; then
    local _reponame="${_repourl##*/}"
    ln -sfT "${_reponame%.git}" linux
  fi

  cd linux

  # apply patches
  for _f in "${source[@]}"; do
    if [[ "$_f" =~ \.patch$ ]]; then
      msg2 "Patching $_f"
Seblu's avatar
Seblu committed
      patch -p1 < "$srcdir/$_f"
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
}

build() {
Seblu's avatar
Seblu committed
  msg2 'Make prepare'
  make prepare
Seblu's avatar
Seblu committed
  msg2 'Make bzImage'
  make bzImage
Seblu's avatar
Seblu committed
  msg2 'Make modules'
  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
  pkgver=$(make kernelversion|tr '-' '_')
Seblu's avatar
Seblu committed
  provides=("linux=$pkgver" "linux-headers=$pkgver")
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 'Install vmlinuz'
  install -D -m644 arch/x86/boot/bzImage "$pkgdir/usr/lib/kernel/vmlinuz-$kernrel"

Seblu's avatar
Seblu committed
  msg2 'Install 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 'Install sources'
Seblu's avatar
Seblu committed
  install_sources
Seblu's avatar
Seblu committed
  msg2 'Remove firmwares'
Seblu's avatar
up  
Seblu committed
  rm -rf "$pkgdir/usr/lib/firmware"
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  msg2 'Generate 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
  local kernsrc="$pkgdir/usr/src/$pkgname"

  # create $kernsrc directory
  install -d -m 755 "$kernsrc"

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

  # Copy kernel config files
  cd "$srcdir/linux"
Seblu's avatar
Seblu committed
  install -D -m644 Makefile "$kernsrc/Makefile"
  install -D -m644 kernel/Makefile "$kernsrc/kernel/Makefile"
  install -D -m644 .config "$kernsrc/.config"
  for i in localversion*; do
Seblu's avatar
Seblu committed
    [[ -e "$i" ]] && install -m644 "$i" "$kernsrc/$i"
  done

  # create include directory
Seblu's avatar
Seblu committed
  install -d "$kernsrc/include"

  for i in acpi asm-generic config crypto drm generated linux math-emu \
    media net pcmcia scsi sound trace uapi video xen; do
Seblu's avatar
Seblu committed
    cp -a include/$i "$kernsrc/include/"
  done

  # copy arch includes for external modules
Seblu's avatar
Seblu committed
  install -d "$kernsrc/arch/x86"
  cp -a arch/x86/include "$kernsrc/arch/x86/"

  # copy files necessary for later builds, like nvidia and vmware
Seblu's avatar
Seblu committed
  cp Module.symvers "$kernsrc"
  cp -a scripts "$kernsrc"
  # remove broken symlinks of unneeded architectures in scripts
  rm -r "$kernsrc/scripts/dtc/include-prefixes"

  # fix permissions on scripts dir
Seblu's avatar
Seblu committed
  chmod og-w -R "$kernsrc/scripts"
Seblu's avatar
Seblu committed
  # add x86 makefile
Seblu's avatar
Seblu committed
  install -d "$kernsrc/.tmp_versions"
  install -d "$kernsrc/arch/x86/kernel"
  cp arch/x86/Makefile "$kernsrc/arch/x86/"
  cp arch/x86/kernel/asm-offsets.s "$kernsrc/arch/x86/kernel/"

  # add dm headers
Seblu's avatar
Seblu committed
  install -d "$kernsrc/drivers/md"
  cp drivers/md/*.h  "$kernsrc/drivers/md"

  # add inotify.h
Seblu's avatar
Seblu committed
  install -d "$kernsrc/include/linux"
  cp include/linux/inotify.h "$kernsrc/include/linux/"

  # add wireless headers
Seblu's avatar
Seblu committed
  install -d "$kernsrc/net/mac80211/"
  cp net/mac80211/*.h "$kernsrc/net/mac80211/"

  # add dvb headers for external modules
  # in reference to:
  # http://bugs.archlinux.org/task/11194
Seblu's avatar
Seblu committed
  install -d "$kernsrc/include/config/dvb/"
  cp include/config/dvb/*.h "$kernsrc/include/config/dvb/"

  # add dvb headers for http://mcentral.de/hg/~mrec/em28xx-new
  # in reference to:
  # http://bugs.archlinux.org/task/13146
  install -Dm644 drivers/media/dvb-frontends/lgdt330x.h \
Seblu's avatar
Seblu committed
    "$kernsrc/drivers/media/dvb-frontends/dvb-frontends/lgdt330x.h"
  install -Dm644 drivers/media/i2c/msp3400-driver.h \
Seblu's avatar
Seblu committed
    "$kernsrc/drivers/media/i2c/msp3400-driver.h"

  # add dvb headers
  # in reference to:
  # http://bugs.archlinux.org/task/20402
Seblu's avatar
Seblu committed
  install -d "$kernsrc/drivers/media/usb/dvb-usb"
  cp drivers/media/usb/dvb-usb/*.h "$kernsrc/drivers/media/usb/dvb-usb/"
  install -d "$kernsrc/drivers/media/dvb-frontends"
  cp drivers/media/dvb-frontends/*.h "$kernsrc/drivers/media/dvb-frontends/"
  install -d "$kernsrc/drivers/media/tuners"
  cp drivers/media/tuners/*.h "$kernsrc/drivers/media/tuners/"

  # copy in Kconfig files
  for i in $(find . -name "Kconfig*"); do
Seblu's avatar
Seblu committed
    install -d "$kernsrc"/$(echo $i | sed 's|/Kconfig.*||')
    cp "$i" "$kernsrc/$i"
Seblu's avatar
Seblu committed
  # remove unneeded architectures added by copying Kconfig
  for i in "$kernsrc"/arch/*; do
Seblu's avatar
Seblu committed
    [[ "${i##*/}" != x86 ]] && rm -rf "$i"
Seblu's avatar
Seblu committed
  done

  # add objtool for external module building when enabled VALIDATION_STACK option
  # this is adding dependencty to glibc and libelf to the kernel package
  install -d "$kernsrc/tools/objtool"
  cp tools/objtool/objtool "$kernsrc/tools/objtool"

Seblu's avatar
Seblu committed
  # fix permissions
  chown -R root:root "$kernsrc"
  find "$kernsrc" -type d -exec chmod 755 {} \;

  # strip scripts directory
Seblu's avatar
Seblu committed
  find "$kernsrc/scripts" -type f -perm -u+w 2>/dev/null | while read binary ; do
    case "$(file -bi "$binary")" in
      *application/x-sharedlib*) # Libraries (.so)
Seblu's avatar
Seblu committed
        strip $STRIP_SHARED "$binary";;
      *application/x-archive*) # Libraries (.a)
Seblu's avatar
Seblu committed
        strip $STRIP_STATIC "$binary";;
      *application/x-executable*) # Binaries
Seblu's avatar
Seblu committed
        strip $STRIP_BINARIES "$binary";;
Seblu's avatar
Seblu committed
  # check rights
Seblu's avatar
Seblu committed
  chown -R root.root "$kernsrc"
  chmod -R u=rwX,go=rX "$kernsrc"
# vim:set ts=2 sw=2 ft=sh et: