--- /dev/null
+# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
+
+source ${LBUILD_DIR}/lbuild-rhel
+
+# increment this if you have made a change that should force a new kernel
+# to build built
+BUILD_GEN+=".0"
+
+SPEC_NAME="kernel.spec"
+DEVEL_PATH_ARCH_DELIMETER="."
+USE_KABI=false
+
+# force local definition of %dist into ~/.rpmmacros
+# to avoid verbose extended strings like ".el8.centos"
+# in kernel version and rpm names
+#
+RMAC=$HOME/.rpmmacros
+grep '^%dist' $RMAC &> /dev/null || echo '%dist .el8' >> $RMAC
+
+# We modify the RHEL8 kmodtool script, because it expects
+# the kernel source to be in the correct packaged RHEL location.
+# lbuild does not put the source in correct packaged RHEL location.
+RHEL_KMODTOOL=/usr/lib/rpm/redhat/kmodtool
+LBUILD_KMODTOOL="${LBUILD_DIR}/rhel8/kmodtool"
+cp $RHEL_KMODTOOL $LBUILD_KMODTOOL
+pushd ${LBUILD_DIR}/rhel8
+patch -p1 < kmodtool.patch
+# Replace the hardcoded /usr/src/kernels with our build path
+tmp="${TOPDIR}/reused/usr/src/kernels"
+tmp="${tmp//\//\\/}"
+sed -i "s/\/usr\/src\/kernels/${tmp}/g" ${LBUILD_DIR}/rhel8/kmodtool
+chmod 755 kmodtool
+popd
+# Next we replace %kernel_module_package with one that is nearly
+# identical, but calls lbuild's modified kmodtool script.
+# We need to cleanout the previous entry
+sed -i "/^%kernel_module_package/,/^)}$/d" $RMAC
+sed -e "s|REPLACE_ME|$LBUILD_KMODTOOL|" -e "s/\/usr\/src\/kernels/${tmp}/g" \
+ ${LBUILD_DIR}/rhel8/rpmmacros.template > ${LBUILD_DIR}/rhel8/rpmmacros
+cat ${LBUILD_DIR}/rhel8/rpmmacros >> $RMAC
+
+patch_spec() {
+ local buildid="$1"
+
+ # the el8 .spec file requires patch names to begin with "patch-3."
+ # so rename the lustre patch from lbuild to one the .spec will like
+ mv $TOPDIR/SOURCES/linux-${lnxmaj}-lustre.patch \
+ $TOPDIR/SOURCES/patch-${lnxmaj}-lustre.patch
+
+ # edit the SPEC with our changes
+ patch_spec_common "$buildid"
+ sed -i -e '/^# empty final patch to facilitate testing of kernel patches/i\
+# adds Lustre patches\
+Patch99995: patch-%{version}-lustre.patch' \
+ -e '/^ApplyOptionalPatch linux-kernel-test.patch/i\
+\
+# lustre patch\
+ApplyOptionalPatch patch-%{version}-lustre.patch\
+' \
+ -e '/rm -f include\/generated\/kernel.cross/i\
+ # lustre kernel config.\
+ if [ -f %{_topdir}/lustre/lustre/kernel_patches/kernel_configs/kernel-%{version}-4.18-rhel8-%{_target_cpu}.config ]; then\
+ echo "# $Arch" > configs/kernel-%{version}-%{_target_cpu}.config\
+ cat %{_topdir}/lustre/lustre/kernel_patches/kernel_configs/kernel-%{version}-4.18-rhel8-%{_target_cpu}.config >> configs/kernel-%{version}-%{_target_cpu}.config\
+ fi'\
+ -e '/^# Dynamically generate kernel/a echo "CONFIG_BH_LRU_SIZE=16" >> config-generic'\
+ -e '/^%define listnewconfig_fail 1/s/1/0/'\
+ SPECS/$SPEC_NAME 2>&1 || \
+ fatal 1 "Error while editing SPECS/$SPEC_NAME"
+
+
+ return 0
+
+}
+
+unpack_linux_devel_rpm-rhel8() {
+ local callers_rpm="$1"
+
+ unpack_linux_devel_rpm-rhel "$callers_rpm"
+
+
+ return 0
+
+}
+
+get_rpmbuildopts() {
+
+ if $KERNEL_LUSTRE_NAMING; then
+ echo -e "--define \"variant -lustre\" \c"
+ fi
+ echo "--with firmware"
+
+ return 0
+
+}
+
+find_linux_rpm-rhel8() {
+ local prefix="$1"
+ local wanted_kernel="$2"
+ local pathtorpms=${3:-"$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH"}
+
+ find_linux_rpm-rhel "$prefix" "$wanted_kernel" "$pathtorpms"
+
+}
+
+kernel_srpm_location() {
+
+ echo "http://vault.centos.org/centos/8/updates/Source/SPackages/"
+
+}
+
+kernel_debuginfo_location() {
+
+ echo "http://debuginfo.centos.org/8/x86_64/"
+
+}
+
+cleanup_rpmmacros() {
+ sed -i "/^%kernel_module_package/,/^)}$/d" $RMAC
+}
+
+apply_kmod_requires_conflicts() {
+ if $PATCHLESS; then
+ # don't allow the patched kernel to be considered as a valid kernel
+ # for the patchless client
+ echo "Conflicts: kernel-lustre" >> rpm/kmp-lustre.preamble
+ fi
+}
--- /dev/null
+lbuild does not install the kernel source in the standard RHEL7 location.
+RHEL's kmodtool (starting in RHEL7) expects the source to be in the standard
+location, and when it fails to find it it adds an extra $arch onto the end
+of verrel. With lbuild, verrel already contains the arch, so we change the
+kmodtool script so that it does not add another.
+
+--- old/kmodtool 2016-06-07 14:36:20.810907740 -0700
++++ new/kmodtool 2016-06-07 14:37:55.335652424 -0700
+@@ -62,7 +62,7 @@ get_kernel_release ()
+ local versuffix=${verrel#$verprefix}
+ verrel=$(ls -Ud /usr/src/kernels/$verprefix*$versuffix.$arch | sort -V | tail -n 1)
+ verrel=${verrel##*/}
+- [[ -z $verrel ]] && verrel=$1.$arch
++ [[ -z $verrel ]] && verrel=$1
+ echo "$verrel"
+ }
+
--- /dev/null
+%kernel_module_package(n:v:r:s:f:xp:) %{expand:%( \
+ %global kmodtool %{-s*}%{!-s:REPLACE_ME} \
+ %global kmod_version %{-v*}%{!-v:%{version}} \
+ %global kmod_release %{-r*}%{!-r:%{release}} \
+ %global latest_kernel %(rpm -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}\\\\n' `rpm -q kernel-devel | /usr/lib/rpm/redhat/rpmsort -r | head -n 1` | head -n 1) \
+ %{!?kernel_version:%{expand:%%global kernel_version %{latest_kernel}}} \
+ %global kverrel %(%{kmodtool} verrel %{?kernel_version} 2>/dev/null) \
+ flavors="default" \
+ if [ -z "%*" ]; then \
+ flavors_to_build=$flavors \
+ elif [ -z "%{-x}" ]; then \
+ flavors_to_build="%*" \
+ else \
+ flavors_to_build=" $flavors "\
+ for i in %* \
+ do \
+ flavors_to_build=${flavors_to_build//$i /}
+ done \
+ fi \
+ echo "%%global flavors_to_build ${flavors_to_build:-%%nil}" \
+ echo "%%global kernel_source() /usr/src/kernels/%kverrel\\\$([ %%%%{1} = default ] || echo ".%%%%{1}")" \
+ echo "%%global kernel_module_package_moddir() extra" \
+ if [ ! -z "%{-f*}" ] \
+ then \
+ filelist="%{-f*}" \
+ fi \
+ if [ ! -z "%{-p*}" ] \
+ then \
+ preamble="%{-p*}" \
+ fi \
+ if [ -z "%{kmodtool_generate_buildreqs}" ] \
+ then \
+ nobuildreqs="yes" \
+ fi \
+ override_filelist="$filelist" override_preamble="$preamble" nobuildreqs="$nobuildreqs" kmod_version=%kmod_version kmod_release=%kmod_release %{kmodtool} rpmtemplate %{-n*}%{!-n:%name} %{kverrel} $flavors_to_build 2>/dev/null \
+)}