Skip to content
PKGBUILD 10 KiB
Newer Older
# Maintainer: Sébastien Luttringer <seblu@aur.archlinux.org>
# Customized version of linux for seblu computers

shopt -s nullglob

Seblu's avatar
up  
Seblu committed
kernelver=3.7.2
Seblu's avatar
Seblu committed
kernelsuf=-seblu
Seblu's avatar
Seblu committed
pkgname=linux
Seblu's avatar
up  
Seblu committed
pkgver=2
Seblu's avatar
up  
Seblu committed
pkgrel=1
Seblu's avatar
up  
Seblu committed
arch=('x86_64')
license=('GPL2')
url='http://www.kernel.org'
options=('!strip')
makedepends=('xmlto' 'docbook-xsl')
source=(
Seblu's avatar
up  
Seblu committed
  "config.$CARCH"
Seblu's avatar
up  
Seblu committed
#  '01-Revert-Bluetooth-Add-missing-QUIRK_NO_RESET-test-to-.patch'
Seblu's avatar
up  
Seblu committed
#  '02-change-default-console-loglevel.patch'
Seblu's avatar
Seblu committed
# here we have a linus rc kernel
if [[ $kernelver =~ -rc ]]; then
  kernelbase=${kernelver%-rc*}
  kernelbase=${kernelbase%%.*}.$((${kernelbase##*.} - 1))
Seblu's avatar
up  
Seblu committed
  source+=("linux-$kernelver.patch.xz::http://www.kernel.org/pub/linux/kernel/v3.0/testing/patch-$kernelver.xz")
Seblu's avatar
Seblu committed
# here we have stable kernel schema
elif [[ $kernelver =~ [[:digit:]]\.[[:digit:]]\.[[:digit:]] ]]; then
  kernelbase=${kernelver%.*}
  (( ${kernelver##*.} != 0 )) &&
Seblu's avatar
up  
Seblu committed
    source+=("linux-$kernelver.patch.xz::http://www.kernel.org/pub/linux/kernel/v3.0/patch-$kernelver.xz")
Seblu's avatar
Seblu committed
# here we have a linus kernel
else
  kernelbase=$kernelver
  kernelver=$kernelver.0
fi
source+=("http://www.kernel.org/pub/linux/kernel/v3.0/linux-$kernelbase.tar.xz")
# we can now compute real package name. Useful to avoid overwrite
pkgname=$pkgname$kernelsuf-$kernelver

# small hack to avoid makepkg to check checksum
SKIPCHECKSUMS=1

build() {
  msg2 "Kernel version: $kernelver"
  msg2 "Kernel suffix: $kernelsuf"

Seblu's avatar
up  
Seblu committed
  # priorize upstream patch
  if [[ -e linux-$kernelver.patch ]]; then
    mv -f linux-$kernelver.patch 00-linux-$kernelver.patch
  fi

Seblu's avatar
Seblu committed
  cd linux-$kernelbase
Seblu's avatar
Seblu committed
  if (( NOEXTRACT == 0 )); then
Seblu's avatar
up  
Seblu committed
    # priorize upstream update patch
Seblu's avatar
Seblu committed
    # merging patches
Seblu's avatar
up  
Seblu committed
    for _f in "$srcdir"/*.patch; do
Seblu's avatar
Seblu committed
      [[ -r "$_f" ]] || continue
      msg2 "  Applying patch: ${_f##*/}"
      patch -N -p1 -i "$_f"
    done

	  # loading default config
    # use make localmodconfig to check .config is correct
    msg2 'Copying config'
Seblu's avatar
Seblu committed
    install "$srcdir"/config.$CARCH .config

	  # removing last dot if zero
	  #sed -ri 's/^SUBLEVEL = 0$/SUBLEVEL =/' Makefile
  fi

	# updating suffixe in config (must be the right!)
	msg2 'Setting kernel suffix'
Seblu's avatar
Seblu committed
	sed -i "s|CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"$kernelsuf\"|g" .config

  # define current build version
Seblu's avatar
Seblu committed
  echo $((pkgver - 1)) > .version

  # Preapre compilation
Seblu's avatar
Seblu committed
  msg2 'Preparing compilation'
  yes '' | make config &>/dev/null
  nice -n 19 make prepare &>/dev/null
  cpucount=$(grep -c processor /proc/cpuinfo 2>/dev/null)
  jc=$((${cpucount:-1}))

  # Compiling sources
  msg2 "Compiling (jobs=$jc)"
  nice -n 19 make -j $jc bzImage modules
}

package() {
Seblu's avatar
Seblu committed
  cd linux-$kernelbase
  # get real compiled kernel version
  compver=$(make kernelrelease)
  pkgdesc="The Linux Kernel, version $compver"
Seblu's avatar
up  
Seblu committed
  provides=("linux=$kernelver" "linux-headers=$kernelver" "linux-docs=$kernelver")
Seblu's avatar
Seblu committed
  depends=('coreutils' 'linux-firmware' 'kmod' 'mkinitcpio')
  install='install'

  sed -ri "s/pkgname=.*/pkgname='$pkgname'/" "$startdir/install"

  # installing modules
Seblu's avatar
up  
Seblu committed
  # disable DEPMOD because it fail due to poor hack in scripts/depmod.sh
  make INSTALL_MOD_PATH="$pkgdir/usr" DEPMOD=/bin/true modules_install

  # do manual depmod call
Seblu's avatar
Seblu committed
  depmod -b "$pkgdir/usr" -- "$compver"

  # install kernel and map
Seblu's avatar
Seblu committed
  install -D -m644 arch/x86/boot/bzImage "$pkgdir/boot/vmlinuz-$compver"

  # install mkinitcpio preset file for kernel
Seblu's avatar
Seblu committed
  install -d "$pkgdir/etc/mkinitcpio.d/"
  cat > "$pkgdir/etc/mkinitcpio.d/$pkgname.preset" << EOF
# mkinitcpio preset file for $pkgname

ALL_config="/etc/mkinitcpio.conf"
Seblu's avatar
Seblu committed
ALL_kver="/boot/vmlinuz-$compver"

PRESETS=('default' 'fallback')

#default_config="/etc/mkinitcpio.conf"
Seblu's avatar
Seblu committed
default_image="/boot/initramfs-$compver.img"
#default_options=""

#fallback_config="/etc/mkinitcpio.conf"
Seblu's avatar
Seblu committed
fallback_image="/boot/initramfs-$compver-fallback.img"
fallback_options="-S autodetect"
EOF

  # setup current version package (used by install script)
Seblu's avatar
Seblu committed
  install -d "$pkgdir/usr/share/$pkgname"
  cat > "$pkgdir/usr/share/$pkgname/info" << EOF
KERNEL_NAME=$pkgname
KERNEL_VERSION=$kernelver
KERNEL_SUFFIX=$kernelsuf
KERNEL_BUILD=$compver
Seblu's avatar
Seblu committed

  # remove build and source links
Seblu's avatar
up  
Seblu committed
  rm -f "$pkgdir/usr/lib/modules/$compver"/{source,build}

  # remove the firmware (avoiding conflict with 2.6
Seblu's avatar
up  
Seblu committed
  rm -rf "$pkgdir/usr/lib/firmware"
Seblu's avatar
Seblu committed

  # copy documentation
  install -d "$pkgdir/usr/src/linux-$compver"
  cp -r Documentation "$pkgdir/usr/src/linux-$compver"

  # copy headers
  copy_headers
Seblu's avatar
Seblu committed

  # check rights
  chown -R root.root "$pkgdir/usr/src/linux-$compver"
  chmod -R u=rwX,go=rX "$pkgdir/usr/src/linux-$compver"

  # gzip -9 all modules to safe 100MB of space
  find "$pkgdir" -name '*.ko' -exec gzip -9 {} \;
}

copy_headers() {
Seblu's avatar
up  
Seblu committed
  # create build symlink into /usr/lib/modules
Seblu's avatar
Seblu committed
  ln -sf ../../../src/linux-$compver "$pkgdir/usr/lib/modules/$compver/build"
Seblu's avatar
up  
Seblu committed

  # Copy kernel config files
Seblu's avatar
Seblu committed
  cd "$srcdir/linux-$kernelbase"
  install -D -m644 Makefile "$pkgdir/usr/src/linux-$compver/Makefile"
  install -D -m644 kernel/Makefile "$pkgdir/usr/src/linux-$compver/kernel/Makefile"
  install -D -m644 .config "$pkgdir/usr/src/linux-$compver/.config"
  for i in localversion*; do
    install -m644 "$i" "$pkgdir/usr/src/linux-$compver/$i"
  done
Seblu's avatar
up  
Seblu committed

  # create include directory
  install -d "$pkgdir/usr/src/linux-$compver/include"

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

  # copy arch includes for external modules
  install -d "$pkgdir/usr/src/linux-$compver/arch/x86"
  cp -a arch/x86/include "$pkgdir/usr/src/linux-$compver/arch/x86/"

  # copy files necessary for later builds, like nvidia and vmware
  cp Module.symvers "$pkgdir/usr/src/linux-$compver"
  cp -a scripts "$pkgdir/usr/src/linux-$compver"
Seblu's avatar
up  
Seblu committed

  # fix permissions on scripts dir
  chmod og-w -R "$pkgdir/usr/src/linux-$compver/scripts"
  install -d "$pkgdir/usr/src/linux-$compver/.tmp_versions"

  install -d "$pkgdir/usr/src/linux-$compver/arch/x86/kernel"

  cp arch/x86/Makefile "$pkgdir/usr/src/linux-$compver/arch/x86/"
  cp arch/x86/kernel/asm-offsets.s "$pkgdir/usr/src/linux-$compver/arch/x86/kernel/"

  # add headers for lirc package
Seblu's avatar
up  
Seblu committed
  # pci
  for i in bt8xx cx88 saa7134; do
    install -d "$pkgdir/usr/src/linux-$compver/drivers/media/pci/$i"
    cp -a drivers/media/pci/$i/*.h "$pkgdir/usr/src/linux-$compver/drivers/media/pci/$i"
  done
  # usb
  for i in cpia2 em28xx pwc sn9c102; do
    install -d "$pkgdir/usr/src/linux-$compver/drivers/media/usb/$i"
    cp -a drivers/media/usb/$i/*.h "$pkgdir/usr/src/linux-$compver/drivers/media/usb/$i"
  done
  # i2c
  mkdir -p "$pkgdir/usr/src/linux-$compver/drivers/media/i2c"
  cp drivers/media/i2c/*.h  "$pkgdir/usr/src/linux-$compver/drivers/media/i2c/"
  for i in cx25840; do
    install -d "$pkgdir/usr/src/linux-$compver/drivers/media/i2c/$i"
    cp -a drivers/media/i2c/$i/*.h "$pkgdir/usr/src/linux-$compver/drivers/media/i2c/$i"
Seblu's avatar
up  
Seblu committed

  # add docbook makefile
  install -D -m644 Documentation/DocBook/Makefile \
    "$pkgdir/usr/src/linux-$compver/Documentation/DocBook/Makefile"
Seblu's avatar
up  
Seblu committed

  # add dm headers
  install -d "$pkgdir/usr/src/linux-$compver/drivers/md"
  cp drivers/md/*.h  "$pkgdir/usr/src/linux-$compver/drivers/md"
Seblu's avatar
up  
Seblu committed

  # add inotify.h
  install -d "$pkgdir/usr/src/linux-$compver/include/linux"
  cp include/linux/inotify.h "$pkgdir/usr/src/linux-$compver/include/linux/"
Seblu's avatar
up  
Seblu committed

  # add wireless headers
  install -d "$pkgdir/usr/src/linux-$compver/net/mac80211/"
  cp net/mac80211/*.h "$pkgdir/usr/src/linux-$compver/net/mac80211/"
Seblu's avatar
up  
Seblu committed

  # add dvb headers for external modules
  # in reference to:
  # http://bugs.archlinux.org/task/9912
Seblu's avatar
up  
Seblu committed
  install -d "$pkgdir/usr/src/linux-$compver/drivers/media/dvb-core"
  cp drivers/media/dvb-core/*.h "$pkgdir/usr/src/linux-$compver/drivers/media/dvb-core/"

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

  # add dvb headers for http://mcentral.de/hg/~mrec/em28xx-new
  # in reference to:
  # http://bugs.archlinux.org/task/13146
Seblu's avatar
up  
Seblu committed
  install -d "$pkgdir/usr/src/linux-$compver/drivers/media/dvb-frontends/"
  cp drivers/media/dvb-frontends/lgdt330x.h "$pkgdir/usr/src/linux-$compver/drivers/media/dvb-frontends/"
  cp drivers/media/i2c/msp3400-driver.h "$pkgdir/usr/src/linux-$compver/drivers/media/i2c/"

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

  # add xfs and shmem for aufs building
  install -d "$pkgdir/usr/src/linux-$compver/fs/xfs"
  install -d "$pkgdir/usr/src/linux-$compver/mm"
  cp fs/xfs/xfs_sb.h "$pkgdir/usr/src/linux-$compver/fs/xfs/xfs_sb.h"
Seblu's avatar
up  
Seblu committed

  # copy in Kconfig files
Seblu's avatar
Seblu committed
  for i in `find . -name "Kconfig*"`; do
    install -d "$pkgdir/usr/src/linux-$compver"/$(echo $i | sed 's|/Kconfig.*||')
    cp "$i" "$pkgdir/usr/src/linux-$compver/$i"
  done

Seblu's avatar
up  
Seblu committed
  # strip scripts directory
  find "$pkgdir/usr/src/linux-$compver/scripts" -type f -perm -u+w 2>/dev/null | while read binary ; do
    case "$(file -bi "$binary")" in
      *application/x-sharedlib*) # Libraries (.so)
        strip $STRIP_SHARED "$binary";;
      *application/x-archive*) # Libraries (.a)
        strip $STRIP_STATIC "$binary";;
      *application/x-executable*) # Binaries
        strip $STRIP_BINARIES "$binary";;
    esac
  done

  # remove unneeded architectures
Seblu's avatar
up  
Seblu committed
  rm -rf "${pkgdir}"/usr/src/linux-${_kernver}/arch/{alpha,arm,arm26,avr32,blackfin,c6x,cris,frv,h8300,hexagon,ia64,m32r,m68k,m68knommu,mips,microblaze,mn10300,openrisc,parisc,powerpc,ppc,s390,score,sh,sh64,sparc,sparc64,tile,unicore32,um,v850,xtensa}
}

# vim:set ts=2 sw=2 ft=sh et: