Skip to content

Commit c13d9fe

Browse files
committed
Add PKGBUILD
Signed-off-by: KenHV <[email protected]>
1 parent c649c8e commit c13d9fe

File tree

1 file changed

+202
-0
lines changed

1 file changed

+202
-0
lines changed

PKGBUILD

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Maintainer: Jan Alexander Steffens (heftig) <[email protected]>
2+
# Maintainer: KenHV <[email protected]>
3+
4+
pkgbase=linux-kensur
5+
pkgver=5.19.7.kensur1
6+
pkgrel=1
7+
pkgdesc='Linux'
8+
_srctag=v${pkgver%.*}-${pkgver##*.}
9+
arch=(x86_64)
10+
license=(GPL2)
11+
makedepends=(
12+
bc libelf pahole cpio perl tar xz
13+
)
14+
15+
options=('!strip')
16+
17+
export KBUILD_BUILD_HOST=archlinux
18+
export KBUILD_BUILD_USER=$pkgbase
19+
export KBUILD_BUILD_TIMESTAMP="$(date -Ru${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"
20+
21+
[ -z ${personal+x} ] && personal=n
22+
[ -z ${ci+x} ] && ci=n
23+
[ -z ${lto+x} ] && lto=n
24+
[ -z ${ccache+x} ] && ccache=n
25+
[ -z ${clean+x} ] && clean=n
26+
27+
prepare() {
28+
cd ..
29+
30+
echo "Setting config..."
31+
make kensur_defconfig
32+
33+
if [ "$ci" = "n" ]; then
34+
vendor=$(lscpu | awk '/Vendor ID/{print $3}')
35+
if [[ "$vendor" == "GenuineIntel" || "$vendor" == "AuthenticAMD" ]]; then
36+
echo "CPU: $(lscpu | awk '/Model name/{ print substr($0, index($0,$3)) }')"
37+
echo "Applying optimizations..."
38+
scripts/config -d GENERIC_CPU
39+
scripts/config --set-val NR_CPUS $(nproc --all)
40+
scripts/config --set-val VGA_ARB_MAX_GPUS $(lspci | grep -E "VGA|3D" | wc -l)
41+
42+
if [[ "$vendor" == "GenuineIntel" ]]; then
43+
scripts/config -e MNATIVE_INTEL
44+
elif [[ "$vendor" == "AuthenticAMD" ]]; then
45+
scripts/config -e MNATIVE_AMD
46+
fi
47+
fi
48+
fi
49+
50+
if [ "$personal" = "y" ]; then
51+
echo "Applying personal config..."
52+
scripts/config -d DRM_AMDGPU
53+
scripts/config -d DRM_NOUVEAU
54+
scripts/config -d DRM_RADEON
55+
scripts/config -d GENERIC_CPU
56+
scripts/config -e MSKYLAKE
57+
scripts/config --set-val NR_CPUS 8
58+
scripts/config --set-val VGA_ARB_MAX_GPUS 2
59+
fi
60+
61+
if [ "$lto" = "y" ]; then
62+
echo "Enabling Clang Full LTO..."
63+
scripts/config -e LTO_CLANG_FULL
64+
fi
65+
66+
if [ "$clean" = "y" ]; then
67+
echo "Clearing ccache..."
68+
rm -rf /tmp/ccache/*
69+
fi
70+
71+
make -s kernelrelease > version
72+
echo "Prepared $pkgbase version $(<version)"
73+
}
74+
75+
build() {
76+
cd ..
77+
if [ "$ccache" = "y" ]; then
78+
env PATH="/usr/lib/ccache/bin:${PATH}" make all -j$(nproc --all)
79+
else
80+
make all -j$(nproc --all)
81+
fi
82+
}
83+
84+
_package() {
85+
pkgdesc="The $pkgdesc kernel and modules"
86+
depends=(coreutils kmod initramfs)
87+
optdepends=('wireless-regdb: to set the correct wireless channels of your country'
88+
'linux-firmware: firmware images needed for some devices')
89+
provides=(VIRTUALBOX-GUEST-MODULES WIREGUARD-MODULE KSMBD-MODULE)
90+
replaces=(virtualbox-guest-modules-arch wireguard-arch)
91+
92+
cd ..
93+
local kernver="$(<version)"
94+
local modulesdir="$pkgdir/usr/lib/modules/$kernver"
95+
96+
echo "Installing boot image..."
97+
# systemd expects to find the kernel here to allow hibernation
98+
# https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
99+
install -Dm644 "$(make -s image_name)" "$modulesdir/vmlinuz"
100+
101+
# Used by mkinitcpio to name the kernel
102+
echo "$pkgbase" | install -Dm644 /dev/stdin "$modulesdir/pkgbase"
103+
104+
echo "Installing modules..."
105+
make INSTALL_MOD_PATH="$pkgdir/usr" INSTALL_MOD_STRIP=1 \
106+
DEPMOD=/doesnt/exist modules_install # Suppress depmod
107+
108+
# remove build and source links
109+
rm "$modulesdir"/{source,build}
110+
}
111+
112+
_package-headers() {
113+
pkgdesc="Headers and scripts for building modules for the $pkgdesc kernel"
114+
depends=(pahole)
115+
116+
cd ..
117+
local builddir="$pkgdir/usr/lib/modules/$(<version)/build"
118+
119+
echo "Installing build files..."
120+
install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map \
121+
version vmlinux
122+
install -Dt "$builddir/kernel" -m644 kernel/Makefile
123+
install -Dt "$builddir/arch/x86" -m644 arch/x86/Makefile
124+
cp -t "$builddir" -a scripts
125+
126+
# required when STACK_VALIDATION is enabled
127+
install -Dt "$builddir/tools/objtool" tools/objtool/objtool
128+
129+
# required when DEBUG_INFO_BTF_MODULES is enabled
130+
#install -Dt "$builddir/tools/bpf/resolve_btfids" tools/bpf/resolve_btfids/resolve_btfids
131+
132+
echo "Installing headers..."
133+
cp -t "$builddir" -a include
134+
cp -t "$builddir/arch/x86" -a arch/x86/include
135+
install -Dt "$builddir/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s
136+
137+
install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h
138+
install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h
139+
140+
# https://bugs.archlinux.org/task/13146
141+
install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h
142+
143+
# https://bugs.archlinux.org/task/20402
144+
install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
145+
install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
146+
install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h
147+
148+
# https://bugs.archlinux.org/task/71392
149+
install -Dt "$builddir/drivers/iio/common/hid-sensors" -m644 drivers/iio/common/hid-sensors/*.h
150+
151+
echo "Installing KConfig files..."
152+
find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \;
153+
154+
echo "Removing unneeded architectures..."
155+
local arch
156+
for arch in "$builddir"/arch/*/; do
157+
[[ $arch = */x86/ ]] && continue
158+
echo "Removing $(basename "$arch")"
159+
rm -r "$arch"
160+
done
161+
162+
echo "Removing documentation..."
163+
rm -r "$builddir/Documentation"
164+
165+
echo "Removing broken symlinks..."
166+
find -L "$builddir" -type l -printf 'Removing %P\n' -delete
167+
168+
echo "Removing loose objects..."
169+
find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete
170+
171+
echo "Stripping build tools..."
172+
local file
173+
while read -rd '' file; do
174+
case "$(file -bi "$file")" in
175+
application/x-sharedlib\;*) # Libraries (.so)
176+
strip -v $STRIP_SHARED "$file" ;;
177+
application/x-archive\;*) # Libraries (.a)
178+
strip -v $STRIP_STATIC "$file" ;;
179+
application/x-executable\;*) # Binaries
180+
strip -v $STRIP_BINARIES "$file" ;;
181+
application/x-pie-executable\;*) # Relocatable binaries
182+
strip -v $STRIP_SHARED "$file" ;;
183+
esac
184+
done < <(find "$builddir" -type f -perm -u+x ! -name vmlinux -print0)
185+
186+
echo "Stripping vmlinux..."
187+
strip -v $STRIP_STATIC "$builddir/vmlinux"
188+
189+
echo "Adding symlink..."
190+
mkdir -p "$pkgdir/usr/src"
191+
ln -sr "$builddir" "$pkgdir/usr/src/$pkgbase"
192+
}
193+
194+
pkgname=("$pkgbase" "$pkgbase-headers")
195+
for _p in "${pkgname[@]}"; do
196+
eval "package_$_p() {
197+
$(declare -f "_package${_p#$pkgbase}")
198+
_package${_p#$pkgbase}
199+
}"
200+
done
201+
202+
# vim:set ts=8 sts=2 sw=2 et:

0 commit comments

Comments
 (0)