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

**Arch Linux kernel build**

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

PKGBUILDの差分

```diff
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**


```sh
sudo pacman -S clang llvm lld
```

```diff
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](https://github.com/dell/dkms/pull/169/commits/6ddb09145930b03c88e63f5930e718a33501024d)
上記の修正を取り込む。clang,lldでビルドしたカーネルの場合、dkmsでカーネルモジュールをコンパイルする場合、clang,lldを用いる。

**dkms-3.0.1**

```diff
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**

```sh
cd ~/build/linux-zen/repos/extra-x86_64/
makepkg -s
```

```diff
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](https://wiki.archlinux.jp/index.php/%E3%82%AB%E3%83%BC%E3%83%8D%E3%83%AB/%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%AB/Arch_Build_System)