# Define the kmod package name here. %define kmod_name mega # If kmod_kernel_version isn't defined on the rpmbuild line, define it here. %{!?kmod_kernel_version: %define kmod_kernel_version 4.18.0-107.el8} %{!?dist: %define dist .el8} Name: kmod-%{kmod_name} Version: 4.18.0.107 Release: 1%{?dist} Summary: %{kmod_name} kernel module(s) Group: System Environment/Kernel License: GPLv2 URL: http://www.kernel.org/ # Sources. Source0: linux-%{kmod_kernel_version}.tar.xz %define findpat %( echo "%""P" ) %define __find_requires /usr/lib/rpm/redhat/find-requires.ksyms %define __find_provides /usr/lib/rpm/redhat/find-provides.ksyms %{kmod_name} %{?epoch:%{epoch}:}%{version}-%{release} %define dup_state_dir %{_localstatedir}/lib/rpm-state/kmod-dups %define kver_state_dir %{dup_state_dir}/kver %define kver_state_file %{kver_state_dir}/%{kmod_kernel_version}.%{_arch} %define dup_module_list %{dup_state_dir}/rpm-kmod-%{kmod_name}-modules %define debug_package %{nil} %global _use_internal_dependency_generator 0 %global kernel_source() %{_usrsrc}/kernels/%{kmod_kernel_version}.%{_arch} BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) ExclusiveArch: x86_64 BuildRequires: elfutils-libelf-devel BuildRequires: kernel-devel = %{kmod_kernel_version} BuildRequires: kernel-abi-whitelists BuildRequires: kernel-rpm-macros BuildRequires: redhat-rpm-config Provides: kernel-modules >= %{kmod_kernel_version}.%{_arch} Provides: kmod-%{kmod_name} = %{?epoch:%{epoch}:}%{version}-%{release} Requires(post): %{_sbindir}/weak-modules Requires(postun): %{_sbindir}/weak-modules Requires: kernel >= %{kmod_kernel_version} %description This package provides the %{kmod_name} kernel module(s). It is built to depend upon the specific ABI provided by a range of releases of the same variant of the Linux kernel and not on any one specific build. %prep %setup -q -n linux-%{kmod_kernel_version} echo "override megaraid_mbox * weak-updates/megaraid_mbox" > kmod-%{kmod_name}.conf echo "override megaraid_mm * weak-updates/megaraid_mm" >> kmod-%{kmod_name}.conf %build %{__make} -C %{kernel_source} modules M="$PWD/drivers/scsi/megaraid" CONFIG_MEGARAID_MM=m CONFIG_MEGARAID_MAILBOX=m whitelist="/lib/modules/kabi-current/kabi_whitelist_%{_target_cpu}" for modules in $( find drivers/scsi/megaraid/ -name "*.ko" -type f -printf "%{findpat}\n" | sed 's|\.ko$||' | sed 's@drivers/scsi/megaraid/@@' | sort -u ) ; do # update greylist nm -u drivers/scsi/megaraid/$modules.ko | sed 's/.*U //' | sed 's/^\.//' | sort -u | while read -r symbol; do grep -q "^\s*$symbol\$" $whitelist || echo "$symbol" >> ./greylist done done sort -u greylist | uniq > greylist.txt %install %{__install} -d %{buildroot}/lib/modules/%{kmod_kernel_version}.%{_arch}/extra/%{kmod_name}/ %{__install} drivers/scsi/megaraid/megaraid_mbox.ko %{buildroot}/lib/modules/%{kmod_kernel_version}.%{_arch}/extra/%{kmod_name}/ %{__install} drivers/scsi/megaraid/megaraid_mm.ko %{buildroot}/lib/modules/%{kmod_kernel_version}.%{_arch}/extra/%{kmod_name}/ %{__install} -d %{buildroot}%{_sysconfdir}/depmod.d/ %{__install} -m 0644 kmod-%{kmod_name}.conf %{buildroot}%{_sysconfdir}/depmod.d/ %{__install} -d %{buildroot}%{_defaultdocdir}/kmod-%{kmod_name}-%{version}/ %{__install} -m 0644 greylist.txt %{buildroot}%{_defaultdocdir}/kmod-%{kmod_name}-%{version}/ # strip the modules(s) find %{buildroot} -type f -name \*.ko -exec %{__strip} --strip-debug \{\} \; %clean %{__rm} -rf %{buildroot} %post modules=( $(find /lib/modules/%{kmod_kernel_version}.x86_64/extra/%{kmod_name} | grep '\.ko$') ) printf '%s\n' "${modules[@]}" | %{_sbindir}/weak-modules --add-modules --no-initramfs mkdir -p "%{kver_state_dir}" touch "%{kver_state_file}" exit 0 %posttrans # We have to re-implement part of weak-modules here because it doesn't allow # calling initramfs regeneration separately if [ -f "%{kver_state_file}" ]; then kver_base="%{kmod_kernel_version}" kvers=$(ls -d "/lib/modules/${kver_base%%.*}"*) for k_dir in $kvers; do k="${k_dir#/lib/modules/}" tmp_initramfs="/boot/initramfs-$k.tmp" dst_initramfs="/boot/initramfs-$k.img" # The same check as in weak-modules: we assume that the kernel present # if the symvers file exists. if [ -e "/boot/symvers-$k.gz" ]; then /usr/bin/dracut -f "$tmp_initramfs" "$k" || exit 1 cmp -s "$tmp_initramfs" "$dst_initramfs" if [ "$?" = 1 ]; then mv "$tmp_initramfs" "$dst_initramfs" else rm -f "$tmp_initramfs" fi fi done rm -f "%{kver_state_file}" rmdir "%{kver_state_dir}" 2> /dev/null fi rmdir "%{dup_state_dir}" 2> /dev/null exit 0 %preun if rpm -q --filetriggers kmod 2> /dev/null| grep -q "Trigger for weak-modules call on kmod removal"; then mkdir -p "%{kver_state_dir}" touch "%{kver_state_file}" fi mkdir -p "%{dup_state_dir}" rpm -ql kmod-%{kmod_name}-%{version}-%{release}.%{_arch} | grep '\.ko$' > "%{dup_module_list}" %postun if rpm -q --filetriggers kmod 2> /dev/null| grep -q "Trigger for weak-modules call on kmod removal"; then initramfs_opt="--no-initramfs" else initramfs_opt="" fi modules=( $(cat "%{dup_module_list}") ) rm -f "%{dup_module_list}" printf '%s\n' "${modules[@]}" | %{_sbindir}/weak-modules --remove-modules $initramfs_opt rmdir "%{dup_state_dir}" 2> /dev/null exit 0 %files %defattr(644,root,root,755) /lib/modules/%{kmod_kernel_version}.%{_arch}/ %config /etc/depmod.d/kmod-%{kmod_name}.conf %doc /usr/share/doc/kmod-%{kmod_name}-%{version}/ %changelog * Tue Sep 3 2019 Nathan Coulson - 4.18.0.107-1 - Rebuilt for Centos 8 * Wed May 16 2018 Nathan Coulson - 3.10.0.862-1 - Updated to the latest upstream centos 7 kernel * Wed Aug 17 2016 Nathan Coulson - 1.0-1 - Initial el7 build of the kmod package. From e1000e-kmod