0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ArchLinux kernel build(kernel-5.15.2, and with clang/LLVM)

Last updated at Posted at 2021-11-13

Arch Linux kernel build

cd ~/
mkdir build
cd build/
ASPROOT=. asp checkout linux
ASPROOT=. asp checkout linux-zen
cd linux/repos/core-x86_64
makepkg -s

PKGBUILDの差分

diff --git a/repos/core-x86_64/PKGBUILD b/repos/core-x86_64/PKGBUILD
index 16ff3af..f1179cf 100644
--- a/repos/core-x86_64/PKGBUILD
+++ b/repos/core-x86_64/PKGBUILD
@@ -1,7 +1,7 @@
 # Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
 
-pkgbase=linux
-pkgver=5.14.16.arch1
+pkgbase=linux-custom
+pkgver=5.15.2.arch1
 pkgrel=1
 pkgdesc='Linux'
 _srctag=v${pkgver%.*}-${pkgver##*.}
@@ -16,7 +16,8 @@ makedepends=(
 options=('!strip')
 _srcname=archlinux-linux
 source=(
-  "$_srcname::git+https://github.com/archlinux/linux?signed#tag=$_srctag"
+  "$_srcname.tar.xz::https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-${pkgver%.*}.tar.xz"
+
   config         # the main kernel config file
 )
 validpgpkeys=(
@@ -33,6 +34,7 @@ export KBUILD_BUILD_USER=$pkgbase
 export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
 
 prepare() {
+  mv linux-${pkgver%.*} $_srcname
   cd $_srcname
 
   echo "Setting version..."
@@ -54,6 +56,9 @@ prepare() {
   make olddefconfig
   diff -u ../config .config || :
 
+  #lsmod > `pwd`/lsmod.txt && make LSMOD=`pwd`/lsmod.txt localmodconfig
+
+  make menuconfig
   make -s kernelrelease > version
   echo "Prepared $pkgbase version $(<version)"
 }
@@ -192,7 +197,7 @@ _package-docs() {
   ln -sr "$builddir/Documentation" "$pkgdir/usr/share/doc/$pkgbase"
 }
 
-pkgname=("$pkgbase" "$pkgbase-headers" "$pkgbase-docs")
+pkgname=("$pkgbase" "$pkgbase-headers")
 for _p in "${pkgname[@]}"; do
   eval "package_$_p() {
     $(declare -f "_package${_p#$pkgbase}")

Arch Linux kernel build with clang/LLVM

sudo pacman -S clang llvm lld
diff --git a/repos/core-x86_64/PKGBUILD b/repos/core-x86_64/PKGBUILD
index 16ff3af..a3b6754 100644
--- a/repos/core-x86_64/PKGBUILD
+++ b/repos/core-x86_64/PKGBUILD
@@ -1,7 +1,7 @@
 # Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
 
-pkgbase=linux
-pkgver=5.14.16.arch1
+pkgbase=linux-custom
+pkgver=5.15.2.arch1
 pkgrel=1
 pkgdesc='Linux'
 _srctag=v${pkgver%.*}-${pkgver##*.}
@@ -16,7 +16,8 @@ makedepends=(
 options=('!strip')
 _srcname=archlinux-linux
 source=(
-  "$_srcname::git+https://github.com/archlinux/linux?signed#tag=$_srctag"
+  "$_srcname.tar.xz::https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-${pkgver%.*}.tar.xz"
+
   config         # the main kernel config file
 )
 validpgpkeys=(
@@ -32,7 +33,14 @@ export KBUILD_BUILD_HOST=archlinux
 export KBUILD_BUILD_USER=$pkgbase
 export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
 
+export set LLVM=1
+export set LLVM_IAS=1
+export set CC=clang
+export set CXX=clang++
+export set LD=ld.lld
+
 prepare() {
+  mv linux-${pkgver%.*} $_srcname
   cd $_srcname
 
   echo "Setting version..."
@@ -54,6 +62,9 @@ prepare() {
   make olddefconfig
   diff -u ../config .config || :
 
+  #lsmod > `pwd`/lsmod.txt && make LSMOD=`pwd`/lsmod.txt localmodconfig
+
+  make menuconfig
   make -s kernelrelease > version
   echo "Prepared $pkgbase version $(<version)"
 }
@@ -61,7 +72,6 @@ prepare() {
 build() {
   cd $_srcname
   make all
-  make htmldocs
 }
 
 _package() {
@@ -192,7 +202,7 @@ _package-docs() {
   ln -sr "$builddir/Documentation" "$pkgdir/usr/share/doc/$pkgbase"
 }
 
-pkgname=("$pkgbase" "$pkgbase-headers" "$pkgbase-docs")
+pkgname=("$pkgbase" "$pkgbase-headers")
 for _p in "${pkgname[@]}"; do
   eval "package_$_p() {
     $(declare -f "_package${_p#$pkgbase}")

DKMS:Support CC=clang and LD=ld.lld
上記の修正を取り込む。clang,lldでビルドしたカーネルの場合、dkmsでカーネルモジュールをコンパイルする場合、clang,lldを用いる。

dkms-3.0.1

diff --git a/dkms.in b/dkms.in
index 9c98a89..ce213e1 100644
--- a/dkms.in
+++ b/dkms.in
@@ -575,6 +575,23 @@ read_conf()
     [[ ! $make_command ]] && make_command="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build"
     [[ ! $clean ]] && clean="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build clean"
 
+    # Check if clang was used to compile or lld was used to link the kernel.
+    if [[ -e $kernel_source_dir/vmlinux ]]; then
+      if  readelf -p .comment $kernel_source_dir/vmlinux | grep -q clang; then
+        make_command="${make_command} CC=clang"
+      fi
+      if  readelf -p .comment $kernel_source_dir/vmlinux | grep -q LLD; then
+        make_command="${make_command} LD=ld.lld"
+      fi
+    elif [[ -e $kernel_source_dir/.config ]]; then
+      if grep -q CONFIG_CC_IS_CLANG=y $kernel_source_dir/.config; then
+        make_command="${make_command} CC=clang"
+      fi
+      if grep -q CONFIG_LD_IS_LLD=y $kernel_source_dir/.config; then
+        make_command="${make_command} LD=ld.lld"
+      fi
+    fi
+
     # Set patch_array (including kernel specific patches)
     count=0
     for ((index=0; index < ${#PATCH[@]}; index++)); do

kernel-zen

cd ~/build/linux-zen/repos/extra-x86_64/
makepkg -s
diff --git a/repos/extra-x86_64/PKGBUILD b/repos/extra-x86_64/PKGBUILD
index 7d08335..94a479b 100644
--- a/repos/extra-x86_64/PKGBUILD
+++ b/repos/extra-x86_64/PKGBUILD
@@ -1,6 +1,6 @@
 # Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
 
-pkgbase=linux-zen
+pkgbase=linux-zen-custom
 pkgver=5.15.2.zen1
 pkgrel=1
 pkgdesc='Linux ZEN'
@@ -16,7 +16,7 @@ makedepends=(
 options=('!strip')
 _srcname=zen-kernel
 source=(
-  "$_srcname::git+https://github.com/zen-kernel/zen-kernel?signed#tag=$_srctag"
+  "$_srcname.tar.gz::https://github.com/zen-kernel/zen-kernel/archive/refs/tags/$_srctag.tar.gz"
   config         # the main kernel config file
 )
 validpgpkeys=(
@@ -32,7 +32,11 @@ export KBUILD_BUILD_HOST=archlinux
 export KBUILD_BUILD_USER=$pkgbase
 export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
 
+export set LLVM=1
+export set LLVM_IAS=1
+
 prepare() {
+  mv $_srcname-${pkgver%.*}-${pkgver##*.} $_srcname
   cd $_srcname
 
   echo "Setting version..."
@@ -53,6 +57,7 @@ prepare() {
   cp ../config .config
   make olddefconfig
   diff -u ../config .config || :
+  make menuconfig
 
   make -s kernelrelease > version
   echo "Prepared $pkgbase version $(<version)"

参考サイト
カーネル/コンパイル/Arch_Build_System

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?