2019-11-23 16:20:23 -05:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
## package name
|
|
|
|
custom_name=linux-lts-native
|
|
|
|
|
|
|
|
## gcc optimization parameters
|
2024-02-25 10:56:09 -05:00
|
|
|
gcc_patch_version=20240221.2
|
|
|
|
#gcc_patch_filename="more-uarches-for-kernel-5.15+.patch"
|
|
|
|
gcc_patch_filename="more-uarches-for-kernel-6.1.79-6.8-rc3.patch"
|
2019-11-23 16:20:23 -05:00
|
|
|
|
2021-08-01 10:53:09 -04:00
|
|
|
gcc_patch_src='enable_additional_cpu_optimizations-$_gcc_more_v.tar.gz::https://github.com\/graysky2/kernel_compiler_patch/archive/$_gcc_more_v.tar.gz'
|
2019-11-23 16:20:23 -05:00
|
|
|
gcc_patch_msg='msg "Applying Additional GCC Optimizations Patch"'
|
2021-08-01 10:53:09 -04:00
|
|
|
gcc_patch_apply="patch -Np1 -i \"\$srcdir/kernel_compiler_patch-\$_gcc_more_v/$gcc_patch_filename\""
|
2019-11-23 16:20:23 -05:00
|
|
|
|
2023-06-11 14:45:53 -04:00
|
|
|
repo_dir=src
|
2019-11-23 16:20:23 -05:00
|
|
|
build_dir=.build
|
|
|
|
build_file="$build_dir/PKGBUILD"
|
|
|
|
hist_dir=config-history
|
2021-02-14 10:34:50 -05:00
|
|
|
makepkg_dir=$(sed -n 's/^BUILDDIR=\(.*\)/\1/p' /etc/makepkg.conf)
|
2019-11-23 16:20:23 -05:00
|
|
|
|
|
|
|
help="$(basename "$0") [-o] [-c] [-h]
|
|
|
|
|
|
|
|
Natively builds the latest version of the linux-lts kernel with
|
|
|
|
graysky's GCC patch and my own config.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-o: use current package build files regardless of newer versions
|
|
|
|
-c: launch make nconfig during build
|
|
|
|
-h: show this"
|
|
|
|
|
|
|
|
get_latest_config() {
|
|
|
|
echo "$hist_dir/$(ls -Art "$hist_dir" | tail -n 1)"
|
|
|
|
}
|
|
|
|
|
|
|
|
back_up_config() {
|
|
|
|
# pull old config if it exists and is not the most recent
|
|
|
|
if [ -e "$build_file" ]; then
|
|
|
|
echo "checking for old config file"
|
|
|
|
|
|
|
|
source "$build_file" # get pkgver
|
2021-02-14 10:34:50 -05:00
|
|
|
|
|
|
|
# copy from the tmp dir if this is what makepkg is configured to do
|
|
|
|
if [[ "$makepkg_dir" == "" ]]; then
|
|
|
|
oldconf="$build_dir/src/linux-$pkgver/.config"
|
|
|
|
else
|
|
|
|
oldconf="$makepkg_dir/linux-lts-native/src/linux-$pkgver/.config"
|
|
|
|
fi
|
2019-11-23 16:20:23 -05:00
|
|
|
|
|
|
|
if [ -e "$oldconf" ]; then
|
|
|
|
echo "found old config"
|
|
|
|
|
|
|
|
oldsum=$(md5sum "$oldconf" | awk '{print $1}')
|
|
|
|
newsum=$(md5sum "$(get_latest_config)" | awk '{print $1}')
|
|
|
|
|
|
|
|
if [ "$oldsum" != "$newsum" ]; then
|
|
|
|
echo "copying old config to $hist_dir"
|
|
|
|
cp "$oldconf" "$hist_dir/.config-$(date +%Y%m%d%H%M)"
|
|
|
|
else
|
|
|
|
echo "config file up to date. nothing to back up"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
update_build() {
|
|
|
|
if [ -z "$old_build" ]; then
|
|
|
|
## update repo tree
|
2023-06-11 14:45:53 -04:00
|
|
|
if [ ! -e src ]; then
|
|
|
|
echo Retrieving linux-lts source
|
|
|
|
git clone https://gitlab.archlinux.org/archlinux/packaging/packages/linux-lts.git src
|
2019-11-23 16:20:23 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
## update linux-lts repo
|
2023-06-11 14:45:53 -04:00
|
|
|
echo Updating linux-lts source
|
|
|
|
cd src || exit
|
2023-09-12 10:23:43 -04:00
|
|
|
git pull
|
2019-11-23 16:20:23 -05:00
|
|
|
cd ..
|
|
|
|
|
|
|
|
rm -rf $build_dir
|
|
|
|
cp -r "$repo_dir" "$build_dir"
|
|
|
|
|
|
|
|
## copy new config
|
|
|
|
latest_conf=$(get_latest_config)
|
|
|
|
echo "copying conf: $latest_conf"
|
|
|
|
cp "$latest_conf" "$build_dir/config"
|
|
|
|
|
|
|
|
## use "make nconfig" if we ask for it (see sed cmd below)
|
|
|
|
if [ -n "$do_config" ]; then
|
|
|
|
make_config_cmds="make oldconfig\n make nconfig"
|
|
|
|
else
|
|
|
|
make_config_cmds="make oldconfig"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## if "security patches is not found in prepare(), warn user
|
|
|
|
## that the GCC patch won't be applied
|
|
|
|
if ! grep 'Setting version...' "$build_file" > /dev/null; then
|
|
|
|
echo "GCC patch not applied!!!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
## modify the PKGBUILD
|
2023-09-12 10:23:43 -04:00
|
|
|
## - remove unnecessary makedeps
|
2019-11-23 16:20:23 -05:00
|
|
|
## - change package name
|
|
|
|
## - change kernelname
|
|
|
|
## - unindent custom name
|
2024-04-21 12:09:53 -04:00
|
|
|
## - remove htmldocs make steps (started in 'build' function to speed up package building)
|
2019-11-23 16:20:23 -05:00
|
|
|
## - add gcc path version variable
|
|
|
|
## - add gcc path to sources
|
|
|
|
## - add gcc patch command in prepare
|
|
|
|
## - add make config commands
|
|
|
|
## - delete docs build command
|
|
|
|
## - delete package-docs
|
|
|
|
## - remove package-docs from pkgname
|
2023-09-12 10:23:43 -04:00
|
|
|
sed -i -z 's/makedepends=([^()]\+)/makedepends=(libelf cpio tar xz)/' \
|
|
|
|
"$build_file"
|
2019-11-23 16:20:23 -05:00
|
|
|
sed -i -e "s/pkgbase=.*/pkgbase=$custom_name/g" \
|
2024-04-21 12:09:53 -04:00
|
|
|
-e '/make htmldocs &/d' \
|
|
|
|
-e '/local pid_docs=\$!/d' \
|
|
|
|
-e '/wait \"\${pid_docs\}\"/d' \
|
2019-11-23 16:20:23 -05:00
|
|
|
-e "/^pkgrel=.*/a _gcc_more_v=\'$gcc_patch_version\'" \
|
|
|
|
-e "s|source=(|source=($gcc_patch_src\n |" \
|
|
|
|
-e "/localversion\.20-pkgname/d" \
|
|
|
|
-e "/Setting version\.\.\./i \ \ $gcc_patch_msg\n\ \ $gcc_patch_apply\n" \
|
|
|
|
-e "/^\s*make olddefconfig/a \ \ $make_config_cmds" \
|
|
|
|
-e "s/\s*htmldocs//" \
|
|
|
|
-e '/^_package-docs()\ {/,/^}/d' \
|
|
|
|
-e 's/\s*"$pkgbase-docs"//' \
|
|
|
|
"$build_file"
|
2023-09-12 10:23:43 -04:00
|
|
|
## remove btfid thingy
|
|
|
|
sed -i '/resolve_btfids/d' "$build_file"
|
|
|
|
# TEMPORARILY DISABLE THE GCC PATCH
|
2021-08-01 10:53:09 -04:00
|
|
|
#sed -i -e "s/pkgbase=.*/pkgbase=$custom_name/g" \
|
|
|
|
# -e "/localversion\.20-pkgname/d" \
|
|
|
|
# -e "/^\s*make olddefconfig/a \ \ $make_config_cmds" \
|
|
|
|
# -e "s/\s*htmldocs//" \
|
|
|
|
# -e '/^_package-docs()\ {/,/^}/d' \
|
|
|
|
# -e 's/\s*"$pkgbase-docs"//' \
|
|
|
|
# "$build_file"
|
2019-11-23 16:20:23 -05:00
|
|
|
|
|
|
|
updpkgsums "$build_file"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts ":och" OPT; do
|
|
|
|
case ${OPT} in
|
|
|
|
o)
|
|
|
|
old_build="true"
|
|
|
|
;;
|
|
|
|
c)
|
|
|
|
do_config="true"
|
|
|
|
;;
|
|
|
|
h)
|
|
|
|
echo "$help"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
\?)
|
|
|
|
echo "$help"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
update_build
|
|
|
|
|
|
|
|
cd "$build_dir" || exit
|
2024-04-21 12:09:53 -04:00
|
|
|
makepkg -s -r -f -i -L
|
2019-11-23 16:20:23 -05:00
|
|
|
cd ..
|
|
|
|
|
2021-02-14 10:34:50 -05:00
|
|
|
back_up_config
|