git » linux-armlfs.git » main » tree

[main] / PKGBUILD

# ARMv7 ex-multi-platform -> C201 -> ARMLFS
# This also builds a (subset of) the kernel tools (perf, cpupower, tmon, usbip),
# to avoid archiving yet another copy of the kernel
# sources under the name of an another package.

# Original by:
# Maintainer: Kevin Mihelich <kevin@archlinuxarm.org>
# Modified by:
# Maintainer: Urja Rannikko <urjaman@gmail.com>

buildarch=4

# This is the "extension" to the base linux-c201 name -- used in zImage 
# dtb paths too
_xname=

pkgbase=linux-armlfs${_xname}
_srcname=linux-6.15
_kernelname=${pkgbase#linux}
_desc="Veyron Speedy"
pkgver=6.15.8
pkgrel=1
arch=('armv7h')
url="http://www.kernel.org/"
license=('GPL2')
makedepends=('xmlto' 'docbook-xsl' 'kmod' 'inetutils' 'bc' 'git' 'dtc' 'vboot-utils' 'uboot-tools')
options=('!strip')
_buildtools=1
_onlybuildtools=0
source=(
	"https://www.kernel.org/pub/linux/kernel/v${pkgver::1}.x/${_srcname}.tar.xz"
        "https://www.kernel.org/pub/linux/kernel/v${pkgver::1}.x/patch-${pkgver}.xz"
	# Those are good until 9.x (10.x will fail), fix this then :P
	'armlfs.patch'
        'kernel.its'
        'kernel.keyblock'
        'kernel_data_key.vbprivk'
        '60-linux.hook'
        'cpupower.default'
        'cpupower.systemd'
        'cpupower.service'
        'usbipd.service'
        'config')

prepare() {
  cd "${srcdir}/${_srcname}"

  # hack to allow git apply to work on non-git files while in a git directory
  export GIT_DIR=/var/empty

  # add upstream patch
  git apply --whitespace=nowarn ../patch-${pkgver}

  # ARMLFS patchset
  git apply ../armlfs.patch

  unset GIT_DIR
  
  cat "${srcdir}/config" > ./.config

  # Append (if -rc*) or set ${_xname}-${pkgrel} as extraversion
  sed -ri "s/^(EXTRAVERSION =) ?(-rc[^-]*|).*/\1 \2${_xname}-${pkgrel}/" Makefile

  # don't run depmod on 'make install'. We'll do this ourselves in packaging
  sed -i '2iexit 0' scripts/depmod.sh

  # force our perf version
  cat > tools/perf/util/PERF-VERSION-GEN << EOF
#!/bin/sh
echo '#define PERF_VERSION "$pkgver-$pkgrel"' > "\${1:-.}"/PERF-VERSION-FILE
EOF
}

build() {
  cd "${srcdir}/${_srcname}"

  if [ $_onlybuildtools -ne 1 ]; then
  # get kernel version
  make prepare

  # load configuration
  # Configure the kernel. Replace the line below with one of your choice.
  #make menuconfig # CLI menu for configuration
  #make nconfig # new CLI menu for configuration
  #make xconfig # X-based configuration
  if [ -n "$_menuconfig" ]; then
    make menuconfig # CLI menu for configuration
    cp ./.config ../../config
  else
    make olddefconfig
  fi

  # ... or manually edit .config

  ####################
  # stop here
  # this is useful to configure the kernel
  #msg "Stopping build"
  #return 1
  ####################

  #yes "" | make config

  # build!
  make -j2 ${MAKEFLAGS} zImage modules dtbs
  # if $_onlybuildtools 
  fi 

  # skip tools build:
  if [ $_buildtools -ne 1 ]; then
    return 0
  fi

  echo ':: perf'
  pushd tools/perf
  make -f Makefile.perf \
    prefix=/usr \
    lib=lib/perf \
    perfexecdir=lib/perf \
    WERROR=0 \
    NO_SDT=1 \
    BUILD_BPF_SKEL=0 \
    PYTHON=python \
    NO_LIBLLVM=1 \
    NO_LIBNUMA=1 \
    NO_LIBBPF=1 \
    PYTHON_CONFIG=python3-config \
    LIBPFM4=1 \
    DESTDIR="$pkgdir"
  popd

  echo ':: cpupower'
  pushd tools/power/cpupower
  sed -i 's/-lpci//g' Makefile
  make VERSION=$pkgver-$pkgrel
  popd

  echo ':: usbip'
  pushd tools/usb/usbip
  # Fix gcc compilation
  sed -i 's,-Wall -Werror -Wextra,-fcommon,' configure.ac
  ./autogen.sh
  ./configure --prefix=/usr
  make
  popd

  echo ':: tmon'
  pushd tools/thermal/tmon
  make
  popd
}

_package() {
  pkgdesc="The Linux Kernel and modules - ${_desc}"
  depends=('coreutils' 'linux-firmware' 'kmod' 'mkinitcpio>=0.7')
  optdepends=('crda: to set the correct wireless channels of your country')
  provides=('kernel26' "linux=${pkgver}")

  cd "${srcdir}/${_srcname}"

  KARCH=arm

  # get kernel version
  _kernver="$(make kernelrelease)"
  _basekernel=${_kernver%%-*}
  _basekernel=${_basekernel%.*}

  mkdir -p "${pkgdir}"/{boot,usr/lib/modules}
  make INSTALL_MOD_PATH="${pkgdir}/usr" modules_install
  make INSTALL_DTBS_PATH="${pkgdir}/boot/dtbs${_xname}" dtbs_install
  cp arch/$KARCH/boot/zImage "${pkgdir}/boot/zImage${_xname}"

  # make room for external modules
  local _extramodules="extramodules-${_basekernel}${_kernelname}"
  ln -s "../${_extramodules}" "${pkgdir}/usr/lib/modules/${_kernver}/extramodules"

  # add real version for building modules and running depmod from hook
  echo "${_kernver}" |
    install -Dm644 /dev/stdin "${pkgdir}/usr/lib/modules/${_extramodules}/version"

  # remove build link
  rm "${pkgdir}"/usr/lib/modules/${_kernver}/build

  # now we call depmod...
  depmod -b "${pkgdir}/usr" -F System.map "${_kernver}"

  # sed expression for following substitutions
  local _subst="
    s|%PKGBASE%|${pkgbase}|g
    s|%KERNVER%|${_kernver}|g
    s|%EXTRAMODULES%|${_extramodules}|g
  "

  # install pacman hooks
  sed "${_subst}" ../60-linux.hook |
    install -Dm644 /dev/stdin "${pkgdir}/usr/share/libalpm/hooks/60-${pkgbase}.hook"
}

_package-chromebook() {
  pkgdesc="The Linux Kernel - ${_desc} - Chromebooks"
  depends=("linux-armlfs${_xname}")
  install=chromebook.install

  cd "${srcdir}/${_srcname}"

  cp ../kernel.its .
  mkimage -D "-I dts -O dtb -p 2048" -f kernel.its vmlinux.uimg || true
  dd if=/dev/zero of=bootloader.bin bs=512 count=1
  echo 'console=ttyS2,115200n8 console=tty0 init=/sbin/init root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd' > cmdline
  vbutil_kernel \
    --pack vmlinux.kpart \
    --version 1 \
    --vmlinuz vmlinux.uimg \
    --arch arm \
    --keyblock ../kernel.keyblock \
    --signprivate ../kernel_data_key.vbprivk \
    --config cmdline \
    --bootloader bootloader.bin

  mkdir -p "${pkgdir}/boot"
  cp vmlinux.kpart "${pkgdir}/boot"
}

if [ $_onlybuildtools -ne 1 ]; then
pkgname=("${pkgbase}" "${pkgbase}-chromebook")
for _p in ${pkgname[@]}; do
  eval "package_${_p}() {
    _package${_p#${pkgbase}}
  }"
done
fi

if [ $_buildtools -eq 1 ]; then
pkgname+=(
  'cpupower'
  'perf'
  'tmon'
  'usbip'
)

# perf deps
makedepends+=('perl' 'python' 'python-setuptools' 'slang' 'elfutils' 'libunwind'
     'zstd' 'libcap' 'libtraceevent' 'openssl' 'libpfm')
#   'audit' 'zstd' 'libcap' 'libtraceevent' 'openssl' 'clang' 'llvm-libs' 'libpfm')
# cpupower deps (none for arm)
# usbip deps
makedepends+=('glib2' 'sysfsutils')
# tmon deps
makedepends+=('ncurses')

# if _buildtools
fi

package_perf() {
  pkgdesc='Linux kernel performance auditing tool'
  depends=('glibc' 'perl' 'python' 'slang' 'elfutils' 'libunwind' 'binutils'
            'coreutils' 'glib2' 'xz' 'zlib' 'libelf' 'bash'
           'zstd' 'libcap' 'libtraceevent' 'openssl' 'libsframe.so' 'libpfm')
  groups=('linux-tools')

  cd ${_srcname}/tools/perf
  make -f Makefile.perf \
    prefix=/usr \
    lib=lib/perf \
    perfexecdir=lib/perf \
    EXTRA_CFLAGS=' -Wno-error=bad-function-cast -Wno-error=declaration-after-statement -Wno-error=switch-enum' \
    NO_SDT=1 \
    BUILD_BPF_SKEL=0 \
    PYTHON=python \
    NO_LIBLLVM=1 \
    NO_LIBNUMA=1 \
    NO_LIBBPF=1 \
    PYTHON_CONFIG=python3-config \
    DESTDIR="$pkgdir" \
    LIBPFM4=1 \
    install install-python_ext
  cd "$pkgdir"
  # add linker search path
  mkdir "$pkgdir/etc/ld.so.conf.d"
  echo '/usr/lib/perf' > "$pkgdir/etc/ld.so.conf.d/$pkgname.conf"
  # move completion in new directory
  install -Dm644 etc/bash_completion.d/perf usr/share/bash-completion/completions/perf
  rm -r etc/bash_completion.d
  # no exec on usr/share
  find usr/share -type f -exec chmod a-x {} \;
}

package_cpupower() {
  pkgdesc='Linux kernel tool to examine and tune power saving related features of your processor'
  backup=('etc/default/cpupower')
  depends=('glibc' 'bash')
  conflicts=('cpufrequtils')
  replaces=('cpufrequtils')
  groups=('linux-tools')

  pushd ${_srcname}/tools/power/cpupower
  make \
    DESTDIR="$pkgdir" \
    sbindir='/usr/bin' \
    libdir='/usr/lib' \
    mandir='/usr/share/man' \
    docdir='/usr/share/doc/cpupower' \
    install install-man
  popd
  # install startup scripts
  install -Dm 644 $pkgname.default "$pkgdir/etc/default/$pkgname"
  install -Dm 644 $pkgname.service "$pkgdir/usr/lib/systemd/system/$pkgname.service"
  install -Dm 755 $pkgname.systemd "$pkgdir/usr/lib/systemd/scripts/$pkgname"
}

package_usbip() {
  pkgdesc='An USB device sharing system over IP network'
  depends=('glibc' 'glib2' 'sysfsutils' 'systemd')
  groups=('linux-tools')

  pushd ${_srcname}/tools/usb/usbip
  make install DESTDIR="$pkgdir"
  popd
  # module loading
  install -Dm 644 /dev/null "$pkgdir/usr/lib/modules-load.d/$pkgname.conf"
  printf 'usbip-core\nusbip-host\n' > "$pkgdir/usr/lib/modules-load.d/$pkgname.conf"
  # systemd
  install -Dm 644 usbipd.service "$pkgdir/usr/lib/systemd/system/usbipd.service"
}

package_tmon() {
  pkgdesc='Monitoring and Testing Tool for Linux kernel thermal subsystem'
  depends=('glibc' 'ncurses')
  groups=('linux-tools')

  cd ${_srcname}/tools/thermal/tmon
  make install INSTALL_ROOT="$pkgdir"
}


sha256sums=('7586962547803be7ecc4056efc927fb25214548722bd28171172f3599abb9764'
            'effa3deecc0266054731349ecabb68455f125c7be2f88fd21a841080fd30a4c8'
            '5ff44c1b375131c544c67abb72558009b1f772dff0720e82f010712f7af90a52'
            '994aee74b13313bdc7c47df4d621c890f5ee52bc18f6c7b658de215c17423b2a'
            '4e708c9ec43ac4a5d718474c9431ba6b6da3e64a9dda6afd2853a9e9e3079ffb'
            'bc9e707a86e55a93f423e7bcdae4a25fd470b868e53829b91bbe2ccfbc6da27b'
            'ae2e95db94ef7176207c690224169594d49445e04249d2499e9d2fbc117a0b21'
            '4fa509949d6863d001075fa3e8671eff2599c046d20c98bb4a70778595cd1c3f'
            'b692f4859ed3fd9831a058a450a84d8c409bf7e3e45aac1c2896a14bb83f3d7a'
            '42d2ec9f1d9cc255ee7945a27301478364ef482f5a6ddfc960189f03725ccec2'
            '8053a6bcd0776a7fefccc5012f93a1710653529e0eab59afcc39f24361c64869'
            '91b60d81760bf349abc4fcc8e7660269ed5fc996a636a1b88b5328256b5c6772')